1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
6#include "qquickparticlegroup_p.h"
7
8/*!
9 \qmltype ParticleGroup
10 \nativetype QQuickParticleGroup
11 \inqmlmodule QtQuick.Particles
12 \brief For setting attributes on a logical particle group.
13 \ingroup qtquick-particles
14
15 This element allows you to set timed transitions on particle groups.
16
17 You can also use this element to group particle system elements related to the logical
18 particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup
19 will automatically apply to that logical particle group. TrailEmitters will automatically follow
20 the group.
21
22 If a ParticleGroup element is not defined for a group, the group will function normally as if
23 none of the transition properties were set.
24*/
25/*!
26 \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::system
27 This is the system which will contain the group.
28
29 If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it.
30*/
31/*!
32 \qmlproperty string QtQuick.Particles::ParticleGroup::name
33 This is the name of the particle group, and how it is generally referred to by other elements.
34
35 If elements refer to a name which does not have an explicit ParticleGroup created, it will
36 work normally (with no transitions specified for the group). If you do not need to assign
37 duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may).
38*/
39/*!
40 \qmlproperty int QtQuick.Particles::ParticleGroup::duration
41 The time in milliseconds before the group will attempt to transition.
42
43*/
44/*!
45 \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::durationVariation
46 The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group.
47
48 Default value is zero.
49*/
50/*!
51 \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::to
52 The weighted list of transitions valid for this group.
53
54 If the chosen transition stays in this group, another duration (+/- up to durationVariation)
55 milliseconds will occur before another transition is attempted.
56*/
57
58QQuickParticleGroup::QQuickParticleGroup(QObject* parent)
59 : QQuickStochasticState(parent)
60 , m_system(nullptr)
61{
62
63}
64
65void delayedRedirect(QQmlListProperty<QObject> *prop, QObject *value)
66{
67 QQuickParticleGroup* pg = qobject_cast<QQuickParticleGroup*>(object: prop->object);
68 if (pg)
69 pg->delayRedirect(obj: value);
70}
71
72QQmlListProperty<QObject> QQuickParticleGroup::particleChildren()
73{
74 QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(object: parent());
75 if (system) {
76 return QQmlListProperty<QObject>(this, nullptr,
77 &QQuickParticleSystem::statePropertyRedirect, nullptr,
78 nullptr, nullptr, nullptr, nullptr);
79 } else {
80 return QQmlListProperty<QObject>(this, nullptr,
81 &delayedRedirect, nullptr, nullptr,
82 nullptr, nullptr, nullptr);
83 }
84}
85
86void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg)
87{
88 if (m_system != arg) {
89 m_system = arg;
90 m_system->registerParticleGroup(g: this);
91 performDelayedRedirects();
92 emit systemChanged(arg);
93 }
94}
95
96void QQuickParticleGroup::delayRedirect(QObject *obj)
97{
98 m_delayedRedirects << obj;
99}
100
101void QQuickParticleGroup::performDelayedRedirects()
102{
103 if (!m_system)
104 return;
105 foreach (QObject* obj, m_delayedRedirects)
106 m_system->stateRedirect(group: this, sys: m_system, value: obj);
107
108 m_delayedRedirects.clear();
109}
110
111void QQuickParticleGroup::componentComplete(){
112 if (!m_system && qobject_cast<QQuickParticleSystem*>(object: parent()))
113 setSystem(qobject_cast<QQuickParticleSystem*>(object: parent()));
114}
115
116#include "moc_qquickparticlegroup_p.cpp"
117

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtdeclarative/src/particles/qquickparticlegroup.cpp