animation/qvariantanimation.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8void QVariantAnimation::updateCurrentValue(const QVariant &) {} -
9 -
10static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2) -
11{ -
12 return p1.first < p2.first;
executed: return p1.first < p2.first;
Execution Count:3559
3559
13} -
14 -
15static QVariant defaultInterpolator(const void *, const void *, qreal) -
16{ -
17 return QVariant();
executed: return QVariant();
Execution Count:2
2
18} -
19 -
20template<> inline QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress) -
21{ -
22 QRect ret; -
23 ret.setCoords(_q_interpolate(f.left(), t.left(), progress), -
24 _q_interpolate(f.top(), t.top(), progress), -
25 _q_interpolate(f.right(), t.right(), progress), -
26 _q_interpolate(f.bottom(), t.bottom(), progress)); -
27 return ret;
executed: return ret;
Execution Count:564
564
28} -
29 -
30template<> inline QRectF _q_interpolate(const QRectF &f, const QRectF &t, qreal progress) -
31{ -
32 qreal x1, y1, w1, h1; -
33 f.getRect(&x1, &y1, &w1, &h1); -
34 qreal x2, y2, w2, h2; -
35 t.getRect(&x2, &y2, &w2, &h2); -
36 return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), 0
37 _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress));
never executed: return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress));
0
38} -
39 -
40template<> inline QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress) -
41{ -
42 return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
never executed: return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
0
43} -
44 -
45template<> inline QLineF _q_interpolate(const QLineF &f, const QLineF &t, qreal progress) -
46{ -
47 return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
never executed: return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
0
48} -
49 -
50QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator) -
51{ }
executed: }
Execution Count:1318
1318
52 -
53void QVariantAnimationPrivate::convertValues(int t) -
54{ -
55 -
56 for (int i = 0; i < keyValues.count(); ++i) {
evaluated: i < keyValues.count()
TRUEFALSE
yes
Evaluation Count:496
yes
Evaluation Count:896
496-896
57 QVariantAnimation::KeyValue &pair = keyValues[i]; -
58 pair.second.convert(static_cast<QVariant::Type>(t)); -
59 }
executed: }
Execution Count:496
496
60 -
61 currentInterval.start.second.convert(static_cast<QVariant::Type>(t)); -
62 currentInterval.end.second.convert(static_cast<QVariant::Type>(t)); -
63 -
64 -
65 updateInterpolator(); -
66}
executed: }
Execution Count:896
896
67 -
68void QVariantAnimationPrivate::updateInterpolator() -
69{ -
70 int type = currentInterval.start.second.userType(); -
71 if (type == currentInterval.end.second.userType())
evaluated: type == currentInterval.end.second.userType()
TRUEFALSE
yes
Evaluation Count:1589
yes
Evaluation Count:2
2-1589
72 interpolator = getInterpolator(type);
executed: interpolator = getInterpolator(type);
Execution Count:1589
1589
73 else -
74 interpolator = 0;
executed: interpolator = 0;
Execution Count:2
2
75 -
76 -
77 if (!interpolator)
evaluated: !interpolator
TRUEFALSE
yes
Evaluation Count:818
yes
Evaluation Count:773
773-818
78 interpolator = &defaultInterpolator;
executed: interpolator = &defaultInterpolator;
Execution Count:818
818
79}
executed: }
Execution Count:1591
1591
80 -
81 -
82 -
83 -
84 -
85 -
86 -
87void QVariantAnimationPrivate::recalculateCurrentInterval(bool force ) -
88{ -
89 -
90 if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
evaluated: (keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2
TRUEFALSE
yes
Evaluation Count:2081
yes
Evaluation Count:3313
evaluated: defaultStartEndValue.isValid()
TRUEFALSE
yes
Evaluation Count:2263
yes
Evaluation Count:3131
2081-3313
91 return;
executed: return;
Execution Count:2081
2081
92 -
93 const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
evaluated: (direction == QAbstractAnimation::Forward)
TRUEFALSE
yes
Evaluation Count:3051
yes
Evaluation Count:262
262-3051
94 const qreal progress = easing.valueForProgress(((duration == 0) ? endProgress : qreal(currentTime) / qreal(duration))); -
95 -
96 -
97 if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
evaluated: force
TRUEFALSE
yes
Evaluation Count:695
yes
Evaluation Count:2618
partially evaluated: currentInterval.start.first > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2618
never evaluated: progress < currentInterval.start.first
0-2618
98 || (currentInterval.end.first < 1 && progress > currentInterval.end.first)) {
partially evaluated: currentInterval.end.first < 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2618
never evaluated: progress > currentInterval.end.first
0-2618
99 -
100 QVariantAnimation::KeyValues::const_iterator it = std::lower_bound(keyValues.constBegin(), -
101 keyValues.constEnd(), -
102 qMakePair(progress, QVariant()), -
103 animationValueLessThan); -
104 if (it == keyValues.constBegin()) {
evaluated: it == keyValues.constBegin()
TRUEFALSE
yes
Evaluation Count:677
yes
Evaluation Count:18
18-677
105 -
106 if (it->first == 0 && keyValues.count() > 1) {
evaluated: it->first == 0
TRUEFALSE
yes
Evaluation Count:239
yes
Evaluation Count:438
evaluated: keyValues.count() > 1
TRUEFALSE
yes
Evaluation Count:238
yes
Evaluation Count:1
1-438
107 currentInterval.start = *it; -
108 currentInterval.end = *(it+1); -
109 } else {
executed: }
Execution Count:238
238
110 currentInterval.start = qMakePair(qreal(0), defaultStartEndValue); -
111 currentInterval.end = *it; -
112 }
executed: }
Execution Count:439
439
113 } else if (it == keyValues.constEnd()) {
evaluated: it == keyValues.constEnd()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16
2-16
114 --it; -
115 if (it->first == 1 && keyValues.count() > 1) {
partially evaluated: it->first == 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
never evaluated: keyValues.count() > 1
0-2
116 -
117 currentInterval.start = *(it-1); -
118 currentInterval.end = *it; -
119 } else {
never executed: }
0
120 -
121 currentInterval.start = *it; -
122 currentInterval.end = qMakePair(qreal(1), defaultStartEndValue); -
123 }
executed: }
Execution Count:2
2
124 } else { -
125 currentInterval.start = *(it-1); -
126 currentInterval.end = *it; -
127 }
executed: }
Execution Count:16
16
128 -
129 -
130 updateInterpolator(); -
131 }
executed: }
Execution Count:695
695
132 setCurrentValueForProgress(progress); -
133}
executed: }
Execution Count:3313
3313
134 -
135void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) -
136{ -
137 QVariantAnimation * const q = q_func(); -
138 -
139 const qreal startProgress = currentInterval.start.first; -
140 const qreal endProgress = currentInterval.end.first; -
141 const qreal localProgress = (progress - startProgress) / (endProgress - startProgress); -
142 -
143 QVariant ret = q->interpolated(currentInterval.start.second, -
144 currentInterval.end.second, -
145 localProgress); -
146 qSwap(currentValue, ret); -
147 q->updateCurrentValue(currentValue); -
148 static QBasicAtomicInt changedSignalIndex = { (0) }; -
149 if (!changedSignalIndex.load()) {
evaluated: !changedSignalIndex.load()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:3297
16-3297
150 -
151 changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)")); -
152 }
executed: }
Execution Count:16
16
153 if (isSignalConnected(changedSignalIndex.load()) && currentValue != ret) {
evaluated: isSignalConnected(changedSignalIndex.load())
TRUEFALSE
yes
Evaluation Count:65
yes
Evaluation Count:3248
evaluated: currentValue != ret
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:59
6-3248
154 -
155 q->valueChanged(currentValue); -
156 }
executed: }
Execution Count:6
6
157}
executed: }
Execution Count:3313
3313
158 -
159QVariant QVariantAnimationPrivate::valueAt(qreal step) const -
160{ -
161 QVariantAnimation::KeyValues::const_iterator result = -
162 qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan); -
163 if (result != keyValues.constEnd())
evaluated: result != keyValues.constEnd()
TRUEFALSE
yes
Evaluation Count:633
yes
Evaluation Count:464
464-633
164 return result->second;
executed: return result->second;
Execution Count:633
633
165 -
166 return QVariant();
executed: return QVariant();
Execution Count:464
464
167} -
168 -
169void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value) -
170{ -
171 if (step < qreal(0.0) || step > qreal(1.0)) {
partially evaluated: step < qreal(0.0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:856
partially evaluated: step > qreal(1.0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:856
0-856
172 QMessageLogger("animation/qvariantanimation.cpp", 322, __PRETTY_FUNCTION__).warning("QVariantAnimation::setValueAt: invalid step = %f", step); -
173 return;
never executed: return;
0
174 } -
175 -
176 QVariantAnimation::KeyValue pair(step, value); -
177 -
178 QVariantAnimation::KeyValues::iterator result = std::lower_bound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan); -
179 if (result == keyValues.end() || result->first != step) {
evaluated: result == keyValues.end()
TRUEFALSE
yes
Evaluation Count:762
yes
Evaluation Count:94
evaluated: result->first != step
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:90
4-762
180 keyValues.insert(result, pair); -
181 } else {
executed: }
Execution Count:766
766
182 if (value.isValid())
evaluated: value.isValid()
TRUEFALSE
yes
Evaluation Count:53
yes
Evaluation Count:37
37-53
183 result->second = value;
executed: result->second = value;
Execution Count:53
53
184 else -
185 keyValues.erase(result);
executed: keyValues.erase(result);
Execution Count:37
37
186 } -
187 -
188 recalculateCurrentInterval( true); -
189}
executed: }
Execution Count:856
856
190 -
191void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value) -
192{ -
193 defaultStartEndValue = value; -
194 recalculateCurrentInterval( true); -
195}
executed: }
Execution Count:458
458
196 -
197 -
198 -
199 -
200 -
201QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent) -
202{ -
203}
executed: }
Execution Count:844
844
204 -
205 -
206 -
207 -
208QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent) -
209{ -
210}
executed: }
Execution Count:474
474
211 -
212 -
213 -
214 -
215QVariantAnimation::~QVariantAnimation() -
216{ -
217} -
218QEasingCurve QVariantAnimation::easingCurve() const -
219{ -
220 const QVariantAnimationPrivate * const d = d_func(); -
221 return d->easing;
executed: return d->easing;
Execution Count:2
2
222} -
223 -
224void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) -
225{ -
226 QVariantAnimationPrivate * const d = d_func(); -
227 d->easing = easing; -
228 d->recalculateCurrentInterval(); -
229}
executed: }
Execution Count:956
956
230 -
231typedef QVector<QVariantAnimation::Interpolator> QInterpolatorVector; -
232static QInterpolatorVector *registeredInterpolators() { static QGlobalStatic<QInterpolatorVector > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QInterpolatorVector *x = new QInterpolatorVector; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QInterpolatorVector > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1598
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:1602
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-1602
233static QBasicMutex registeredInterpolatorsMutex; -
234void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType) -
235{ -
236 -
237 QInterpolatorVector *interpolators = registeredInterpolators(); -
238 -
239 -
240 -
241 if (interpolators) {
partially evaluated: interpolators
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
242 QMutexLocker locker(&registeredInterpolatorsMutex); -
243 if (int(interpolationType) >= interpolators->count())
evaluated: int(interpolationType) >= interpolators->count()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:7
6-7
244 interpolators->resize(int(interpolationType) + 1);
executed: interpolators->resize(int(interpolationType) + 1);
Execution Count:6
6
245 interpolators->replace(interpolationType, func); -
246 }
executed: }
Execution Count:13
13
247}
executed: }
Execution Count:13
13
248 -
249 -
250template<typename T> static inline QVariantAnimation::Interpolator castToInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) -
251{ -
252 return reinterpret_cast<QVariantAnimation::Interpolator>(func);
executed: return reinterpret_cast<QVariantAnimation::Interpolator>(func);
Execution Count:767
767
253} -
254 -
255QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) -
256{ -
257 { -
258 QInterpolatorVector *interpolators = registeredInterpolators(); -
259 QMutexLocker locker(&registeredInterpolatorsMutex); -
260 QVariantAnimation::Interpolator ret = 0; -
261 if (interpolationType < interpolators->count()) {
evaluated: interpolationType < interpolators->count()
TRUEFALSE
yes
Evaluation Count:1400
yes
Evaluation Count:189
189-1400
262 ret = interpolators->at(interpolationType); -
263 if (ret) return ret;
executed: return ret;
Execution Count:6
evaluated: ret
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1394
6-1394
264 }
executed: }
Execution Count:1394
1394
265 } -
266 -
267 switch(interpolationType) -
268 { -
269 case QMetaType::Int: -
270 return castToInterpolator(_q_interpolateVariant<int>);
executed: return castToInterpolator(_q_interpolateVariant<int>);
Execution Count:414
414
271 case QMetaType::Double: -
272 return castToInterpolator(_q_interpolateVariant<double>);
executed: return castToInterpolator(_q_interpolateVariant<double>);
Execution Count:68
68
273 case QMetaType::Float: -
274 return castToInterpolator(_q_interpolateVariant<float>);
never executed: return castToInterpolator(_q_interpolateVariant<float>);
0
275 case QMetaType::QLine: -
276 return castToInterpolator(_q_interpolateVariant<QLine>);
never executed: return castToInterpolator(_q_interpolateVariant<QLine>);
0
277 case QMetaType::QLineF: -
278 return castToInterpolator(_q_interpolateVariant<QLineF>);
never executed: return castToInterpolator(_q_interpolateVariant<QLineF>);
0
279 case QMetaType::QPoint: -
280 return castToInterpolator(_q_interpolateVariant<QPoint>);
never executed: return castToInterpolator(_q_interpolateVariant<QPoint>);
0
281 case QMetaType::QPointF: -
282 return castToInterpolator(_q_interpolateVariant<QPointF>);
executed: return castToInterpolator(_q_interpolateVariant<QPointF>);
Execution Count:3
3
283 case QMetaType::QSize: -
284 return castToInterpolator(_q_interpolateVariant<QSize>);
never executed: return castToInterpolator(_q_interpolateVariant<QSize>);
0
285 case QMetaType::QSizeF: -
286 return castToInterpolator(_q_interpolateVariant<QSizeF>);
never executed: return castToInterpolator(_q_interpolateVariant<QSizeF>);
0
287 case QMetaType::QRect: -
288 return castToInterpolator(_q_interpolateVariant<QRect>);
executed: return castToInterpolator(_q_interpolateVariant<QRect>);
Execution Count:282
282
289 case QMetaType::QRectF: -
290 return castToInterpolator(_q_interpolateVariant<QRectF>);
never executed: return castToInterpolator(_q_interpolateVariant<QRectF>);
0
291 default: -
292 return 0;
executed: return 0;
Execution Count:816
816
293 } -
294}
never executed: }
0
295int QVariantAnimation::duration() const -
296{ -
297 const QVariantAnimationPrivate * const d = d_func(); -
298 return d->duration;
executed: return d->duration;
Execution Count:9362
9362
299} -
300 -
301void QVariantAnimation::setDuration(int msecs) -
302{ -
303 QVariantAnimationPrivate * const d = d_func(); -
304 if (msecs < 0) {
evaluated: msecs < 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:533
2-533
305 QMessageLogger("animation/qvariantanimation.cpp", 517, __PRETTY_FUNCTION__).warning("QVariantAnimation::setDuration: cannot set a negative duration"); -
306 return;
executed: return;
Execution Count:2
2
307 } -
308 if (d->duration == msecs)
evaluated: d->duration == msecs
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:520
13-520
309 return;
executed: return;
Execution Count:13
13
310 d->duration = msecs; -
311 d->recalculateCurrentInterval(); -
312}
executed: }
Execution Count:520
520
313QVariant QVariantAnimation::startValue() const -
314{ -
315 return keyValueAt(0);
executed: return keyValueAt(0);
Execution Count:540
540
316} -
317 -
318void QVariantAnimation::setStartValue(const QVariant &value) -
319{ -
320 setKeyValueAt(0, value); -
321}
executed: }
Execution Count:205
205
322QVariant QVariantAnimation::endValue() const -
323{ -
324 return keyValueAt(1);
executed: return keyValueAt(1);
Execution Count:546
546
325} -
326 -
327void QVariantAnimation::setEndValue(const QVariant &value) -
328{ -
329 setKeyValueAt(1, value); -
330}
executed: }
Execution Count:638
638
331QVariant QVariantAnimation::keyValueAt(qreal step) const -
332{ -
333 return d_func()->valueAt(step);
executed: return d_func()->valueAt(step);
Execution Count:1097
1097
334} -
335void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value) -
336{ -
337 d_func()->setValueAt(step, value); -
338}
executed: }
Execution Count:856
856
339 -
340 -
341 -
342 -
343 -
344 -
345QVariantAnimation::KeyValues QVariantAnimation::keyValues() const -
346{ -
347 return d_func()->keyValues;
executed: return d_func()->keyValues;
Execution Count:9
9
348} -
349 -
350 -
351 -
352 -
353 -
354 -
355 -
356void QVariantAnimation::setKeyValues(const KeyValues &keyValues) -
357{ -
358 QVariantAnimationPrivate * const d = d_func(); -
359 d->keyValues = keyValues; -
360 qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan); -
361 d->recalculateCurrentInterval( true); -
362}
executed: }
Execution Count:3
3
363QVariant QVariantAnimation::currentValue() const -
364{ -
365 const QVariantAnimationPrivate * const d = d_func(); -
366 if (!d->currentValue.isValid())
evaluated: !d->currentValue.isValid()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:31
7-31
367 const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();
executed: const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();
Execution Count:7
7
368 return d->currentValue;
executed: return d->currentValue;
Execution Count:38
38
369} -
370 -
371 -
372 -
373 -
374bool QVariantAnimation::event(QEvent *event) -
375{ -
376 return QAbstractAnimation::event(event);
executed: return QAbstractAnimation::event(event);
Execution Count:249
249
377} -
378 -
379 -
380 -
381 -
382void QVariantAnimation::updateState(QAbstractAnimation::State newState, -
383 QAbstractAnimation::State oldState) -
384{ -
385 (void)oldState;; -
386 (void)newState;; -
387}
executed: }
Execution Count:949
949
388QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -
389{ -
390 return d_func()->interpolator(from.constData(), to.constData(), progress);
executed: return d_func()->interpolator(from.constData(), to.constData(), progress);
Execution Count:3313
3313
391} -
392 -
393 -
394 -
395 -
396void QVariantAnimation::updateCurrentTime(int) -
397{ -
398 d_func()->recalculateCurrentInterval(); -
399}
executed: }
Execution Count:2594
2594
400 -
401 -
402 -
403 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial