From 83b093f172435f7347d7a22d8265a761f450a203 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 11 Dec 2017 14:54:12 +0100 Subject: Label: use deferred execution Task-number: QTBUG-50992 Change-Id: I8e626d1a0585f93cbd612aca39a1e9050f5e0ed3 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicklabel.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/quicktemplates2/qquicklabel.cpp') diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index d1ddfbd6..418a7834 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -38,6 +38,7 @@ #include "qquicklabel_p_p.h" #include "qquickcontrol_p.h" #include "qquickcontrol_p_p.h" +#include "qquickdeferredexecute_p_p.h" #include #include @@ -155,6 +156,20 @@ QAccessible::Role QQuickLabelPrivate::accessibleRole() const } #endif +static inline QString backgroundName() { return QStringLiteral("background"); } + +void QQuickLabelPrivate::executeBackground(bool complete) +{ + Q_Q(QQuickLabel); + if (background.wasExecuted()) + return; + + if (!background) + quickBeginDeferred(q, backgroundName(), background); + if (complete) + quickCompleteDeferred(q, backgroundName(), background); +} + QQuickLabel::QQuickLabel(QQuickItem *parent) : QQuickText(*(new QQuickLabelPrivate), parent) { @@ -190,7 +205,9 @@ void QQuickLabel::setFont(const QFont &font) */ QQuickItem *QQuickLabel::background() const { - Q_D(const QQuickLabel); + QQuickLabelPrivate *d = const_cast(d_func()); + if (!d->background) + d->executeBackground(); return d->background; } @@ -200,14 +217,15 @@ void QQuickLabel::setBackground(QQuickItem *background) if (d->background == background) return; - QQuickControlPrivate::destroyDelegate(d->background, this); + delete d->background; d->background = background; if (background) { background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); } - emit backgroundChanged(); + if (!d->background.isExecuting()) + emit backgroundChanged(); } void QQuickLabel::classBegin() @@ -220,6 +238,7 @@ void QQuickLabel::classBegin() void QQuickLabel::componentComplete() { Q_D(QQuickLabel); + d->executeBackground(true); QQuickText::componentComplete(); #if QT_CONFIG(accessibility) if (!d->accessibleAttached && QAccessible::isActive()) -- cgit v1.2.3