aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-11-14 11:47:59 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-11-16 15:58:10 +0000
commit08c7db1f8dc388af3170fe46ee5c54ac8ae2d40b (patch)
tree966c40166ada3d3c939a2dab44a735d8f7ee6a6c /tests
parent792be4d3c8db1553f97d31019612a7c94e6a8816 (diff)
ApplicationWindow: introduce attached properties
The attached properties provide convenient direct access to an application window and its building blocks. Change-Id: I2d96842d80faec47c875156202c1e33a2af96ad3 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/applicationwindow/applicationwindow.pro2
-rw-r--r--tests/auto/applicationwindow/data/attachedProperties.qml144
-rw-r--r--tests/auto/applicationwindow/tst_applicationwindow.cpp135
3 files changed, 280 insertions, 1 deletions
diff --git a/tests/auto/applicationwindow/applicationwindow.pro b/tests/auto/applicationwindow/applicationwindow.pro
index 6665a640..5a664b63 100644
--- a/tests/auto/applicationwindow/applicationwindow.pro
+++ b/tests/auto/applicationwindow/applicationwindow.pro
@@ -4,7 +4,7 @@ SOURCES += tst_applicationwindow.cpp
osx:CONFIG -= app_bundle
-QT += core-private gui-private qml-private quick-private testlib
+QT += core-private gui-private qml-private quick-private labstemplates-private testlib
include (../shared/util.pri)
diff --git a/tests/auto/applicationwindow/data/attachedProperties.qml b/tests/auto/applicationwindow/data/attachedProperties.qml
new file mode 100644
index 00000000..060a3093
--- /dev/null
+++ b/tests/auto/applicationwindow/data/attachedProperties.qml
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.6
+import QtQuick.Window 2.2
+import Qt.labs.controls 1.0
+
+ApplicationWindow {
+ property alias childItem: childItem
+ property alias childObject: childObject
+
+ Item {
+ id: childItem
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+
+ QtObject {
+ id: childObject
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+
+ property alias childWindow: childWindow
+ property alias childWindowItem: childWindowItem
+ property alias childWindowObject: childWindowObject
+
+ Window {
+ id: childWindow
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+
+ Item {
+ id: childWindowItem
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+
+ QtObject {
+ id: childWindowObject
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+ }
+
+ property alias childAppWindow: childAppWindow
+ property alias childAppWindowItem: childAppWindowItem
+ property alias childAppWindowObject: childAppWindowObject
+
+ ApplicationWindow {
+ id: childAppWindow
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+
+ Item {
+ id: childAppWindowItem
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+
+ QtObject {
+ id: childAppWindowObject
+
+ property ApplicationWindow attached_window: ApplicationWindow.window
+ property Item attached_contentItem: ApplicationWindow.contentItem
+ property Item attached_activeFocusItem: ApplicationWindow.activeFocusItem
+ property Item attached_header: ApplicationWindow.header
+ property Item attached_footer: ApplicationWindow.footer
+ property Item attached_overlay: ApplicationWindow.overlay
+ }
+ }
+}
diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp
index e654437d..0f91d634 100644
--- a/tests/auto/applicationwindow/tst_applicationwindow.cpp
+++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp
@@ -41,6 +41,7 @@
#include <QtQml/qqmlcontext.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/private/qquickitem_p.h>
+#include <QtLabsTemplates/private/qquickapplicationwindow_p.h>
#include "../shared/util.h"
#include "../shared/visualtestutil.h"
@@ -57,6 +58,7 @@ private slots:
void activeFocusOnTab2();
void defaultFocus();
void implicitFill();
+ void attachedProperties();
};
void tst_applicationwindow::qmlCreation()
@@ -247,6 +249,139 @@ void tst_applicationwindow::implicitFill()
QCOMPARE(nextItem->height(), 400.0);
}
+void tst_applicationwindow::attachedProperties()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("attachedProperties.qml"));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(!object.isNull(), qPrintable(component.errorString()));
+
+ QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(object.data());
+ QVERIFY(window);
+
+ QQuickItem *childItem = object->property("childItem").value<QQuickItem *>();
+ QVERIFY(childItem);
+ QCOMPARE(childItem->property("attached_window").value<QQuickApplicationWindow *>(), window);
+ QCOMPARE(childItem->property("attached_contentItem").value<QQuickItem *>(), window->contentItem());
+ QCOMPARE(childItem->property("attached_activeFocusItem").value<QQuickItem *>(), window->activeFocusItem());
+ QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), window->header());
+ QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), window->footer());
+ QCOMPARE(childItem->property("attached_overlay").value<QQuickItem *>(), window->overlay());
+
+ QObject *childObject = object->property("childObject").value<QObject *>();
+ QVERIFY(childObject);
+ QVERIFY(!childObject->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childObject->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childObject->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childObject->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childObject->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childObject->property("attached_overlay").value<QQuickItem *>());
+
+ QQuickWindow *childWindow = object->property("childWindow").value<QQuickWindow *>();
+ QVERIFY(childWindow);
+ QVERIFY(!childWindow->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childWindow->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childWindow->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childWindow->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childWindow->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childWindow->property("attached_overlay").value<QQuickItem *>());
+
+ QQuickItem *childWindowItem = object->property("childWindowItem").value<QQuickItem *>();
+ QVERIFY(childWindowItem);
+ QVERIFY(!childWindowItem->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childWindowItem->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childWindowItem->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childWindowItem->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childWindowItem->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childWindowItem->property("attached_overlay").value<QQuickItem *>());
+
+ QObject *childWindowObject = object->property("childWindowObject").value<QObject *>();
+ QVERIFY(childWindowObject);
+ QVERIFY(!childWindowObject->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childWindowObject->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childWindowObject->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childWindowObject->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childWindowObject->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childWindowObject->property("attached_overlay").value<QQuickItem *>());
+
+ QQuickApplicationWindow *childAppWindow = object->property("childAppWindow").value<QQuickApplicationWindow *>();
+ QVERIFY(childAppWindow);
+ QVERIFY(!childAppWindow->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childAppWindow->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childAppWindow->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childAppWindow->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childAppWindow->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childAppWindow->property("attached_overlay").value<QQuickItem *>());
+
+ QQuickItem *childAppWindowItem = object->property("childAppWindowItem").value<QQuickItem *>();
+ QVERIFY(childAppWindowItem);
+ QCOMPARE(childAppWindowItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
+ QCOMPARE(childAppWindowItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
+ QCOMPARE(childAppWindowItem->property("attached_activeFocusItem").value<QQuickItem *>(), childAppWindow->activeFocusItem());
+ QCOMPARE(childAppWindowItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
+ QCOMPARE(childAppWindowItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
+ QCOMPARE(childAppWindowItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
+
+ QObject *childAppWindowObject = object->property("childAppWindowObject").value<QObject *>();
+ QVERIFY(childAppWindowObject);
+ QVERIFY(!childAppWindowObject->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childAppWindowObject->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childAppWindowObject->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childAppWindowObject->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childAppWindowObject->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childAppWindowObject->property("attached_overlay").value<QQuickItem *>());
+
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QVERIFY(!childItem->hasActiveFocus());
+ childItem->forceActiveFocus();
+ QTRY_VERIFY(childItem->hasActiveFocus());
+ QCOMPARE(window->activeFocusItem(), childItem);
+ QCOMPARE(childItem->property("attached_activeFocusItem").value<QQuickItem *>(), childItem);
+
+ QQuickItem *header = new QQuickItem;
+ window->setHeader(header);
+ QCOMPARE(window->header(), header);
+ QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), header);
+
+ QQuickItem *footer = new QQuickItem;
+ window->setFooter(footer);
+ QCOMPARE(window->footer(), footer);
+ QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), footer);
+
+ childAppWindow->show();
+ childAppWindow->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(childAppWindow));
+
+ QVERIFY(!childAppWindowItem->hasActiveFocus());
+ childAppWindowItem->forceActiveFocus();
+ QTRY_VERIFY(childAppWindowItem->hasActiveFocus());
+ QCOMPARE(childAppWindow->activeFocusItem(), childAppWindowItem);
+ QCOMPARE(childAppWindowItem->property("attached_activeFocusItem").value<QQuickItem *>(), childAppWindowItem);
+
+ childItem->setParentItem(childAppWindow->contentItem());
+ QCOMPARE(childItem->window(), childAppWindow);
+ QCOMPARE(childItem->property("attached_window").value<QQuickApplicationWindow *>(), childAppWindow);
+ QCOMPARE(childItem->property("attached_contentItem").value<QQuickItem *>(), childAppWindow->contentItem());
+ QCOMPARE(childItem->property("attached_activeFocusItem").value<QQuickItem *>(), childAppWindow->activeFocusItem());
+ QCOMPARE(childItem->property("attached_header").value<QQuickItem *>(), childAppWindow->header());
+ QCOMPARE(childItem->property("attached_footer").value<QQuickItem *>(), childAppWindow->footer());
+ QCOMPARE(childItem->property("attached_overlay").value<QQuickItem *>(), childAppWindow->overlay());
+
+ childItem->setParentItem(Q_NULLPTR);
+ QVERIFY(!childItem->window());
+ QVERIFY(!childItem->property("attached_window").value<QQuickApplicationWindow *>());
+ QVERIFY(!childItem->property("attached_contentItem").value<QQuickItem *>());
+ QVERIFY(!childItem->property("attached_activeFocusItem").value<QQuickItem *>());
+ QVERIFY(!childItem->property("attached_header").value<QQuickItem *>());
+ QVERIFY(!childItem->property("attached_footer").value<QQuickItem *>());
+ QVERIFY(!childItem->property("attached_overlay").value<QQuickItem *>());
+}
+
QTEST_MAIN(tst_applicationwindow)
#include "tst_applicationwindow.moc"