aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicklabel.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-12-11 14:54:12 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-12-13 13:37:16 +0000
commit83b093f172435f7347d7a22d8265a761f450a203 (patch)
treebfdadd7feac5ec8207825a855960cc29c90fd10f /src/quicktemplates2/qquicklabel.cpp
parent417b8459c3311fbf397fe82b9e76580469ec8ce8 (diff)
Label: use deferred execution
Task-number: QTBUG-50992 Change-Id: I8e626d1a0585f93cbd612aca39a1e9050f5e0ed3 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicklabel.cpp')
-rw-r--r--src/quicktemplates2/qquicklabel.cpp25
1 files changed, 22 insertions, 3 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())