diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-10-31 10:33:31 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-11-05 09:16:51 +0000 |
commit | f2244820016f27ac2f7d26c8ba51d806956e4968 (patch) | |
tree | 84738e9bba80f4cabf9c0bcc37bcb63e65dae757 /tests | |
parent | b340d8bb8886ecb46c8702127ff4dffb727c4f24 (diff) |
DesignerSupport: Fix emitComponentCompleteSignalForAttachedProperty
The signal for completed for the attached Component property was
no emitted correctly by emitComponentCompleteSignalForAttachedProperty().
I added a test for the correct behaivour.
Change-Id: I0ebfc10e512ba5c5e2352a5f5d6be3030b43cbbc
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'tests')
5 files changed, 209 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickdesignersupport/data/Component01.qml b/tests/auto/quick/qquickdesignersupport/data/Component01.qml new file mode 100644 index 0000000000..463417445c --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/Component01.qml @@ -0,0 +1,51 @@ +import QtQuick 2.9 +import QtQuick.Window 2.3 + +Item { + visible: true + width: 640 + height: 480 + objectName: "componentRoot" + + Rectangle { + objectName: "topLevelComplete" + id: rectangle + x: 378 + y: 91 + width: 100 + height: 100 + color: "#ffffff" + } + + Item { + id: element + x: 14 + y: 39 + width: 120 + height: 120 + + Rectangle { + id: rectangle1 + objectName: "implemented" + x: 43 + y: 52 + width: 110 + height: 110 + color: "#ffffff" + + Component.onCompleted: { + rectangle1.color = "blue" + } + } + } + + Component02 { + id: element1 + x: 88 + y: 251 + } + + Component.onCompleted: { + rectangle.color = "red" + } +} diff --git a/tests/auto/quick/qquickdesignersupport/data/Component02.qml b/tests/auto/quick/qquickdesignersupport/data/Component02.qml new file mode 100644 index 0000000000..7bbad0c917 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/Component02.qml @@ -0,0 +1,24 @@ +import QtQuick 2.9 +import QtQuick.Window 2.3 + +Item { + id: element1 + width: 200 + height: 200 + objectName: "inner" + + + Rectangle { + id: rectangle2 + objectName: "most inner" + x: 59 + y: 51 + width: 200 + height: 200 + color: "#ffffff" + } + + Component.onCompleted: { + rectangle2.color = "green" + } +} diff --git a/tests/auto/quick/qquickdesignersupport/data/componentTest.qml b/tests/auto/quick/qquickdesignersupport/data/componentTest.qml new file mode 100644 index 0000000000..a30cfafc90 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/componentTest.qml @@ -0,0 +1,33 @@ +import QtQuick 2.9 +import QtQuick.Window 2.3 + +Item { + visible: true + width: 640 + height: 480 + + Component01 { + id: rectangle + x: 205 + y: 70 + width: 251 + height: 242 + } + + Item { + id: element + x: 14 + y: 39 + width: 285 + height: 304 + + Rectangle { + id: rectangle1 + x: 43 + y: 52 + width: 200 + height: 200 + color: "#ffffff" + } + } +} diff --git a/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro index 6e1ad6b95e..6212a996f1 100644 --- a/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro +++ b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro @@ -12,4 +12,8 @@ TESTDATA = data/* QT += core-private gui-private qml-private quick-private testlib DISTFILES += \ - data/TestComponent.qml + data/TestComponent.qml \ + data/test.qml \ + data/componentTest.qml \ + data/Component01.qml \ + data/Component02.qml diff --git a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp index 3e0765552a..b44977bd5a 100644 --- a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp +++ b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp @@ -61,6 +61,7 @@ private slots: void statesPropertyChanges(); void testNotifyPropertyChangeCallBack(); void testFixResourcePathsForObjectCallBack(); + void testComponentOnCompleteSignal(); }; void tst_qquickdesignersupport::customData() @@ -490,6 +491,101 @@ void tst_qquickdesignersupport::testFixResourcePathsForObjectCallBack() QCOMPARE(simpleItem , s_object); } +void doComponentCompleteRecursive(QObject *object) +{ + if (object) { + QQuickItem *item = qobject_cast<QQuickItem*>(object); + + if (item && DesignerSupport::isComponentComplete(item)) + return; + + DesignerSupport::emitComponentCompleteSignalForAttachedProperty(object); + + QList<QObject*> childList = object->children(); + + if (item) { + foreach (QQuickItem *childItem, item->childItems()) { + if (!childList.contains(childItem)) + childList.append(childItem); + } + } + + foreach (QObject *child, childList) + doComponentCompleteRecursive(child); + + if (item) { + static_cast<QQmlParserStatus*>(item)->componentComplete(); + } else { + QQmlParserStatus *qmlParserStatus = dynamic_cast< QQmlParserStatus*>(object); + if (qmlParserStatus) + qmlParserStatus->componentComplete(); + } + } +} + +void tst_qquickdesignersupport::testComponentOnCompleteSignal() +{ + { + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("componentTest.qml")); + + QVERIFY(view->errors().isEmpty()); + QQuickItem *rootItem = view->rootObject(); + QVERIFY(rootItem); + + QQuickItem *item = findItem<QQuickItem>(view->rootObject(), QLatin1String("topLevelComplete")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("red")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("implemented")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("blue")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("most inner")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("green")); + } + + { + ComponentCompleteDisabler disableComponentComplete; + + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("componentTest.qml")); + + QVERIFY(view->errors().isEmpty()); + QQuickItem *rootItem = view->rootObject(); + QVERIFY(rootItem); + + QQuickItem *item = findItem<QQuickItem>(view->rootObject(), QLatin1String("topLevelComplete")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("white")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("implemented")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("white")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("most inner")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("white")); + + doComponentCompleteRecursive(rootItem); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("topLevelComplete")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("red")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("implemented")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("blue")); + + item = findItem<QQuickItem>(view->rootObject(), QLatin1String("most inner")); + QVERIFY(item); + QCOMPARE(item->property("color").value<QColor>(), QColor("green")); + } +} + QTEST_MAIN(tst_qquickdesignersupport) |