Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dparticleemitburst.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
8#include <qdebug.h>
9
11
12/*!
13 \qmltype EmitBurst3D
14 \inherits QtObject
15 \inqmlmodule QtQuick3D.Particles3D
16 \brief Declarative emitter bursts.
17 \since 6.2
18
19 This element defines particle bursts in the \l ParticleEmitter3D. These bursts are
20 static, meaning that they are evaluated when the particlesystem starts. This allows
21 better performance than \l DynamicBurst3D and bursting outside of the particlesystem
22 time (so e.g. burst at 1000ms while system time starts from 2000ms).
23 \note EmitBurst3D uses emitter properties (position, rotation etc.) at the
24 particlesystem start. For dynamic emitters, use \l DynamicBurst3D instead.
25
26 For example, to emit 100 particles at the beginning, and 50 particles at 2 seconds,
27 so that both bursts take 200 milliseconds:
28
29 \qml
30 ParticleEmitter3D {
31 ...
32 emitBursts: [
33 EmitBurst3D {
34 time: 0
35 amount: 100
36 duration: 200
37 },
38 EmitBurst3D {
39 time: 2000
40 amount: 50
41 duration: 200
42 }
43 ]
44 }
45 \endqml
46*/
47
48QQuick3DParticleEmitBurst::QQuick3DParticleEmitBurst(QObject *parent)
49 : QObject(parent)
50{
51 m_parentEmitter = qobject_cast<QQuick3DParticleEmitter *>(parent);
52}
53
54QQuick3DParticleEmitBurst::~QQuick3DParticleEmitBurst()
55{
56 if (m_parentEmitter)
57 m_parentEmitter->unRegisterEmitBurst(this);
58}
59
60/*!
61 \qmlproperty int EmitBurst3D::time
62
63 This property defines the time in milliseconds when emitting the burst starts.
64
65 The default value is \c 0.
66*/
67int QQuick3DParticleEmitBurst::time() const
68{
69 return m_time;
70}
71
72/*!
73 \qmlproperty int EmitBurst3D::amount
74
75 This property defines the amount of particles emitted during the burst.
76
77 The default value is \c 0.
78*/
79int QQuick3DParticleEmitBurst::amount() const
80{
81 return m_amount;
82}
83
84/*!
85 \qmlproperty int EmitBurst3D::duration
86
87 This property defines the duration of the burst. The default value is 0,
88 meaning all particles will burst at the beginning of \l time.
89 If the duration is set, particles emitting is distributed between \c time
90 and \c time + \c duration.
91
92 For example, to have emit rate of 400 between 1000 and 1200 milliseconds:
93 \qml
94 EmitBurst3D {
95 time: 1000
96 amount: 80
97 duration: 1200
98 }
99 \endqml
100
101 The default value is \c 0.
102*/
103int QQuick3DParticleEmitBurst::duration() const
104{
105 return m_duration;
106}
107
108void QQuick3DParticleEmitBurst::setTime(int time)
109{
110 if (m_time == time)
111 return;
112
113 m_time = time;
114 Q_EMIT timeChanged();
115}
116
117void QQuick3DParticleEmitBurst::setAmount(int amount)
118{
119 if (m_amount == amount)
120 return;
121 if (amount < 0) {
122 qWarning () << "EmitBurst3D: Amount must be positive.";
123 return;
124 }
125 m_amount = amount;
126 Q_EMIT amountChanged();
127}
128
129void QQuick3DParticleEmitBurst::setDuration(int duration)
130{
131 if (m_duration == duration)
132 return;
133 if (duration < 0) {
134 qWarning () << "EmitBurst3D: Duration must be positive.";
135 return;
136 }
137 m_duration = duration;
138 Q_EMIT durationChanged();
139}
140
141void QQuick3DParticleEmitBurst::componentComplete()
142{
143 m_parentEmitter = qobject_cast<QQuick3DParticleEmitter *>(parent());
144 if (m_parentEmitter)
145 m_parentEmitter->registerEmitBurst(this);
146 else
147 qWarning() << "EmitBurst requires parent Emitter to function correctly!";
148}
149
150QT_END_NAMESPACE
Combined button and popup list for selecting options.