OpenCoverage

qquicktrailemitter.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquicktrailemitter.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qquicktrailemitter_p.h"-
41#include <private/qqmlengine_p.h>-
42#include <private/qqmlglobal_p.h>-
43#include <QRandomGenerator>-
44#include <cmath>-
45QT_BEGIN_NAMESPACE-
46-
47/*!-
48 \qmltype TrailEmitter-
49 \instantiates QQuickTrailEmitter-
50 \inqmlmodule QtQuick.Particles-
51 \inherits QQuickParticleEmitter-
52 \brief Emits logical particles from other logical particles.-
53 \ingroup qtquick-particles-
54-
55 This element emits logical particles into the ParticleSystem, with the-
56 starting positions based on those of other logical particles.-
57*/-
58QQuickTrailEmitter::QQuickTrailEmitter(QQuickItem *parent) :-
59 QQuickParticleEmitter(parent)-
60 , m_particlesPerParticlePerSecond(0)-
61 , m_lastTimeStamp(0)-
62 , m_emitterXVariation(0)-
63 , m_emitterYVariation(0)-
64 , m_followCount(0)-
65 , m_emissionExtruder(nullptr)-
66 , m_defaultEmissionExtruder(new QQuickParticleExtruder(this))-
67{-
68 //TODO: If followed increased their size-
69 connect(this, SIGNAL(followChanged(QString)),-
70 this, SLOT(recalcParticlesPerSecond()));-
71 connect(this, SIGNAL(particleDurationChanged(int)),-
72 this, SLOT(recalcParticlesPerSecond()));-
73 connect(this, SIGNAL(particlesPerParticlePerSecondChanged(int)),-
74 this, SLOT(recalcParticlesPerSecond()));-
75}
executed 18 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquicktrailemitter
18
76-
77/*!-
78 \qmlproperty string QtQuick.Particles::TrailEmitter::follow-
79-
80 The type of logical particle which this is emitting from.-
81*/-
82/*!-
83 \qmlproperty qreal QtQuick.Particles::TrailEmitter::velocityFromMovement-
84-
85 If this value is non-zero, then any movement of the emitter will provide additional-
86 starting velocity to the particles based on the movement. The additional vector will be the-
87 same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters-
88 movement multiplied by velocityFromMovement.-
89-
90 Default value is 0.-
91*/-
92/*!-
93 \qmlproperty Shape QtQuick.Particles::TrailEmitter::emitShape-
94-
95 As the area of a TrailEmitter is the area it follows, a separate shape can be provided-
96 to be the shape it emits out of. This shape has width and height specified by emitWidth-
97 and emitHeight, and is centered on the followed particle's position.-
98-
99 The default shape is a filled Rectangle.-
100*/-
101/*!-
102 \qmlproperty real QtQuick.Particles::TrailEmitter::emitWidth-
103-
104 The width in pixels the emitShape is scaled to. If set to TrailEmitter.ParticleSize,-
105 the width will be the current size of the particle being followed.-
106-
107 Default is 0.-
108*/-
109/*!-
110 \qmlproperty real QtQuick.Particles::TrailEmitter::emitHeight-
111-
112 The height in pixels the emitShape is scaled to. If set to TrailEmitter.ParticleSize,-
113 the height will be the current size of the particle being followed.-
114-
115 Default is 0.-
116*/-
117/*!-
118 \qmlproperty real QtQuick.Particles::TrailEmitter::emitRatePerParticle-
119*/-
120/*!-
121 \qmlsignal QtQuick.Particles::TrailEmitter::emitFollowParticles(Array particles, Particle followed)-
122-
123 This signal is emitted when particles are emitted from the \a followed particle. \a particles contains an array of particle objects which can be directly manipulated.-
124-
125 The corresponding handler is \c onEmitFollowParticles. If you use this signal handler, emitParticles will not be emitted.-
126*/-
127-
128bool QQuickTrailEmitter::isEmitFollowConnected()-
129{-
130 IS_SIGNAL_CONNECTED(this, QQuickTrailEmitter, emitFollowParticles, (QQmlV4Handle,QQmlV4Handle));
executed 21850 times by 1 test: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);
Executed by:
  • tst_qquicktrailemitter
