aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@digia.com>2013-05-08 11:18:04 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-08 15:01:47 +0200
commit95fd73b86cddf806c2065cbdad2e0f7641379ce6 (patch)
tree7d33bd1114dcf0ed747527b21874bf3803f40292 /tests
parentef1d6244091e309c1bbdce7d52ad5d019ab498a0 (diff)
The resources property should be independent from QObject
Resources was a direct mapping of the QObject children. This led to problems since the QObject children can also contain other objects from other sources like attached properties. This patch decouples resources from QObject properties and also does not call setParent() anymore. The special case for QQuickWindow in data_append does rely on the fact that QObject::setParent() is called and the inner window becomes a QObject::child of the content item. So we keep the setParent for this special case. The children property does not take QObject ownership either. QObject ownership is handled by the VME. None of the documented QML use cases should be touched by this change. This is a cleaner solution then the ad hoc fix provided by https://codereview.qt-project.org/#change,54677 I changed also the test. The list count now has to be exactly 4. Change-Id: I5c119e333ee82e888aaac1da559fd63a875d08ee Reviewed-by: Liang Qi <liang.qi@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickitem2/data/resourcesProperty.qml23
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp36
2 files changed, 46 insertions, 13 deletions
diff --git a/tests/auto/quick/qquickitem2/data/resourcesProperty.qml b/tests/auto/quick/qquickitem2/data/resourcesProperty.qml
index b8f18bb375..2c4c0aa5c1 100644
--- a/tests/auto/quick/qquickitem2/data/resourcesProperty.qml
+++ b/tests/auto/quick/qquickitem2/data/resourcesProperty.qml
@@ -8,14 +8,27 @@ Item {
property bool test3
property bool test4
property bool test5
+ property bool test6
Component.onCompleted: {
- test1 = (root.resources.length >= 3)
- test2 = root.resources[0] == item1
- test3 = root.resources[1] == item2
- test4 = root.resources[2] == item3
- test5 = root.resources[10] == null
+ test1 = (root.resources.length === 4)
+ test2 = root.resources[0] === item1
+ test3 = root.resources[1] === item2
+ test4 = root.resources[2] === item3
+ test5 = root.resources[3] === otherObject
+ test6 = root.resources[10] == null
}
+ //Resources can be used explicitly
resources: [ Item { id: item1 }, Item { id: item2 }, Item { id: item3 } ]
+
+ Item {
+ //Item in Data go the children property.
+ }
+
+ QtObject {
+ //Objects in Data which are not items are put in resources.
+ id: otherObject
+ objectName: "subObject";
+ }
}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index 18ab581ed9..9a6bed6dbe 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -1840,15 +1840,35 @@ void tst_QQuickItem::resourcesProperty()
{
QQmlComponent component(&engine, testFileUrl("resourcesProperty.qml"));
- QObject *o = component.create();
- QVERIFY(o != 0);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
- QCOMPARE(o->property("test1").toBool(), true);
- QCOMPARE(o->property("test2").toBool(), true);
- QCOMPARE(o->property("test3").toBool(), true);
- QCOMPARE(o->property("test4").toBool(), true);
- QCOMPARE(o->property("test5").toBool(), true);
- delete o;
+ QQmlProperty property(object, "resources", component.creationContext());
+
+ QVERIFY(property.isValid());
+ QQmlListReference list = qvariant_cast<QQmlListReference>(property.read());
+ QVERIFY(list.isValid());
+
+ QCOMPARE(list.count(), 4);
+
+ QCOMPARE(object->property("test1").toBool(), true);
+ QCOMPARE(object->property("test2").toBool(), true);
+ QCOMPARE(object->property("test3").toBool(), true);
+ QCOMPARE(object->property("test4").toBool(), true);
+ QCOMPARE(object->property("test5").toBool(), true);
+ QCOMPARE(object->property("test6").toBool(), true);
+
+ QObject *subObject = object->findChild<QObject *>("subObject");
+
+ QVERIFY(subObject);
+
+ QCOMPARE(object, subObject->parent());
+
+ delete subObject;
+
+ QCOMPARE(list.count(), 3);
+
+ delete object;
}
void tst_QQuickItem::propertyChanges()