diff options
author | Liang Qi <liang.qi@qt.io> | 2018-01-22 13:21:04 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-01-22 14:08:36 +0100 |
commit | 598acd70a44f787a3e72c586576bfc028d5af02d (patch) | |
tree | 30691da4bbdb935dbf592d9689d034060b9d4d74 /tests/auto/core/nodes/tst_nodes.cpp | |
parent | 32a511a667bab93d4fca2e71b38d89f8d76aa07c (diff) | |
parent | 2b19bde378e084331b1b7ba9aa076270492999bb (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/render/backend/renderer_p.h
src/render/geometry/geometryrenderer.cpp
src/render/geometry/qmesh.cpp
src/render/geometry/qmesh_p.h
tests/auto/render/commons/testrenderer.h
tests/auto/render/meshfunctors/tst_meshfunctors.cpp
tests/auto/render/qmesh/tst_qmesh.cpp
Change-Id: Ia078029e2faf23fe253c5ce385e393c094266e3b
Diffstat (limited to 'tests/auto/core/nodes/tst_nodes.cpp')
-rw-r--r-- | tests/auto/core/nodes/tst_nodes.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 6dcd1bd13..0ec661fed 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -80,6 +80,7 @@ private slots: void removingChildEntitiesFromNode(); void checkConstructionSetParentMix(); // QTBUG-60612 + void checkConstructionWithParent(); void appendingComponentToEntity(); void appendingParentlessComponentToEntity(); @@ -169,13 +170,17 @@ void SimplePostman::notifyBackend(const Qt3DCore::QSceneChangePtr &change) m_spy->sceneChangeEventWithLock(change); } + + class MyQNode : public Qt3DCore::QNode { Q_OBJECT Q_PROPERTY(QString customProperty READ customProperty WRITE setCustomProperty NOTIFY customPropertyChanged) + Q_PROPERTY(MyQNode *nodeProperty READ nodeProperty WRITE setNodeProperty NOTIFY nodePropertyChanged) public: explicit MyQNode(Qt3DCore::QNode *parent = 0) : QNode(parent) + , m_nodeProperty(nullptr) {} ~MyQNode() @@ -211,11 +216,37 @@ public: Qt3DCore::QNodePrivate::get(this)->m_hasBackendNode = created; } + MyQNode *nodeProperty() const { return m_nodeProperty; } + +public slots: + void setNodeProperty(MyQNode *node) + { + Qt3DCore::QNodePrivate *d = Qt3DCore::QNodePrivate::get(this); + if (m_nodeProperty == node) + return; + + if (m_nodeProperty) + d->unregisterDestructionHelper(m_nodeProperty); + + if (node && !node->parent()) + node->setParent(this); + + m_nodeProperty = node; + + // Ensures proper bookkeeping + if (m_nodeProperty) + d->registerDestructionHelper(m_nodeProperty, &MyQNode::setNodeProperty, m_nodeProperty); + + emit nodePropertyChanged(node); + } + signals: void customPropertyChanged(); + void nodePropertyChanged(MyQNode *node); protected: QString m_customProperty; + MyQNode *m_nodeProperty; }; class MyQEntity : public Qt3DCore::QEntity @@ -847,6 +878,49 @@ void tst_Nodes::checkConstructionSetParentMix() QCOMPARE(lastEvent->addedNodeId(), subTreeRoot->id()); } +void tst_Nodes::checkConstructionWithParent() +{ + // 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 we create a child and then set it as a Node* property + auto *node = new MyQNode(root.data()); + root->setNodeProperty(node); + + // THEN we should get one creation change, one child added change + // and one property change event, in that order. + QCoreApplication::processEvents(); + QCOMPARE(root->children().count(), 1); + QCOMPARE(spy.events.size(), 3); // 1 creation change, 1 child added change, 1 property change + + // Ensure first event is child node's creation change + const auto creationEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!creationEvent.isNull()); + QCOMPARE(creationEvent->subjectId(), node->id()); + + const auto newChildEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); + QVERIFY(!newChildEvent.isNull()); + QCOMPARE(newChildEvent->subjectId(), root->id()); + QCOMPARE(newChildEvent->propertyName(), "children"); + QCOMPARE(newChildEvent->addedNodeId(), node->id()); + + // Ensure second and last event is property set change + const auto propertyEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyUpdatedChange>(); + QVERIFY(!propertyEvent.isNull()); + QCOMPARE(propertyEvent->subjectId(), root->id()); + QCOMPARE(propertyEvent->propertyName(), "nodeProperty"); + QCOMPARE(propertyEvent->value().value<Qt3DCore::QNodeId>(), node->id()); +} + void tst_Nodes::appendingParentlessComponentToEntity() { // GIVEN |