diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-12-11 14:54:12 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 13:37:16 +0000 |
commit | 83b093f172435f7347d7a22d8265a761f450a203 (patch) | |
tree | bfdadd7feac5ec8207825a855960cc29c90fd10f /src | |
parent | 417b8459c3311fbf397fe82b9e76580469ec8ce8 (diff) |
Label: use deferred execution
Task-number: QTBUG-50992
Change-Id: I8e626d1a0585f93cbd612aca39a1e9050f5e0ed3
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquicklabel.cpp | 25 | ||||
-rw-r--r-- | src/quicktemplates2/qquicklabel_p.h | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquicklabel_p_p.h | 5 |
3 files changed, 27 insertions, 4 deletions
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 <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquicktext_p.h> @@ -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<QQuickLabelPrivate *>(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()) diff --git a/src/quicktemplates2/qquicklabel_p.h b/src/quicktemplates2/qquicklabel_p.h index 04172900..c31e173b 100644 --- a/src/quicktemplates2/qquicklabel_p.h +++ b/src/quicktemplates2/qquicklabel_p.h @@ -60,6 +60,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickLabel : public QQuickText Q_OBJECT Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) // override Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + Q_CLASSINFO("DeferredPropertyNames", "background") public: explicit QQuickLabel(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicklabel_p_p.h b/src/quicktemplates2/qquicklabel_p_p.h index c24c855b..b8ad2ae7 100644 --- a/src/quicktemplates2/qquicklabel_p_p.h +++ b/src/quicktemplates2/qquicklabel_p_p.h @@ -49,6 +49,7 @@ // #include <QtQuick/private/qquicktext_p_p.h> +#include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h> #if QT_CONFIG(accessibility) #include <QtGui/qaccessible.h> @@ -84,8 +85,10 @@ public: QAccessible::Role accessibleRole() const override; #endif + void executeBackground(bool complete = false); + QFont font; - QQuickItem *background; + QQuickDeferredPointer<QQuickItem> background; QQuickAccessibleAttached *accessibleAttached; }; |