aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquicklabel.cpp25
-rw-r--r--src/quicktemplates2/qquicklabel_p.h1
-rw-r--r--src/quicktemplates2/qquicklabel_p_p.h5
-rw-r--r--tests/auto/customization/data/styles/empty/Label.qml57
-rw-r--r--tests/auto/customization/data/styles/override/Label.qml61
-rw-r--r--tests/auto/customization/data/styles/simple/Label.qml63
-rw-r--r--tests/auto/customization/tst_customization.cpp8
7 files changed, 215 insertions, 5 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;
};
diff --git a/tests/auto/customization/data/styles/empty/Label.qml b/tests/auto/customization/data/styles/empty/Label.qml
new file mode 100644
index 00000000..806209d6
--- /dev/null
+++ b/tests/auto/customization/data/styles/empty/Label.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Templates 2.2 as T
+
+T.Label {
+ id: control
+ objectName: "label-empty"
+}
diff --git a/tests/auto/customization/data/styles/override/Label.qml b/tests/auto/customization/data/styles/override/Label.qml
new file mode 100644
index 00000000..03650af3
--- /dev/null
+++ b/tests/auto/customization/data/styles/override/Label.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import "../simple" as Simple
+
+Simple.Label {
+ id: control
+ objectName: "label-override"
+
+ background: Rectangle {
+ objectName: "label-background-override"
+ }
+}
diff --git a/tests/auto/customization/data/styles/simple/Label.qml b/tests/auto/customization/data/styles/simple/Label.qml
new file mode 100644
index 00000000..592d7f64
--- /dev/null
+++ b/tests/auto/customization/data/styles/simple/Label.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Templates 2.2 as T
+
+T.Label {
+ id: control
+ objectName: "label-simple"
+
+ background: Rectangle {
+ objectName: "label-background-simple"
+ implicitWidth: 20
+ implicitHeight: 20
+ }
+}
diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp
index c55c05d4..f3d1e64b 100644
--- a/tests/auto/customization/tst_customization.cpp
+++ b/tests/auto/customization/tst_customization.cpp
@@ -115,7 +115,10 @@ QObject* tst_customization::createControl(const QString &name)
{
QQmlComponent component(engine);
component.setData("import QtQuick.Controls 2.2; " + name.toUtf8() + " { }", QUrl());
- return component.create();
+ QObject *obj = component.create();
+ if (!obj)
+ qDebug() << component.errorString();
+ return obj;
}
void tst_customization::creation_data()
@@ -128,6 +131,7 @@ void tst_customization::creation_data()
QTest::newRow("empty:Button") << "empty" << "Button"<< (QStringList() << "button-empty");
QTest::newRow("empty:CheckBox") << "empty" << "CheckBox" << (QStringList() << "checkbox-empty");
QTest::newRow("empty:Dial") << "empty" << "Dial" << (QStringList() << "dial-empty");
+ QTest::newRow("empty:Label") << "empty" << "Label"<< (QStringList() << "label-empty");
QTest::newRow("empty:RadioButton") << "empty" << "RadioButton" << (QStringList() << "radiobutton-empty");
QTest::newRow("empty:Slider") << "empty" << "Slider" << (QStringList() << "slider-empty");
@@ -142,6 +146,7 @@ void tst_customization::creation_data()
QTest::newRow("simple:Button") << "simple" << "Button" << (QStringList() << "button-simple" << "button-background-simple" << "button-contentItem-simple");
QTest::newRow("simple:CheckBox") << "simple" << "CheckBox" << (QStringList() << "checkbox-simple" << "checkbox-contentItem-simple" << "checkbox-indicator-simple");
QTest::newRow("simple:Dial") << "simple" << "Dial" << (QStringList() << "dial-simple" << "dial-background-simple" << "dial-handle-simple");
+ QTest::newRow("simple:Label") << "simple" << "Label" << (QStringList() << "label-simple" << "label-background-simple");
QTest::newRow("simple:RadioButton") << "simple" << "RadioButton" << (QStringList() << "radiobutton-simple" << "radiobutton-contentItem-simple" << "radiobutton-indicator-simple");
QTest::newRow("simple:Slider") << "simple" << "Slider" << (QStringList() << "slider-simple" << "slider-background-simple" << "slider-handle-simple");
@@ -149,6 +154,7 @@ void tst_customization::creation_data()
QTest::newRow("override:Button") << "override" << "Button" << (QStringList() << "button-override" << "button-background-override" << "button-contentItem-override" << "button-empty"); // overrides "empty"
QTest::newRow("override:CheckBox") << "override" << "CheckBox" << (QStringList() << "checkbox-override" << "checkbox-background-override" << "checkbox-contentItem-incomplete" << "checkbox-incomplete"); // overrides "incomplete"
QTest::newRow("override:Dial") << "override" << "Dial" << (QStringList() << "dial-override" << "dial-background-override" << "dial-handle-override" << "dial-incomplete"); // overrides "incomplete"
+ QTest::newRow("override:Label") << "override" << "Label" << (QStringList() << "label-override" << "label-background-override" << "label-simple"); // overrides "simple"
QTest::newRow("override:RadioButton") << "override" << "RadioButton" << (QStringList() << "radiobutton-override" << "radiobutton-background-override" << "radiobutton-contentItem-simple" << "radiobutton-indicator-override" << "radiobutton-simple"); // overrides "simple"
QTest::newRow("override:Slider") << "override" << "Slider" << (QStringList() << "slider-override" << "slider-background-override" << "slider-handle-override" << "slider-incomplete"); // overrides "incomplete"
}