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 /src/quick3d/quick3d/items | |
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 'src/quick3d/quick3d/items')
-rw-r--r-- | src/quick3d/quick3d/items/quick3dnodeinstantiator.cpp | 12 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3dnodeinstantiator_p.h | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/quick3d/quick3d/items/quick3dnodeinstantiator.cpp b/src/quick3d/quick3d/items/quick3dnodeinstantiator.cpp index c6e8aa7c1..b99f6ae75 100644 --- a/src/quick3d/quick3d/items/quick3dnodeinstantiator.cpp +++ b/src/quick3d/quick3d/items/quick3dnodeinstantiator.cpp @@ -245,6 +245,7 @@ void Quick3DNodeInstantiatorPrivate::makeModel() Quick3DNodeInstantiator::Quick3DNodeInstantiator(QNode *parent) : QNode(*new Quick3DNodeInstantiatorPrivate, parent) { + connect(this, &QNode::parentChanged, this, &Quick3DNodeInstantiator::onParentChanged); } /*! @@ -501,6 +502,17 @@ void Quick3DNodeInstantiator::componentComplete() } } +/*! + \internal +*/ +void Quick3DNodeInstantiator::onParentChanged(QObject *parent) +{ + Q_D(const Quick3DNodeInstantiator); + auto parentNode = static_cast<QNode *>(parent); + for (auto obj : d->m_objects) + static_cast<QNode *>(obj.data())->setParent(parentNode); +} + // TODO: Avoid cloning here //void Quick3DNodeInstantiator::copy(const QNode *ref) //{ diff --git a/src/quick3d/quick3d/items/quick3dnodeinstantiator_p.h b/src/quick3d/quick3d/items/quick3dnodeinstantiator_p.h index fd7a1d83d..a79cb4f90 100644 --- a/src/quick3d/quick3d/items/quick3dnodeinstantiator_p.h +++ b/src/quick3d/quick3d/items/quick3dnodeinstantiator_p.h @@ -113,6 +113,9 @@ Q_SIGNALS: void objectAdded(int index, QObject *object); void objectRemoved(int index, QObject *object); +private slots: + void onParentChanged(QObject *parent); + private: Q_DISABLE_COPY(Quick3DNodeInstantiator) Q_DECLARE_PRIVATE(Quick3DNodeInstantiator) |