OpenCoverage

qquickcustomaffector.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickcustomaffector.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 "qquickcustomaffector_p.h"-
41#include <private/qv8engine_p.h>-
42#include <private/qqmlengine_p.h>-
43#include <private/qqmlglobal_p.h>-
44#include <QQmlEngine>-
45#include <QDebug>-
46QT_BEGIN_NAMESPACE-
47-
48//TODO: Move docs (and inheritence) to real base when docs can propagate. Currently this pretends to be the base class!-
49/*!-
50 \qmlsignal QtQuick.Particles::Affector::affectParticles(Array particles, real dt)-
51-
52 This signal is emitted when particles are selected to be affected. particles contains-
53 an array of particle objects which can be directly manipulated.-
54-
55 dt is the time since the last time it was affected. Use dt to normalize-
56 trajectory manipulations to real time.-
57-
58 Note that JavaScript is slower to execute, so it is not recommended to use this in-
59 high-volume particle systems.-
60-
61 The corresponding handler is \c onAffectParticles.-
62*/-
63-
64/*!-
65 \qmlproperty StochasticDirection QtQuick.Particles::Affector::position-
66-
67 Affected particles will have their position set to this direction,-
68 relative to the ParticleSystem. When interpreting directions as points,-
69 imagine it as an arrow with the base at the 0,0 of the ParticleSystem and the-
70 tip at where the specified position will be.-
71*/-
72-
73/*!-
74 \qmlproperty StochasticDirection QtQuick.Particles::Affector::velocity-
75-
76 Affected particles will have their velocity set to this direction.-
77*/-
78-
79-
80/*!-
81 \qmlproperty StochasticDirection QtQuick.Particles::Affector::acceleration-
82-
83 Affected particles will have their acceleration set to this direction.-
84*/-
85-
86-
87/*!-
88 \qmlproperty bool QtQuick.Particles::Affector::relative-
89-
90 Whether the affected particles have their existing position/velocity/acceleration added-
91 to the new one.-
92-
93 Default is true.-
94*/-
95QQuickCustomAffector::QQuickCustomAffector(QQuickItem *parent) :-
96 QQuickParticleAffector(parent)-
97 , m_position(&m_nullVector)-
98 , m_velocity(&m_nullVector)-
99 , m_acceleration(&m_nullVector)-
100 , m_relative(true)-
101{-
102}
executed 24 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickcustomaffector
  • tst_qquickparticlesystem
24
103-
104bool QQuickCustomAffector::isAffectConnected()-
105{-
106 IS_SIGNAL_CONNECTED(this, QQuickCustomAffector, affectParticles, (QQmlV4Handle,qreal));
executed 324 times by 1 test: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);
Executed by:
  • tst_qquickcustomaffector
