aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2023-09-19 17:14:51 +0300
committerThomas Hartmann <thomas.hartmann@qt.io>2023-09-22 07:20:10 +0000
commitc17250881e891c91c3ca5d76c4b2f801dfc72b58 (patch)
treec6f695ba64adbde5719fc1c91d7e545f1f8cb7a7
parent00865d944a112c824e85d35cd768b40fda5c4cc1 (diff)
QmlDesigner: Only play animations related to selected particle system
When particle mode is enabled in 3D view, only the animations related to the selected particle system are played instead of all animations in the scene. Timeline animations are never played, as those are controlled with timeline controls. Animation is considered related to selected particle system if the animation target is either descendant or ancestor of the selected system, or the system itself. Fixes: QDS-10678 Change-Id: Iaaaec14f86d61c7aba2347b16bc757fc188601a0 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> (cherry picked from commit 8d4b4fd04d157774073426f7488e8376ff5f438c) Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp63
1 files changed, 60 insertions, 3 deletions
diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
index 663adcf3e1..3491aa85a0 100644
--- a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
+++ b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
@@ -533,9 +533,66 @@ void Qt5InformationNodeInstanceServer::handleParticleSystemSelected(QQuick3DPart
}
});
- const auto anim = animations();
- for (auto a : anim)
- a->restart();
+ if (m_targetParticleSystem) {
+ auto checkAncestor = [](QObject *checkObj, QObject *ancestor) -> bool {
+ QObject *parent = checkObj->parent();
+ while (parent) {
+ if (parent == ancestor)
+ return true;
+ parent = parent->parent();
+ }
+ return false;
+ };
+ auto isAnimContainer = [](QObject *o) -> bool {
+ return ServerNodeInstance::isSubclassOf(o, "QQuickParallelAnimation")
+ || ServerNodeInstance::isSubclassOf(o, "QQuickSequentialAnimation");
+ };
+
+ const QVector<QQuickAbstractAnimation *> anims = animations();
+ QSet<QQuickAbstractAnimation *> containers;
+ for (auto a : anims) {
+ // Stop all animations by default. We only want to run animations related to currently
+ // active particle system and nothing else.
+ a->stop();
+
+ // Timeline animations are controlled by timeline controls, so exclude those
+ if (ServerNodeInstance::isSubclassOf(a, "QQuickTimelineAnimation"))
+ continue;
+
+ if (ServerNodeInstance::isSubclassOf(a, "QQuickPropertyAnimation")
+ || ServerNodeInstance::isSubclassOf(a, "QQuickPropertyAction")) {
+ QObject *target = a->property("target").value<QObject *>();
+ if (target != m_targetParticleSystem
+ && !checkAncestor(target, m_targetParticleSystem)
+ && !checkAncestor(m_targetParticleSystem, target)) {
+ continue;
+ }
+ } else {
+ continue;
+ }
+
+ QObject *animParent = a->parent();
+ bool isContained = isAnimContainer(animParent);
+ if (isContained) {
+ // We only want to start the toplevel container animations
+ while (isContained) {
+ if (isAnimContainer(animParent->parent())) {
+ animParent = animParent->parent();
+ isContained = true;
+ } else {
+ containers.insert(qobject_cast<QQuickAbstractAnimation *>(animParent));
+ isContained = false;
+ }
+ }
+ } else {
+ a->restart();
+ }
+ }
+
+ // Activate necessary container animations
+ for (auto container : std::as_const(containers))
+ container->restart();
+ }
}
static QString baseProperty(const QString &property)