diff options
Diffstat (limited to 'src/core/nodes/qentity.cpp')
-rw-r--r-- | src/core/nodes/qentity.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp index 69d774dd1..164e0feff 100644 --- a/src/core/nodes/qentity.cpp +++ b/src/core/nodes/qentity.cpp @@ -239,6 +239,10 @@ QNodeId QEntityPrivate::parentEntityId() const QNodeCreatedChangeBasePtr QEntity::createNodeCreationChange() const { + // connect to the parentChanged signal here rather than constructor because + // until now there's no backend node to notify when parent changes + connect(this, &QNode::parentChanged, this, &QEntity::onParentChanged); + auto creationChange = QNodeCreatedChangePtr<QEntityData>::create(this); auto &data = creationChange->data; @@ -268,6 +272,17 @@ QNodeCreatedChangeBasePtr QEntity::createNodeCreationChange() const return creationChange; } +void QEntity::onParentChanged(QObject *) +{ + const auto parentID = parentEntity() ? parentEntity()->id() : Qt3DCore::QNodeId(); + auto parentChange = Qt3DCore::QPropertyUpdatedChangePtr::create(id()); + parentChange->setPropertyName("parentEntityUpdated"); + parentChange->setValue(QVariant::fromValue(parentID)); + const bool blocked = blockNotifications(false); + notifyObservers(parentChange); + blockNotifications(blocked); +} + } // namespace Qt3DCore QT_END_NAMESPACE |