diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index b4c8513dc50..6eb7a7146e0 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -104,6 +104,12 @@ #endif #endif +#ifdef QUICK3D_PARTICLES_MODULE +#include +#include +#include +#endif + #ifdef IMPORT_QUICK3D_ASSETS #include #endif @@ -412,7 +418,7 @@ void Qt5InformationNodeInstanceServer::resetParticleSystem() void Qt5InformationNodeInstanceServer::handleParticleSystemSelected(QQuick3DParticleSystem* targetParticleSystem) { - if (!m_particleAnimationDriver) + if (!m_particleAnimationDriver || targetParticleSystem == m_targetParticleSystem) return; m_particleAnimationDriver->reset(); @@ -453,7 +459,46 @@ static QString baseProperty(const QString &property) return property; } -void Qt5InformationNodeInstanceServer::handleParticleSystemDeselected() +template +static QQuick3DParticleSystem *systemProperty(QObject *object) +{ + return qobject_cast(object) ? qobject_cast(object)->system() : nullptr; +} + +static QQuick3DParticleSystem *getSystemOrSystemProperty(QObject *selectedObject) +{ + QQuick3DParticleSystem *system = nullptr; + system = qobject_cast(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + return nullptr; +} + +static QQuick3DParticleSystem *parentParticleSystem(QObject *selectedObject) +{ + auto *ps = getSystemOrSystemProperty(selectedObject); + if (ps) + return ps; + QObject *parent = selectedObject->parent(); + while (parent) { + ps = getSystemOrSystemProperty(parent); + if (ps) + return ps; + parent = parent->parent(); + } + return nullptr; +} + +void Qt5InformationNodeInstanceServer::handleParticleSystemDeselected(QObject *selectedObject) { m_targetParticleSystem = nullptr; const auto anim = animations(); @@ -1824,9 +1869,7 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm { if (!m_editView3DSetupDone) return; -#ifdef QUICK3D_PARTICLES_MODULE - resetParticleSystem(); -#endif + m_lastSelectionChangeCommand = command; if (m_selectionChangeTimer.isActive()) { // If selection was recently changed by puppet, hold updating the selection for a bit to @@ -1855,10 +1898,17 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm #ifdef QUICK3D_PARTICLES_MODULE auto particlesystem = qobject_cast(instance.internalObject()); - if (particlesystem) + if (particlesystem) { handleParticleSystemSelected(particlesystem); - else - handleParticleSystemDeselected(); + } else { + particlesystem = parentParticleSystem(instance.internalObject()); + if (particlesystem) { + if (particlesystem != m_targetParticleSystem) + handleParticleSystemSelected(particlesystem); + } else { + handleParticleSystemDeselected(instance.internalObject()); + } + } #endif auto isSelectableAsRoot = [&]() -> bool { #ifdef QUICK3D_MODULE diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index 25a4b900ce8..ef6f576dac9 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -149,7 +149,7 @@ private: #ifdef QUICK3D_PARTICLES_MODULE void handleParticleSystemSelected(QQuick3DParticleSystem* targetParticleSystem); void resetParticleSystem(); - void handleParticleSystemDeselected(); + void handleParticleSystemDeselected(QObject *selectedObject); #endif RenderViewData m_editView3DData;