324
107}
never executed: end of block
0
108-
109void QQuickCustomAffector::affectSystem(qreal dt)-
110{-
111 //Acts a bit differently, just emits affected for everyone it might affect, when the only thing is connecting to affected(x,y)-
112 bool justAffected = (m_acceleration == &m_nullVector
m_acceleration... &m_nullVectorDescription
TRUEevaluated 243 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 81 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
81-243
113 && m_velocity == &m_nullVector
m_velocity == &m_nullVectorDescription
TRUEevaluated 243 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-243
114 && m_position == &m_nullVector
m_position == &m_nullVectorDescription
TRUEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 82 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
82-161
115 && isAffectedConnected());
isAffectedConnected()Description
TRUEevaluated 82 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 79 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
79-82
116 if (!isAffectConnected() && !justAffected) {
!isAffectConnected()Description
TRUEevaluated 245 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 79 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
!justAffectedDescription
TRUEevaluated 163 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 82 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
79-245
117 QQuickParticleAffector::affectSystem(dt);-
118 return;
executed 163 times by 1 test: return;
Executed by:
  • tst_qquickcustomaffector
163
119 }-
120 if (!m_enabled)
!m_enabledDescription
TRUEnever evaluated
FALSEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-161
121 return;
never executed: return;
0
122 updateOffsets();-
123-
124 QList<QQuickParticleData*> toAffect;-
125 foreach (QQuickParticleGroupData* gd, m_system->groupData) {
_container_.controlDescription
TRUEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
_container_.controlDescription
TRUEevaluated 322 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-322
126 if (activeGroup(gd->index)) {
activeGroup(gd->index)Description
TRUEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-161
127 foreach (QQuickParticleData* d, gd->data) {
_container_.controlDescription
TRUEevaluated 80500 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 80500 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
_container_.controlDescription
TRUEevaluated 80661 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 80500 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 161 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-80661
128 if (shouldAffect(d)) {
shouldAffect(d)Description
TRUEevaluated 2512 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 77988 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
2512-77988
129 toAffect << d;-
130 }
executed 2512 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
2512
131 }
executed 80500 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
80500
132 }
executed 161 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
161
133 }
executed 161 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
161
134-
135 if (toAffect.isEmpty())
toAffect.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 157 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
4-157
136 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qquickcustomaffector
4
137-
138 if (justAffected) {
justAffectedDescription
TRUEevaluated 80 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
77-80
139 foreach (QQuickParticleData* d, toAffect) {//Not postAffect to avoid saying the particle changed
_container_.controlDescription
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 1280 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
_container_.controlDescription
TRUEevaluated 1360 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 80 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-1360
140 if (m_onceOff)
m_onceOffDescription
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-1280
141 m_onceOffed << qMakePair(d->groupId, d->index);
executed 1280 times by 1 test: m_onceOffed << qMakePair(d->groupId, d->index);
Executed by:
  • tst_qquickcustomaffector
1280
142 emit affected(d->curX(m_system), d->curY(m_system));-
143 }
executed 1280 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
1280
144 return;
executed 80 times by 1 test: return;
Executed by:
  • tst_qquickcustomaffector
80
145 }-
146-
147 if (m_onceOff)
m_onceOffDescription
TRUEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-77
148 dt = 1.0;
executed 77 times by 1 test: dt = 1.0;
Executed by:
  • tst_qquickcustomaffector
77
149-
150 QQmlEngine *qmlEngine = ::qmlEngine(this);-
151 QV4::ExecutionEngine *v4 = qmlEngine->handle();-
152-
153 QV4::Scope scope(v4);-
154 QV4::ScopedArrayObject array(scope, v4->newArrayObject(toAffect.size()));-
155 QV4::ScopedValue v(scope);-
156 for (int i=0; i<toAffect.size(); i++)
i<toAffect.size()Description
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
77-1232
157 array->put(i, (v = toAffect[i]->v4Value(m_system)));
executed 1232 times by 1 test: array->put(i, (v = toAffect[i]->v4Value(m_system)));
Executed by:
  • tst_qquickcustomaffector
1232
158-
159 if (dt >= simulationCutoff || dt <= simulationDelta) {
dt >= simulationCutoffDescription
TRUEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
dt <= simulationDeltaDescription
TRUEnever evaluated
FALSEnever evaluated
0-77
160 affectProperties(toAffect, dt);-
161 emit affectParticles(QQmlV4Handle(array), dt);-
162 } else {
executed 77 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
77
163 int realTime = m_system->timeInt;-
164 m_system->timeInt -= dt * 1000.0;-
165 while (dt > simulationDelta) {
dt > simulationDeltaDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 m_system->timeInt += simulationDelta * 1000.0;-
167 dt -= simulationDelta;-
168 affectProperties(toAffect, simulationDelta);-
169 emit affectParticles(QQmlV4Handle(array), simulationDelta);-
170 }
never executed: end of block
0
171 m_system->timeInt = realTime;-
172 if (dt > 0.0) {
dt > 0.0Description
TRUEnever evaluated
FALSEnever evaluated
0
173 affectProperties(toAffect, dt);-
174 emit affectParticles(QQmlV4Handle(array), dt);-
175 }
never executed: end of block
0
176 }
never executed: end of block
0
177-
178 foreach (QQuickParticleData* d, toAffect)
_container_.controlDescription
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
_container_.controlDescription
TRUEevaluated 1309 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-1309
179 if (d->update == 1.0)
d->update == 1.0Description
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-1232
180 postAffect(d);
executed 1232 times by 1 test: postAffect(d);
Executed by:
  • tst_qquickcustomaffector
1232
181}
executed 77 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
77
182-
183bool QQuickCustomAffector::affectParticle(QQuickParticleData *d, qreal dt)-
184{-
185 //This does the property based affecting, called by superclass if signal isn't hooked up.-
186 bool changed = false;-
187 QPointF curPos(d->curX(m_system), d->curY(m_system));-
188-
189 if (m_acceleration != &m_nullVector){
m_acceleration... &m_nullVectorDescription
TRUEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 26072 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
24342-26072
190 QPointF pos = m_acceleration->sample(curPos);-
191 QPointF curAcc = QPointF(d->curAX(), d->curAY());-
192 if (m_relative) {
m_relativeDescription
TRUEnever evaluated
FALSEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-24342
193 pos *= dt;-
194 pos += curAcc;-
195 }
never executed: end of block
0
196 if (pos != curAcc) {
pos != curAccDescription
TRUEevaluated 1264 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 23078 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
1264-23078
197 d->setInstantaneousAX(pos.x(), m_system);-
198 d->setInstantaneousAY(pos.y(), m_system);-
199 changed = true;-
200 }
executed 1264 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
1264
201 }
executed 24342 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
24342
202-
203 if (m_velocity != &m_nullVector){
m_velocity != &m_nullVectorDescription
TRUEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 26072 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
24342-26072
204 QPointF pos = m_velocity->sample(curPos);-
205 QPointF curVel = QPointF(d->curVX(m_system), d->curVY(m_system));-
206 if (m_relative) {
m_relativeDescription
TRUEnever evaluated
FALSEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-24342
207 pos *= dt;-
208 pos += curVel;-
209 }
never executed: end of block
0
210 if (pos != curVel) {
pos != curVelDescription
TRUEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
0-24342
211 d->setInstantaneousVX(pos.x(), m_system);-
212 d->setInstantaneousVY(pos.y(), m_system);-
213 changed = true;-
214 }
executed 24342 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
24342
215 }
executed 24342 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
24342
216-
217 if (m_position != &m_nullVector){
m_position != &m_nullVectorDescription
TRUEevaluated 49182 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
1232-49182
218 QPointF pos = m_position->sample(curPos);-
219 if (m_relative) {
m_relativeDescription
TRUEnever evaluated
FALSEevaluated 49182 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-49182
220 pos *= dt;-
221 pos += curPos;-
222 }
never executed: end of block
0
223 if (pos != curPos) {
pos != curPosDescription
TRUEevaluated 24342 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 24840 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
24342-24840
224 d->setInstantaneousX(pos.x(), m_system);-
225 d->setInstantaneousY(pos.y(), m_system);-
226 changed = true;-
227 }
executed 24342 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
24342
228 }
executed 49182 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
49182
229-
230 return changed;
executed 50414 times by 1 test: return changed;
Executed by:
  • tst_qquickcustomaffector
50414
231}-
232-
233void QQuickCustomAffector::affectProperties(const QList<QQuickParticleData*> particles, qreal dt)-
234{-
235 foreach (QQuickParticleData* d, particles)
_container_.controlDescription
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
_container_.controlDescription
TRUEevaluated 1309 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
FALSEevaluated 77 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-1309
236 if ( affectParticle(d, dt) )
affectParticle(d, dt)Description
TRUEnever evaluated
FALSEevaluated 1232 times by 1 test
Evaluated by:
  • tst_qquickcustomaffector
0-1232
237 d->update = 1.0;
never executed: d->update = 1.0;
0
238}
executed 77 times by 1 test: end of block
Executed by:
  • tst_qquickcustomaffector
77
239-
240QT_END_NAMESPACE-
241-
242#include "moc_qquickcustomaffector_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0