From 9d9c5a786c1c3c5986461fc9d885ca7c5ef06b83 Mon Sep 17 00:00:00 2001 From: Fabio Falsini Date: Wed, 20 Nov 2019 20:04:30 +0100 Subject: Add QQuickItemParticle give() method body The current version of QQuickItemParticle give() method was not implemented and a simple TODO comment was present instead. I added a working body and add also a reparent feature when an added item is released. Fixes: QTBUG-76827 Change-Id: Ib7d289cad2ff0cd166e766eb7f07e92437e7681b Reviewed-by: Shawn Rutledge --- src/particles/qquickitemparticle.cpp | 24 +++++++++++++++++++----- src/particles/qquickitemparticle_p.h | 3 ++- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/particles') diff --git a/src/particles/qquickitemparticle.cpp b/src/particles/qquickitemparticle.cpp index fc28864746..740d0f60f3 100644 --- a/src/particles/qquickitemparticle.cpp +++ b/src/particles/qquickitemparticle.cpp @@ -159,8 +159,15 @@ void QQuickItemParticle::take(QQuickItem *item, bool prioritize) void QQuickItemParticle::give(QQuickItem *item) { - //TODO: This - Q_UNUSED(item); + for (auto groupId : groupIds()) { + for (QQuickParticleData* data : qAsConst(m_system->groupData[groupId]->data)) { + if (data->delegate == item){ + m_deletables << item; + data->delegate = nullptr; + return; + } + } + } } void QQuickItemParticle::initialize(int gIdx, int pIdx) @@ -179,8 +186,11 @@ void QQuickItemParticle::processDeletables() item->setOpacity(0.); item->setVisible(false); QQuickItemParticleAttached* mpa; - if ((mpa = qobject_cast(qmlAttachedPropertiesObject(item)))) - mpa->detach();//reparent as well? + if ((mpa = qobject_cast(qmlAttachedPropertiesObject(item)))) { + if (mpa->m_parentItem != nullptr) + item->setParentItem(mpa->m_parentItem); + mpa->detach(); + } int idx = -1; if ((idx = m_managed.indexOf(item)) != -1) { m_managed.takeAt(idx); @@ -205,9 +215,12 @@ void QQuickItemParticle::tick(int time) m_deletables << d->delegate; d->delegate = nullptr; } + QQuickItem* parentItem = nullptr; if (!m_pendingItems.isEmpty()){ - d->delegate = m_pendingItems.front(); + QQuickItem *item = m_pendingItems.front(); m_pendingItems.pop_front(); + parentItem = item->parentItem(); + d->delegate = item; }else if (m_delegate){ d->delegate = qobject_cast(m_delegate->create(qmlContext(this))); if (d->delegate) @@ -218,6 +231,7 @@ void QQuickItemParticle::tick(int time) d->delegate->setY(d->curY(m_system) - d->delegate->height() / 2); QQuickItemParticleAttached* mpa = qobject_cast(qmlAttachedPropertiesObject(d->delegate)); if (mpa){ + mpa->m_parentItem = parentItem; mpa->m_mp = this; mpa->attach(); } diff --git a/src/particles/qquickitemparticle_p.h b/src/particles/qquickitemparticle_p.h index 70cfe2a446..ea46c67db7 100644 --- a/src/particles/qquickitemparticle_p.h +++ b/src/particles/qquickitemparticle_p.h @@ -130,13 +130,14 @@ class QQuickItemParticleAttached : public QObject Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT); public: QQuickItemParticleAttached(QObject* parent) - : QObject(parent), m_mp(0) + : QObject(parent), m_mp(0), m_parentItem(nullptr) {;} QQuickItemParticle* particle() const { return m_mp; } void detach(){Q_EMIT detached();} void attach(){Q_EMIT attached();} private: QQuickItemParticle* m_mp; + QPointer m_parentItem; friend class QQuickItemParticle; Q_SIGNALS: void detached(); -- cgit v1.2.3