aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMathias Malmqvist <mathias.malmqvist@nokia.com>2011-12-05 19:21:33 +0000
committerQt by Nokia <qt-info@nokia.com>2012-02-10 00:43:20 +0100
commit9c1793913da9c504b8ef384795d564dc304950a7 (patch)
treeae63839b0d09ee11bb9f991845f8dafccf0aa736 /tests/auto
parente299f0d86dc7f3d158fbb59d055584e768e39c6b (diff)
Added new convenience readonly visibleChildren property to Item
Change-Id: I5ec541226fabd72c05ce8ccb8bb7e56f6ec7717a Task-number: 22724 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtquick2/qquickitem2/data/visiblechildren.qml143
-rw-r--r--tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp61
2 files changed, 204 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickitem2/data/visiblechildren.qml b/tests/auto/qtquick2/qquickitem2/data/visiblechildren.qml
new file mode 100644
index 0000000000..e51eb3551b
--- /dev/null
+++ b/tests/auto/qtquick2/qquickitem2/data/visiblechildren.qml
@@ -0,0 +1,143 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ width: 400
+ height: 300
+
+ Row {
+ id: row
+ Item { id: item1
+ Item { id: item1_1; visible: true }
+ Item { id: item1_2; visible: true }
+ }
+ Item { id: item2 }
+ Item { id: item3
+ Item { id: item3_1; visible: false }
+ Item { id: item3_2; visible: false }
+ }
+ Item { id: item4; visible: false
+ Item { id: item4_1 // implicitly invisible
+ Item { id: item4_1_1 } // implicitly invisible
+ Item { id: item4_1_2 } // implicitly invisible
+ }
+ }
+ }
+
+ property int row_changeEventCalls: 0
+ property int item1_changeEventCalls: 0
+ property int item2_changeEventCalls: 0
+ property int item3_changeEventCalls: 0
+ property int item4_1_changeEventCalls: 0
+ property int item4_1_1_changeEventCalls: 0
+ Connections { target: row; onVisibleChildrenChanged: row_changeEventCalls++ }
+ Connections { target: item1; onVisibleChildrenChanged: item1_changeEventCalls++ }
+ Connections { target: item2; onVisibleChildrenChanged: item2_changeEventCalls++ }
+ Connections { target: item3; onVisibleChildrenChanged: item3_changeEventCalls++ }
+ Connections { target: item4_1; onVisibleChildrenChanged: item4_1_changeEventCalls++ }
+ Connections { target: item4_1_1; onVisibleChildrenChanged: item4_1_1_changeEventCalls++ }
+
+ // Make sure there are three visible children and no signals fired yet
+ property bool test1_1: row.visibleChildren.length == 3
+ property bool test1_2: row.visibleChildren[0] == item1 && row.visibleChildren[1] == item2 && row.visibleChildren[2] == item3
+ property bool test1_3: row_changeEventCalls == 0
+ property bool test1_4: item1_changeEventCalls == 0 && item2_changeEventCalls == 0 && item3_changeEventCalls == 0
+
+ // Next test
+ function hideFirstAndLastRowChild() {
+ item1.visible = false;
+ item3.visible = false;
+ }
+
+ // Make sure row is signaled twice and item1 only once, and item3 not at all, and that item2 is the visible child
+ property bool test2_1: row.visibleChildren.length == 1
+ property bool test2_2: row.visibleChildren[0] == item2
+ property bool test2_3: row_changeEventCalls == 2
+ property bool test2_4: item1_changeEventCalls == 1 && item2_changeEventCalls == 0 && item3_changeEventCalls == 0
+
+ // Next test
+ function showLastRowChildsLastChild() {
+ item3_2.visible = true;
+ }
+
+ // Make sure item3_changeEventCalls is not signaled
+ property bool test3_1: row.visibleChildren.length == 1
+ property bool test3_2: row.visibleChildren[0] == item2
+ property bool test3_3: row_changeEventCalls == 2
+ property bool test3_4: item1_changeEventCalls == 1 && item2_changeEventCalls == 0 && item3_changeEventCalls == 0
+
+ // Next test
+ function showLastRowChild() {
+ item3.visible = true;
+ }
+
+ // Make sure row and item3 are signaled
+ property bool test4_1: row.visibleChildren.length == 2
+ property bool test4_2: row.visibleChildren[0] == item2 && row.visibleChildren[1] == item3
+ property bool test4_3: row_changeEventCalls == 3
+ property bool test4_4: item1_changeEventCalls == 1 && item2_changeEventCalls == 0 && item3_changeEventCalls == 1
+
+ // Next test
+ function tryWriteToReadonlyVisibleChildren() {
+ var foo = fooComponent.createObject(root);
+ if (Qt.isQtObject(foo) && foo.children.length == 3 && foo.visibleChildren.length == 3) {
+ test5_1 = true;
+ }
+
+ foo.visibleChildren.length = 10; // make sure this has no effect
+ test5_1 = (foo.visibleChildren.length == 3);
+ delete foo;
+ }
+
+ Component {
+ id: fooComponent
+ Item {
+ children: [ Item {},Item {},Item {} ]
+ visibleChildren: [ Item {} ]
+ }
+ }
+
+ // Make sure visibleChildren.length is 3 and stays that way
+ property bool test5_1: false
+
+ // Next test
+ function reparentVisibleItem3() {
+ item3.parent = hiddenItem; // item3 has one visible children
+ }
+
+ Item { id: hiddenItem; visible: false }
+
+ property bool test6_1: row.visibleChildren.length == 1 && row_changeEventCalls == 4
+ property bool test6_2: item3_changeEventCalls == 2
+ property bool test6_3: item3.visible == false
+
+ // Next test
+
+ property bool test6_4: item4_1.visible == false && item4_1_changeEventCalls == 0
+
+ function reparentImlicitlyInvisibleItem4_1() {
+ item4_1.parent = visibleItem;
+ }
+
+ Item { id: visibleItem; visible: true }
+ property int visibleItem_changeEventCalls: 0
+ Connections { target: visibleItem; onVisibleChildrenChanged: visibleItem_changeEventCalls++ }
+
+
+ // Make sure that an item with implictly invisible children will be signaled when reparented to a visible parent
+ property bool test7_1: row.visibleChildren.length == 1 && row_changeEventCalls == 4
+ property bool test7_2: item4_1.visible == true
+ property bool test7_3: item4_1_changeEventCalls == 1
+ property bool test7_4: visibleItem_changeEventCalls == 1
+
+
+
+ // FINALLY make sure nothing has changes while we weren't paying attention
+
+ property bool test8_1: row.visibleChildren.length == 1 && row.visibleChildren[0] == item2 && row_changeEventCalls == 4
+ property bool test8_2: item1_changeEventCalls == 1 && item1.visible == false
+ property bool test8_3: item2_changeEventCalls == 0 && item2.visible == true
+ property bool test8_4: item3_changeEventCalls == 2 && item3.visible == false
+ property bool test8_5: item4_1_1_changeEventCalls == 0 && item4_1_1.visible == true
+
+}
diff --git a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
index f6a7b0c9c3..c26fc94178 100644
--- a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
@@ -85,6 +85,7 @@ private slots:
void transformCrash();
void implicitSize();
void qtbug_16871();
+ void visibleChildren();
private:
QDeclarativeEngine engine;
};
@@ -1246,6 +1247,66 @@ void tst_QQuickItem::qtbug_16871()
delete o;
}
+
+void tst_QQuickItem::visibleChildren()
+{
+ QQuickView *canvas = new QQuickView(0);
+ canvas->setSource(testFileUrl("visiblechildren.qml"));
+ canvas->show();
+
+ QQuickItem *root = qobject_cast<QQuickItem*>(canvas->rootObject());
+ QVERIFY(root);
+
+ QCOMPARE(root->property("test1_1").toBool(), true);
+ QCOMPARE(root->property("test1_2").toBool(), true);
+ QCOMPARE(root->property("test1_3").toBool(), true);
+ QCOMPARE(root->property("test1_4").toBool(), true);
+
+ QMetaObject::invokeMethod(root, "hideFirstAndLastRowChild");
+ QCOMPARE(root->property("test2_1").toBool(), true);
+ QCOMPARE(root->property("test2_2").toBool(), true);
+ QCOMPARE(root->property("test2_3").toBool(), true);
+ QCOMPARE(root->property("test2_4").toBool(), true);
+
+ QMetaObject::invokeMethod(root, "showLastRowChildsLastChild");
+ QCOMPARE(root->property("test3_1").toBool(), true);
+ QCOMPARE(root->property("test3_2").toBool(), true);
+ QCOMPARE(root->property("test3_3").toBool(), true);
+ QCOMPARE(root->property("test3_4").toBool(), true);
+
+ QMetaObject::invokeMethod(root, "showLastRowChild");
+ QCOMPARE(root->property("test4_1").toBool(), true);
+ QCOMPARE(root->property("test4_2").toBool(), true);
+ QCOMPARE(root->property("test4_3").toBool(), true);
+ QCOMPARE(root->property("test4_4").toBool(), true);
+
+ QString warning1 = testFileUrl("visiblechildren.qml").toString() + ":96:32: QML Item: QQuickItem: visibleChildren property is readonly and cannot be assigned to.";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QMetaObject::invokeMethod(root, "tryWriteToReadonlyVisibleChildren");
+ QCOMPARE(root->property("test5_1").toBool(), true);
+
+ QMetaObject::invokeMethod(root, "reparentVisibleItem3");
+ QCOMPARE(root->property("test6_1").toBool(), true);
+ QCOMPARE(root->property("test6_2").toBool(), true);
+ QCOMPARE(root->property("test6_3").toBool(), true);
+ QCOMPARE(root->property("test6_4").toBool(), true);
+
+ QMetaObject::invokeMethod(root, "reparentImlicitlyInvisibleItem4_1");
+ QCOMPARE(root->property("test7_1").toBool(), true);
+ QCOMPARE(root->property("test7_2").toBool(), true);
+ QCOMPARE(root->property("test7_3").toBool(), true);
+ QCOMPARE(root->property("test7_4").toBool(), true);
+
+ // FINALLY TEST THAT EVERYTHING IS AS EXPECTED
+ QCOMPARE(root->property("test8_1").toBool(), true);
+ QCOMPARE(root->property("test8_2").toBool(), true);
+ QCOMPARE(root->property("test8_3").toBool(), true);
+ QCOMPARE(root->property("test8_4").toBool(), true);
+ QCOMPARE(root->property("test8_5").toBool(), true);
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_QQuickItem)
#include "tst_qquickitem.moc"