diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 17:03:37 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 16:36:19 +0000 |
commit | 1c265b23ef7494abc6a00094e781a8e48de87121 (patch) | |
tree | ab84ff7c137045436e19fa808d8cbb5f0f22f816 | |
parent | 59f72376602c306f6322c9482e2201f1cc9e3819 (diff) |
ApplicationWindow: use deferred execution
Task-number: QTBUG-50992
Change-Id: Ia07055d2fa3d30c91bdf3c526cf7301c7ed1ce2b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
6 files changed, 211 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp index e3f16d55..c1a7f301 100644 --- a/src/quicktemplates2/qquickapplicationwindow.cpp +++ b/src/quicktemplates2/qquickapplicationwindow.cpp @@ -43,6 +43,8 @@ #include "qquicktoolbar_p.h" #include "qquicktabbar_p.h" #include "qquickdialogbuttonbox_p.h" +#include "qquickdeferredexecute_p_p.h" +#include "qquickdeferredpointer_p_p.h" #include <QtCore/private/qobject_p.h> #include <QtQuick/private/qquickitem_p.h> @@ -173,8 +175,10 @@ public: static void contentData_append(QQmlListProperty<QObject> *prop, QObject *obj); + void executeBackground(bool complete = false); + bool complete; - QQuickItem *background; + QQuickDeferredPointer<QQuickItem> background; QQuickItem *contentItem; QQuickItem *header; QQuickItem *footer; @@ -295,6 +299,20 @@ void QQuickApplicationWindowPrivate::contentData_append(QQmlListProperty<QObject QQuickPopupPrivate::get(popup)->setWindow(static_cast<QQuickApplicationWindow *>(prop->data)); } +static inline QString backgroundName() { return QStringLiteral("background"); } + +void QQuickApplicationWindowPrivate::executeBackground(bool complete) +{ + Q_Q(QQuickApplicationWindow); + if (background.wasExecuted()) + return; + + if (!background) + quickBeginDeferred(q, backgroundName(), background); + if (complete) + quickCompleteDeferred(q, backgroundName(), background); +} + QQuickApplicationWindow::QQuickApplicationWindow(QWindow *parent) : QQuickWindowQmlImpl(parent), d_ptr(new QQuickApplicationWindowPrivate) { @@ -336,7 +354,9 @@ QQuickApplicationWindow::~QQuickApplicationWindow() */ QQuickItem *QQuickApplicationWindow::background() const { - Q_D(const QQuickApplicationWindow); + QQuickApplicationWindowPrivate *d = const_cast<QQuickApplicationWindowPrivate *>(d_func()); + if (!d->background) + d->executeBackground(); return d->background; } @@ -346,7 +366,7 @@ void QQuickApplicationWindow::setBackground(QQuickItem *background) if (d->background == background) return; - QQuickControlPrivate::destroyDelegate(d->background, this); + delete d->background; d->background = background; if (background) { background->setParentItem(QQuickWindow::contentItem()); @@ -355,7 +375,8 @@ void QQuickApplicationWindow::setBackground(QQuickItem *background) if (isComponentComplete()) d->relayout(); } - emit backgroundChanged(); + if (!d->background.isExecuting()) + emit backgroundChanged(); } /*! @@ -716,6 +737,7 @@ void QQuickApplicationWindow::componentComplete() { Q_D(QQuickApplicationWindow); d->complete = true; + d->executeBackground(true); QQuickWindowQmlImpl::componentComplete(); } diff --git a/src/quicktemplates2/qquickapplicationwindow_p.h b/src/quicktemplates2/qquickapplicationwindow_p.h index 07ddc67e..c1e7935b 100644 --- a/src/quicktemplates2/qquickapplicationwindow_p.h +++ b/src/quicktemplates2/qquickapplicationwindow_p.h @@ -72,6 +72,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickApplicationWindow : public QQuickWi Q_PROPERTY(QQuickOverlay *overlay READ overlay CONSTANT FINAL) Q_PROPERTY(QFont font READ font WRITE setFont RESET resetFont NOTIFY fontChanged FINAL) Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET resetLocale NOTIFY localeChanged FINAL) + Q_CLASSINFO("DeferredPropertyNames", "background") Q_CLASSINFO("DefaultProperty", "contentData") public: diff --git a/tests/auto/customization/data/styles/empty/ApplicationWindow.qml b/tests/auto/customization/data/styles/empty/ApplicationWindow.qml new file mode 100644 index 00000000..e814d2d6 --- /dev/null +++ b/tests/auto/customization/data/styles/empty/ApplicationWindow.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.ApplicationWindow { + id: control + objectName: "applicationwindow-empty" +} diff --git a/tests/auto/customization/data/styles/override/ApplicationWindow.qml b/tests/auto/customization/data/styles/override/ApplicationWindow.qml new file mode 100644 index 00000000..71580373 --- /dev/null +++ b/tests/auto/customization/data/styles/override/ApplicationWindow.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.ApplicationWindow { + id: control + objectName: "applicationwindow-override" + + background: Rectangle { + objectName: "applicationwindow-background-override" + } +} diff --git a/tests/auto/customization/data/styles/simple/ApplicationWindow.qml b/tests/auto/customization/data/styles/simple/ApplicationWindow.qml new file mode 100644 index 00000000..e8de22f3 --- /dev/null +++ b/tests/auto/customization/data/styles/simple/ApplicationWindow.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.ApplicationWindow { + id: control + objectName: "applicationwindow-simple" + + background: Rectangle { + objectName: "applicationwindow-background-simple" + implicitWidth: 20 + implicitHeight: 20 + } +} diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp index 04b1af0b..20914b61 100644 --- a/tests/auto/customization/tst_customization.cpp +++ b/tests/auto/customization/tst_customization.cpp @@ -128,6 +128,7 @@ void tst_customization::creation_data() QTest::addColumn<QStringList>("delegates"); // the "empty" style does not contain any delegates + QTest::newRow("empty:ApplicationWindow") << "empty" << "ApplicationWindow"<< (QStringList() << "applicationwindow-empty"); 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"); @@ -147,6 +148,7 @@ void tst_customization::creation_data() QTest::newRow("incomplete:Slider") << "incomplete" << "Slider" << (QStringList() << "slider-incomplete" << "slider-handle-incomplete"); // the "simple" style simulates a proper style and contains most delegates + QTest::newRow("simple:ApplicationWindow") << "simple" << "ApplicationWindow" << (QStringList() << "applicationwindow-simple" << "applicationwindow-background-simple"); 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"); @@ -158,6 +160,7 @@ void tst_customization::creation_data() QTest::newRow("simple:TextArea") << "simple" << "TextArea" << (QStringList() << "textarea-simple" << "textarea-background-simple"); // the "override" style overrides various delegates in the above styles + QTest::newRow("override:ApplicationWindow") << "override" << "ApplicationWindow" << (QStringList() << "applicationwindow-override" << "applicationwindow-background-override" << "applicationwindow-simple"); // overrides "simple" 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" |