summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-07-11 15:50:10 +0200
committerPaul Lemire <paul.lemire@kdab.com>2018-07-18 07:46:28 +0000
commit5376853866e49b5a6841c6c41affef5a3d3d4bb5 (patch)
treed9460391f5811c75947ad9ba0bb9b0c308b29f95 /tests
parentc39e20dcc693b525f2ee2259e864487d664c3856 (diff)
QNode: _q_postConstructorInit set scene on whole subtree
_q_postConstrutorInit is called in a deferred invocation when constructing a Node with a parent. If several nodes are created that way, the _q_postConstructorInit call from the node which parents the other will actually build the node creation changes for the whole subtree and incidently prevent the _q_postConstructorInit invocation for the children to do anything (including setting the scene). Therefore _q_postConstructorInit should set the scene on all the Node it will be creating creation changes for. Change-Id: I07d4e80675758b9701cc941881f1faaa1c89af4b Task-number: QTBUG-69352 Reviewed-by: Svenn-Arne Dragly <svenn-arne.dragly@qt.io> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/nodes/tst_nodes.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp
index d81a229cc..75d7a7799 100644
--- a/tests/auto/core/nodes/tst_nodes.cpp
+++ b/tests/auto/core/nodes/tst_nodes.cpp
@@ -83,6 +83,7 @@ private slots:
void checkConstructionSetParentMix(); // QTBUG-60612
void checkConstructionWithParent();
void checkConstructionAsListElement();
+ void checkSceneIsSetOnConstructionWithParent(); // QTBUG-69352
void appendingComponentToEntity();
void appendingParentlessComponentToEntity();
@@ -1162,6 +1163,52 @@ void tst_Nodes::checkConstructionAsListElement()
QCOMPARE(newChildEvent->addedNodeId(), node->id());
}
+void tst_Nodes::checkSceneIsSetOnConstructionWithParent()
+{
+ // GIVEN
+ ObserverSpy spy;
+ Qt3DCore::QScene scene;
+ QScopedPointer<MyQNode> root(new MyQNode());
+
+ // WHEN
+ root->setArbiterAndScene(&spy, &scene);
+ root->setSimulateBackendCreated(true);
+
+ // THEN
+ QVERIFY(Qt3DCore::QNodePrivate::get(root.data())->scene() != nullptr);
+
+ // WHEN
+ Qt3DCore::QEntity *subTreeRoot = new Qt3DCore::QEntity(root.data());
+
+ QVector<Qt3DCore::QEntity *> children;
+ QVector<Qt3DCore::QComponent *> cmps;
+ children.reserve(5);
+ cmps.reserve(5);
+ for (int i = 0; i < 5; ++i) {
+ const auto cmp = new MyQComponent(subTreeRoot);
+ cmps << cmp;
+ children << new Qt3DCore::QEntity(cmp);
+
+ // When cmp is full created, it will also send the creation change for its child entity
+ }
+ QCoreApplication::processEvents();
+ QCOMPARE(root->children().count(), 1);
+ QCOMPARE(subTreeRoot->children().count(), 5);
+ QCOMPARE(spy.events.size(), 12); // 1 subTreeRoot creation change, 5 child creation, 5 cmp creation, 1 child added (subTree to root)
+
+
+ spy.events.clear();
+
+ // Add component in a separate loop to ensure components are added after
+ // entities have been fully created
+ for (int i = 0; i < 5; ++i) {
+ children.at(i)->addComponent(cmps.at(i));
+ }
+
+ // THEN
+ QCOMPARE(spy.events.size(), 10); // 5 QComponentAddedChange(entity, cmp) and 5 QComponentAddedChange(cmp, entity)
+}
+
void tst_Nodes::appendingParentlessComponentToEntity()
{
// GIVEN
@@ -1588,6 +1635,8 @@ void tst_Nodes::checkTrackedPropertyNamesUpdate()
}
+
+
QTEST_MAIN(tst_Nodes)
#include "tst_nodes.moc"