diff options
author | Mauro Persano <mauro.persano@kdab.com> | 2017-06-15 19:35:42 -0300 |
---|---|---|
committer | Mauro Persano <mauro.persano@kdab.com> | 2017-06-16 12:53:49 +0000 |
commit | 01a6bcd086cecef3169e5d79bd72dbb0d1393a0f (patch) | |
tree | ff1df20d85c15dc6f35e82f0e2df7ae9f3b6d19d /tests/auto/quick3d | |
parent | c804e393e7b0e66c03ebe5ca3d7c5a246e5fcda8 (diff) |
Update NodeInstantiator's children on parent update
Currently the parent for elements created by NodeInstantiator are set to
the instantiator's parent. This doesn't work for nested instantiators,
since at the time the inner instantiator's children are being created
the instantiator itself doesn't yet have a parent node yet.
Update the parent of elements created by the instantiator when the
instantiator's parent changes.
Change-Id: I6f260ad2a8a81af5551799e6c643d8849f46e342
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'tests/auto/quick3d')
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/quick3d/quick3dnodeinstantiator/data/createNested.qml b/tests/auto/quick3d/quick3dnodeinstantiator/data/createNested.qml new file mode 100644 index 000000000..55be54297 --- /dev/null +++ b/tests/auto/quick3d/quick3dnodeinstantiator/data/createNested.qml @@ -0,0 +1,15 @@ +import QtQml 2.1 +import Qt3D.Core 2.0 + +Entity { + NodeInstantiator { + model: 3 + delegate: NodeInstantiator { + model: 4 + delegate: Entity { + property bool success: true + property int idx: index + } + } + } +} diff --git a/tests/auto/quick3d/quick3dnodeinstantiator/quick3dnodeinstantiator.pro b/tests/auto/quick3d/quick3dnodeinstantiator/quick3dnodeinstantiator.pro index 15435d13e..9026f91ff 100644 --- a/tests/auto/quick3d/quick3dnodeinstantiator/quick3dnodeinstantiator.pro +++ b/tests/auto/quick3d/quick3dnodeinstantiator/quick3dnodeinstantiator.pro @@ -12,6 +12,7 @@ OTHER_FILES = \ data/createMultiple.qml \ data/createNone.qml \ data/createSingle.qml \ + data/createNested.qml \ data/inactive.qml \ data/stringModel.qml diff --git a/tests/auto/quick3d/quick3dnodeinstantiator/tst_quick3dnodeinstantiator.cpp b/tests/auto/quick3d/quick3dnodeinstantiator/tst_quick3dnodeinstantiator.cpp index acaba6690..d4d0d56e2 100644 --- a/tests/auto/quick3d/quick3dnodeinstantiator/tst_quick3dnodeinstantiator.cpp +++ b/tests/auto/quick3d/quick3dnodeinstantiator/tst_quick3dnodeinstantiator.cpp @@ -50,6 +50,7 @@ private slots: void createNone(); void createSingle(); void createMultiple(); + void createNested(); void stringModel(); void activeProperty(); void intModelChange(); @@ -109,6 +110,34 @@ void tst_quick3dnodeinstantiator::createMultiple() } } +void tst_quick3dnodeinstantiator::createNested() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("createNested.qml")); + const auto root = qobject_cast<Qt3DCore::QNode*>(component.create()); + QVERIFY(root != 0); + + auto instantiators = root->findChildren<Quick3DNodeInstantiator*>(); + QCOMPARE(instantiators.count(), 4); + + const auto outerInstantiator = instantiators.takeFirst(); + QCOMPARE(outerInstantiator->isActive(), true); + QCOMPARE(outerInstantiator->count(), 3); + + for (const auto instantiator : instantiators) { + QCOMPARE(instantiator->isActive(), true); + QCOMPARE(instantiator->count(), 4); + + for (int i = 0; i < 4; i++) { + auto object = instantiator->objectAt(i); + QVERIFY(object); + QCOMPARE(object->parent(), root); + QCOMPARE(object->property("success").toBool(), true); + QCOMPARE(object->property("idx").toInt(), i); + } + } +} + void tst_quick3dnodeinstantiator::stringModel() { QQmlEngine engine; |