diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-06-09 15:26:58 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-06-11 19:27:56 +0000 |
commit | 3fc58a37f50cbae3d3e551dc6311771b561175cd (patch) | |
tree | f85094e6b55b450f2a2656427f07cf82f7b7d6a9 /src/core/nodes/qcomponent.cpp | |
parent | 1d2818870034eacb1b0b6de3df279284d3ad24c3 (diff) |
QNode parent changes
- introduce QNode::setParent(QNode *)
- QNode created with explicit parent now invoke
QNodePrivate::_q_addChild
- QNode::cleanup introduces, need to be added to the
dtor of every QT3D_CLONABLE QNode subclass. Handles
proper destruction.
- QNode::cleanup added to all classes that should have it.
- Updated unit tests of Nodes, Entity, Scene
Change-Id: Id2c2784122a78edaae5580fe5976d88be5a1921c
Task-number: QTBUG-45947
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core/nodes/qcomponent.cpp')
-rw-r--r-- | src/core/nodes/qcomponent.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/core/nodes/qcomponent.cpp b/src/core/nodes/qcomponent.cpp index 4194c68e4..9f2cdbd66 100644 --- a/src/core/nodes/qcomponent.cpp +++ b/src/core/nodes/qcomponent.cpp @@ -38,7 +38,7 @@ #include "qcomponent_p.h" #include "qentity.h" #include "qentity_p.h" - +#include "qsceneinterface.h" #include <Qt3DCore/qscenepropertychange.h> QT_BEGIN_NAMESPACE @@ -60,6 +60,12 @@ void QComponentPrivate::addEntity(QEntity *entity) { m_entities.append(entity); + if (m_scene != Q_NULLPTR) { + if (!m_shareable && !m_scene->entitiesForComponent(m_id).isEmpty()) + qWarning() << "Trying to assign a non shareable component to more than one Entity"; + m_scene->addEntityForComponent(m_id, entity->id()); + } + // We notify only if we have a QChangeArbiter if (m_changeArbiter != Q_NULLPTR) { Q_Q(QComponent); @@ -81,6 +87,9 @@ void QComponentPrivate::removeEntity(QEntity *entity) notifyObservers(e); } + if (m_scene != Q_NULLPTR) + m_scene->removeEntityForComponent(m_id, entity->id()); + m_entities.removeAll(entity); } @@ -116,6 +125,8 @@ QComponent::QComponent(QNode *parent) QComponent::~QComponent() { + Q_ASSERT_X(QNodePrivate::get(this)->m_wasCleanedUp, Q_FUNC_INFO, "QNode::cleanup should have been called by now. A Qt3D::QComponent subclass didn't call QNode::cleanup in its destructor"); + Q_FOREACH (QEntity *entity, entities()) { QEntityPrivate *entityPimpl = dynamic_cast<QEntityPrivate *>(QEntityPrivate::get(entity)); if (entityPimpl) |