21850
131}
never executed: end of block
0
132-
133void QQuickTrailEmitter::recalcParticlesPerSecond(){-
134 if (!m_system)
!m_systemDescription
TRUEevaluated 50 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquicktrailemitter
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
2-50
135 return;
executed 50 times by 2 tests: return;
Executed by:
  • tst_examples
  • tst_qquicktrailemitter
50
136 m_followCount = m_system->groupData[m_system->groupIds[m_follow]]->size();-
137 if (!m_followCount){
!m_followCountDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-2
138 setParticlesPerSecond(1);//XXX: Fix this horrendous hack, needed so they aren't turned off from start (causes crashes - test that when gone you don't crash with 0 PPPS)-
139 }else{
never executed: end of block
0
140 setParticlesPerSecond(m_particlesPerParticlePerSecond * m_followCount);-
141 m_lastEmission.resize(m_followCount);-
142 m_lastEmission.fill(m_lastTimeStamp);-
143 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquicktrailemitter
2
144}-
145-
146void QQuickTrailEmitter::reset()-
147{-
148 m_followCount = 0;-
149}
executed 36 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquicktrailemitter
36
150-
151void QQuickTrailEmitter::emitWindow(int timeStamp)-
152{-
153 if (m_system == nullptr)
m_system == nullptrDescription
TRUEnever evaluated
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-76
154 return;
never executed: return;
0
155 if (!m_enabled && !m_pulseLeft && m_burstQueue.isEmpty())
!m_enabledDescription
TRUEnever evaluated
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
!m_pulseLeftDescription
TRUEnever evaluated
FALSEnever evaluated
m_burstQueue.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0-76
156 return;
never executed: return;
0
157 if (m_followCount != m_system->groupData[m_system->groupIds[m_follow]]->size()){
m_followCount ...llow]]->size()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 74 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
2-74
158 qreal oldPPS = m_particlesPerSecond;-
159 recalcParticlesPerSecond();-
160 if (m_particlesPerSecond != oldPPS)
m_particlesPerSecond != oldPPSDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEnever evaluated
0-2
161 return;//system may need to update
executed 2 times by 1 test: return;
Executed by:
  • tst_qquicktrailemitter
2
162 }
never executed: end of block
0
163-
164 if (m_pulseLeft){
m_pulseLeftDescription
TRUEnever evaluated
FALSEevaluated 74 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-74
165 m_pulseLeft -= timeStamp - m_lastTimeStamp * 1000.;-
166 if (m_pulseLeft < 0){
m_pulseLeft < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
167 timeStamp += m_pulseLeft;-
168 m_pulseLeft = 0;-
169 }
never executed: end of block
0
170 }
never executed: end of block
0
171-
172 //TODO: Implement startTime and velocityFromMovement-
173 qreal time = timeStamp / 1000.;-
174 qreal particleRatio = 1. / m_particlesPerParticlePerSecond;-
175 qreal pt;-
176 qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0;-
177-
178 //Have to map it into this system, because particlesystem automaps it back-
179 QPointF offset = m_system->mapFromItem(this, QPointF(0, 0));-
180 qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize;
m_particleEndSize >= 0Description
TRUEnever evaluated
FALSEevaluated 74 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-74
181-
182 int gId = m_system->groupIds[m_follow];-
183 int gId2 = groupId();-
184 for (int i=0; i<m_system->groupData[gId]->data.count(); i++) {
i<m_system->gr...->data.count()Description
TRUEevaluated 37000 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 74 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
74-37000
185 QQuickParticleData *d = m_system->groupData[gId]->data[i];-
186 if (!d->stillAlive(m_system)){
!d->stillAlive(m_system)Description
TRUEevaluated 15150 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
15150-21850
187 m_lastEmission[i] = time; //Should only start emitting when it returns to life-
188 continue;
executed 15150 times by 1 test: continue;
Executed by:
  • tst_qquicktrailemitter
15150
189 }-
190 pt = m_lastEmission[i];-
191 if (pt < d->t)
pt < d->tDescription
TRUEevaluated 978 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 20872 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
978-20872
192 pt = d->t;
executed 978 times by 1 test: pt = d->t;
Executed by:
  • tst_qquicktrailemitter
978
193 if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now
pt + maxLife < timeDescription
TRUEnever evaluated
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-21850
194 pt = time - maxLife;
never executed: pt = time - maxLife;
0
195-
196 if ((width() || height()) && !effectiveExtruder()->contains(QRectF(offset.x(), offset.y(), width(), height()),
!effectiveExtr...rY(m_system)))Description
TRUEnever evaluated
FALSEnever evaluated
0
197 QPointF(d->curX(m_system), d->curY(m_system)))) {
!effectiveExtr...rY(m_system)))Description
TRUEnever evaluated
FALSEnever evaluated
0
198 m_lastEmission[d->index] = time;//jump over this time period without emitting, because it's outside-
199 continue;
never executed: continue;
0
200 }-
201-
202 QList<QQuickParticleData*> toEmit;-
203-
204 while (pt < time || !m_burstQueue.isEmpty()){
pt < timeDescription
TRUEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
!m_burstQueue.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-21850
205 QQuickParticleData* datum = m_system->newDatum(gId2, !m_overwrite);-
206 if (datum){//else, skip this emission
datumDescription
TRUEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEnever evaluated
0-1182
207 // Particle timestamp-
208 datum->t = pt;-
209 datum->lifeSpan =-
210 (m_particleDuration-
211 + (QRandomGenerator::global()->bounded((m_particleDurationVariation*2) + 1) - m_particleDurationVariation))-
212 / 1000.0;-
213-
214 // Particle position-
215 // Note that burst location doesn't get used for follow emitter-
216 qreal followT = pt - d->t;-
217 qreal followT2 = followT * followT * 0.5;-
218 qreal eW = m_emitterXVariation < 0 ? d->curSize(m_system) : m_emitterXVariation;
m_emitterXVariation < 0Description
TRUEnever evaluated
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-1182
219 qreal eH = m_emitterYVariation < 0 ? d->curSize(m_system) : m_emitterYVariation;
m_emitterYVariation < 0Description
TRUEnever evaluated
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-1182
220 //Subtract offset, because PS expects this in emitter coordinates-
221 QRectF boundsRect(d->x - offset.x() + d->vx * followT + d->ax * followT2 - eW/2,-
222 d->y - offset.y() + d->vy * followT + d->ay * followT2 - eH/2,-
223 eW, eH);-
224-
225 QQuickParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder;
m_emissionExtruderDescription
TRUEnever evaluated
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-1182
226 const QPointF &newPos = effectiveEmissionExtruder->extrude(boundsRect);-
227 datum->x = newPos.x();-
228 datum->y = newPos.y();-
229-
230 // Particle velocity-
231 const QPointF &velocity = m_velocity->sample(newPos);-
232 datum->vx = velocity.x()-
233 + m_velocity_from_movement * d->vx;-
234 datum->vy = velocity.y()-
235 + m_velocity_from_movement * d->vy;-
236-
237 // Particle acceleration-
238 const QPointF &accel = m_acceleration->sample(newPos);-
239 datum->ax = accel.x();-
240 datum->ay = accel.y();-
241-
242 // Particle size-
243 float sizeVariation = -m_particleSizeVariation-
244 + QRandomGenerator::global()->generateDouble() * m_particleSizeVariation * 2;-
245-
246 float size = qMax((qreal)0.0, m_particleSize + sizeVariation);-
247 float endSize = qMax((qreal)0.0, sizeAtEnd + sizeVariation);-
248-
249 datum->size = size * float(m_enabled);-
250 datum->endSize = endSize * float(m_enabled);-
251-
252 toEmit << datum;-
253-
254 m_system->emitParticle(datum, this);-
255 }
executed 1182 times by 1 test: end of block
Executed by:
  • tst_qquicktrailemitter
1182
256 if (!m_burstQueue.isEmpty()){
!m_burstQueue.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-1182
257 m_burstQueue.first().first--;-
258 if (m_burstQueue.first().first <= 0)
m_burstQueue.f...t().first <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
259 m_burstQueue.pop_front();
never executed: m_burstQueue.pop_front();
0
260 }else{
never executed: end of block
0
261 pt += particleRatio;-
262 }
executed 1182 times by 1 test: end of block
Executed by:
  • tst_qquicktrailemitter
1182
263 }-
264-
265 foreach (QQuickParticleData* d, toEmit)
_container_.controlDescription
TRUEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
_container_.controlDescription
TRUEevaluated 23032 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 1182 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-23032
266 m_system->emitParticle(d, this);
executed 1182 times by 1 test: m_system->emitParticle(d, this);
Executed by:
  • tst_qquicktrailemitter
1182
267-
268 if (isEmitConnected() || isEmitFollowConnected()) {
isEmitConnected()Description
TRUEnever evaluated
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
isEmitFollowConnected()Description
TRUEnever evaluated
FALSEevaluated 21850 times by 1 test
Evaluated by:
  • tst_qquicktrailemitter
0-21850
269 QQmlEngine *qmlEngine = ::qmlEngine(this);-
270 QV4::ExecutionEngine *v4 = qmlEngine->handle();-
271-
272 QV4::Scope scope(v4);-
273 QV4::ScopedArrayObject array(scope, v4->newArrayObject(toEmit.size()));-
274 QV4::ScopedValue v(scope);-
275 for (int i=0; i<toEmit.size(); i++)
i<toEmit.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
276 array->put(i, (v = toEmit[i]->v4Value(m_system)));
never executed: array->put(i, (v = toEmit[i]->v4Value(m_system)));
0
277-
278 if (isEmitFollowConnected())
isEmitFollowConnected()Description
TRUEnever evaluated
FALSEnever evaluated
0
279 emitFollowParticles(QQmlV4Handle(array), d->v4Value(m_system));//A chance for many arbitrary JS changes
never executed: emitFollowParticles(QQmlV4Handle(array), d->v4Value(m_system));
0
280 else if (isEmitConnected())
isEmitConnected()Description
TRUEnever evaluated
FALSEnever evaluated
0
281 emitParticles(QQmlV4Handle(array));//A chance for arbitrary JS changes
never executed: emitParticles(QQmlV4Handle(array));
0
282 }
never executed: end of block
0
283 m_lastEmission[d->index] = pt;-
284 }
executed 21850 times by 1 test: end of block
Executed by:
  • tst_qquicktrailemitter
21850
285-
286 m_lastTimeStamp = time;-
287}
executed 74 times by 1 test: end of block
Executed by:
  • tst_qquicktrailemitter
74
288QT_END_NAMESPACE-
289-
290#include "moc_qquicktrailemitter_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0