animation/qvariantanimation.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore 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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qvariantanimation.h" -
43#include "qvariantanimation_p.h" -
44 -
45#include <QtCore/qrect.h> -
46#include <QtCore/qline.h> -
47#include <QtCore/qmutex.h> -
48 -
49#include <algorithm> -
50 -
51#ifndef QT_NO_ANIMATION -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55/*! -
56 \class QVariantAnimation -
57 \inmodule QtCore -
58 \ingroup animation -
59 \brief The QVariantAnimation class provides an abstract base class for animations. -
60 \since 4.6 -
61 -
62 This class is part of \l{The Animation Framework}. It serves as a -
63 base class for property and item animations, with functions for -
64 shared functionality. -
65 -
66 QVariantAnimation cannot be used directly as it is an abstract -
67 class; it has a pure virtual method called updateCurrentValue(). -
68 The class performs interpolation over -
69 \l{QVariant}s, but leaves using the interpolated values to its -
70 subclasses. Currently, Qt provides QPropertyAnimation, which -
71 animates Qt \l{Qt's Property System}{properties}. See the -
72 QPropertyAnimation class description if you wish to animate such -
73 properties. -
74 -
75 You can then set start and end values for the property by calling -
76 setStartValue() and setEndValue(), and finally call start() to -
77 start the animation. QVariantAnimation will interpolate the -
78 property of the target object and emit valueChanged(). To react to -
79 a change in the current value you have to reimplement the -
80 updateCurrentValue() virtual function. -
81 -
82 It is also possible to set values at specified steps situated -
83 between the start and end value. The interpolation will then -
84 touch these points at the specified steps. Note that the start and -
85 end values are defined as the key values at 0.0 and 1.0. -
86 -
87 There are two ways to affect how QVariantAnimation interpolates -
88 the values. You can set an easing curve by calling -
89 setEasingCurve(), and configure the duration by calling -
90 setDuration(). You can change how the QVariants are interpolated -
91 by creating a subclass of QVariantAnimation, and reimplementing -
92 the virtual interpolated() function. -
93 -
94 Subclassing QVariantAnimation can be an alternative if you have -
95 \l{QVariant}s that you do not wish to declare as Qt properties. -
96 Note, however, that you in most cases will be better off declaring -
97 your QVariant as a property. -
98 -
99 Not all QVariant types are supported. Below is a list of currently -
100 supported QVariant types: -
101 -
102 \list -
103 \li \l{QMetaType::}{Int} -
104 \li \l{QMetaType::}{Double} -
105 \li \l{QMetaType::}{Float} -
106 \li \l{QMetaType::}{QLine} -
107 \li \l{QMetaType::}{QLineF} -
108 \li \l{QMetaType::}{QPoint} -
109 \li \l{QMetaType::}{QPointF} -
110 \li \l{QMetaType::}{QSize} -
111 \li \l{QMetaType::}{QSizeF} -
112 \li \l{QMetaType::}{QRect} -
113 \li \l{QMetaType::}{QRectF} -
114 \li \l{QMetaType::}{QColor} -
115 \endlist -
116 -
117 If you need to interpolate other variant types, including custom -
118 types, you have to implement interpolation for these yourself. -
119 To do this, you can register an interpolator function for a given -
120 type. This function takes 3 parameters: the start value, the end value -
121 and the current progress. -
122 -
123 Example: -
124 \code -
125 QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) -
126 { -
127 ... -
128 return QColor(...); -
129 } -
130 ... -
131 qRegisterAnimationInterpolator<QColor>(myColorInterpolator); -
132 \endcode -
133 -
134 Another option is to reimplement interpolated(), which returns -
135 interpolation values for the value being interpolated. -
136 -
137 \omit We need some snippets around here. \endomit -
138 -
139 \sa QPropertyAnimation, QAbstractAnimation, {The Animation Framework} -
140*/ -
141 -
142/*! -
143 \fn void QVariantAnimation::valueChanged(const QVariant &value) -
144 -
145 QVariantAnimation emits this signal whenever the current \a value changes. -
146 -
147 \sa currentValue, startValue, endValue -
148*/ -
149 -
150/*! -
151 This virtual function is called every time the animation's current -
152 value changes. The \a value argument is the new current value. -
153 -
154 The base class implementation does nothing. -
155 -
156 \sa currentValue -
157*/ -
158void QVariantAnimation::updateCurrentValue(const QVariant &) {} -
159 -
160static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2) -
161{ -
162 return p1.first < p2.first;
executed: return p1.first < p2.first;
Execution Count:3559
3559
163} -
164 -
165static QVariant defaultInterpolator(const void *, const void *, qreal) -
166{ -
167 return QVariant();
executed: return QVariant();
Execution Count:2
2
168} -
169 -
170template<> Q_INLINE_TEMPLATE QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress) -
171{ -
172 QRect ret;
executed (the execution status of this line is deduced): QRect ret;
-
173 ret.setCoords(_q_interpolate(f.left(), t.left(), progress),
executed (the execution status of this line is deduced): ret.setCoords(_q_interpolate(f.left(), t.left(), progress),
-
174 _q_interpolate(f.top(), t.top(), progress),
executed (the execution status of this line is deduced): _q_interpolate(f.top(), t.top(), progress),
-
175 _q_interpolate(f.right(), t.right(), progress),
executed (the execution status of this line is deduced): _q_interpolate(f.right(), t.right(), progress),
-
176 _q_interpolate(f.bottom(), t.bottom(), progress));
executed (the execution status of this line is deduced): _q_interpolate(f.bottom(), t.bottom(), progress));
-
177 return ret;
executed: return ret;
Execution Count:564
564
178} -
179 -
180template<> Q_INLINE_TEMPLATE QRectF _q_interpolate(const QRectF &f, const QRectF &t, qreal progress) -
181{ -
182 qreal x1, y1, w1, h1;
never executed (the execution status of this line is deduced): qreal x1, y1, w1, h1;
-
183 f.getRect(&x1, &y1, &w1, &h1);
never executed (the execution status of this line is deduced): f.getRect(&x1, &y1, &w1, &h1);
-
184 qreal x2, y2, w2, h2;
never executed (the execution status of this line is deduced): qreal x2, y2, w2, h2;
-
185 t.getRect(&x2, &y2, &w2, &h2);
never executed (the execution status of this line is deduced): t.getRect(&x2, &y2, &w2, &h2);
-
186 return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, 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
187 _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
188} -
189 -
190template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress) -
191{ -
192 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
193} -
194 -
195template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF &t, qreal progress) -
196{ -
197 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
198} -
199 -
200QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator) -
201{ }
executed: }
Execution Count:1318
1318
202 -
203void QVariantAnimationPrivate::convertValues(int t) -
204{ -
205 //this ensures that all the keyValues are of type t -
206 for (int i = 0; i < keyValues.count(); ++i) {
evaluated: i < keyValues.count()
TRUEFALSE
yes
Evaluation Count:496
yes
Evaluation Count:896
496-896
207 QVariantAnimation::KeyValue &pair = keyValues[i];
executed (the execution status of this line is deduced): QVariantAnimation::KeyValue &pair = keyValues[i];
-
208 pair.second.convert(static_cast<QVariant::Type>(t));
executed (the execution status of this line is deduced): pair.second.convert(static_cast<QVariant::Type>(t));
-
209 }
executed: }
Execution Count:496
496
210 //we also need update to the current interval if needed -
211 currentInterval.start.second.convert(static_cast<QVariant::Type>(t));
executed (the execution status of this line is deduced): currentInterval.start.second.convert(static_cast<QVariant::Type>(t));
-
212 currentInterval.end.second.convert(static_cast<QVariant::Type>(t));
executed (the execution status of this line is deduced): currentInterval.end.second.convert(static_cast<QVariant::Type>(t));
-
213 -
214 //... and the interpolator -
215 updateInterpolator();
executed (the execution status of this line is deduced): updateInterpolator();
-
216}
executed: }
Execution Count:896
896
217 -
218void QVariantAnimationPrivate::updateInterpolator() -
219{ -
220 int type = currentInterval.start.second.userType();
executed (the execution status of this line is deduced): int type = currentInterval.start.second.userType();
-
221 if (type == currentInterval.end.second.userType())
evaluated: type == currentInterval.end.second.userType()
TRUEFALSE
yes
Evaluation Count:1589
yes
Evaluation Count:2
2-1589
222 interpolator = getInterpolator(type);
executed: interpolator = getInterpolator(type);
Execution Count:1589
1589
223 else -
224 interpolator = 0;
executed: interpolator = 0;
Execution Count:2
2
225 -
226 //we make sure that the interpolator is always set to something -
227 if (!interpolator)
evaluated: !interpolator
TRUEFALSE
yes
Evaluation Count:818
yes
Evaluation Count:773
773-818
228 interpolator = &defaultInterpolator;
executed: interpolator = &defaultInterpolator;
Execution Count:818
818
229}
executed: }
Execution Count:1591
1591
230 -
231/*! -
232 \internal -
233 The goal of this function is to update the currentInterval member. As a consequence, we also -
234 need to update the currentValue. -
235 Set \a force to true to always recalculate the interval. -
236*/ -
237void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) -
238{ -
239 // can't interpolate if we don't have at least 2 values -
240 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
241 return;
executed: return;
Execution Count:2081
2081
242 -
243 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
244 const qreal progress = easing.valueForProgress(((duration == 0) ? endProgress : qreal(currentTime) / qreal(duration)));
executed (the execution status of this line is deduced): const qreal progress = easing.valueForProgress(((duration == 0) ? endProgress : qreal(currentTime) / qreal(duration)));
-
245 -
246 //0 and 1 are still the boundaries -
247 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
248 || (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
249 //let's update currentInterval -
250 QVariantAnimation::KeyValues::const_iterator it = std::lower_bound(keyValues.constBegin(),
executed (the execution status of this line is deduced): QVariantAnimation::KeyValues::const_iterator it = std::lower_bound(keyValues.constBegin(),
-
251 keyValues.constEnd(),
executed (the execution status of this line is deduced): keyValues.constEnd(),
-
252 qMakePair(progress, QVariant()),
executed (the execution status of this line is deduced): qMakePair(progress, QVariant()),
-
253 animationValueLessThan);
executed (the execution status of this line is deduced): animationValueLessThan);
-
254 if (it == keyValues.constBegin()) {
evaluated: it == keyValues.constBegin()
TRUEFALSE
yes
Evaluation Count:677
yes
Evaluation Count:18
18-677
255 //the item pointed to by it is the start element in the range -
256 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
257 currentInterval.start = *it;
executed (the execution status of this line is deduced): currentInterval.start = *it;
-
258 currentInterval.end = *(it+1);
executed (the execution status of this line is deduced): currentInterval.end = *(it+1);
-
259 } else {
executed: }
Execution Count:238
238
260 currentInterval.start = qMakePair(qreal(0), defaultStartEndValue);
executed (the execution status of this line is deduced): currentInterval.start = qMakePair(qreal(0), defaultStartEndValue);
-
261 currentInterval.end = *it;
executed (the execution status of this line is deduced): currentInterval.end = *it;
-
262 }
executed: }
Execution Count:439
439
263 } else if (it == keyValues.constEnd()) {
evaluated: it == keyValues.constEnd()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16
2-16
264 --it; //position the iterator on the last item
executed (the execution status of this line is deduced): --it;
-
265 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
266 //we have an end value (item with progress = 1) -
267 currentInterval.start = *(it-1);
never executed (the execution status of this line is deduced): currentInterval.start = *(it-1);
-
268 currentInterval.end = *it;
never executed (the execution status of this line is deduced): currentInterval.end = *it;
-
269 } else {
never executed: }
0
270 //we use the default end value here -
271 currentInterval.start = *it;
executed (the execution status of this line is deduced): currentInterval.start = *it;
-
272 currentInterval.end = qMakePair(qreal(1), defaultStartEndValue);
executed (the execution status of this line is deduced): currentInterval.end = qMakePair(qreal(1), defaultStartEndValue);
-
273 }
executed: }
Execution Count:2
2
274 } else { -
275 currentInterval.start = *(it-1);
executed (the execution status of this line is deduced): currentInterval.start = *(it-1);
-
276 currentInterval.end = *it;
executed (the execution status of this line is deduced): currentInterval.end = *it;
-
277 }
executed: }
Execution Count:16
16
278 -
279 // update all the values of the currentInterval -
280 updateInterpolator();
executed (the execution status of this line is deduced): updateInterpolator();
-
281 }
executed: }
Execution Count:695
695
282 setCurrentValueForProgress(progress);
executed (the execution status of this line is deduced): setCurrentValueForProgress(progress);
-
283}
executed: }
Execution Count:3313
3313
284 -
285void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) -
286{ -
287 Q_Q(QVariantAnimation);
executed (the execution status of this line is deduced): QVariantAnimation * const q = q_func();
-
288 -
289 const qreal startProgress = currentInterval.start.first;
executed (the execution status of this line is deduced): const qreal startProgress = currentInterval.start.first;
-
290 const qreal endProgress = currentInterval.end.first;
executed (the execution status of this line is deduced): const qreal endProgress = currentInterval.end.first;
-
291 const qreal localProgress = (progress - startProgress) / (endProgress - startProgress);
executed (the execution status of this line is deduced): const qreal localProgress = (progress - startProgress) / (endProgress - startProgress);
-
292 -
293 QVariant ret = q->interpolated(currentInterval.start.second,
executed (the execution status of this line is deduced): QVariant ret = q->interpolated(currentInterval.start.second,
-
294 currentInterval.end.second,
executed (the execution status of this line is deduced): currentInterval.end.second,
-
295 localProgress);
executed (the execution status of this line is deduced): localProgress);
-
296 qSwap(currentValue, ret);
executed (the execution status of this line is deduced): qSwap(currentValue, ret);
-
297 q->updateCurrentValue(currentValue);
executed (the execution status of this line is deduced): q->updateCurrentValue(currentValue);
-
298 static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0); -
299 if (!changedSignalIndex.load()) {
evaluated: !changedSignalIndex.load()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:3297
16-3297
300 //we keep the mask so that we emit valueChanged only when needed (for performance reasons) -
301 changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
executed (the execution status of this line is deduced): changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
-
302 }
executed: }
Execution Count:16
16
303 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
304 //the value has changed -
305 emit q->valueChanged(currentValue);
executed (the execution status of this line is deduced): q->valueChanged(currentValue);
-
306 }
executed: }
Execution Count:6
6
307}
executed: }
Execution Count:3313
3313
308 -
309QVariant QVariantAnimationPrivate::valueAt(qreal step) const -
310{ -
311 QVariantAnimation::KeyValues::const_iterator result =
executed (the execution status of this line is deduced): QVariantAnimation::KeyValues::const_iterator result =
-
312 qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan);
executed (the execution status of this line is deduced): qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan);
-
313 if (result != keyValues.constEnd())
evaluated: result != keyValues.constEnd()
TRUEFALSE
yes
Evaluation Count:633
yes
Evaluation Count:464
464-633
314 return result->second;
executed: return result->second;
Execution Count:633
633
315 -
316 return QVariant();
executed: return QVariant();
Execution Count:464
464
317} -
318 -
319void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value) -
320{ -
321 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
322 qWarning("QVariantAnimation::setValueAt: invalid step = %f", step);
never executed (the execution status of this line is deduced): QMessageLogger("animation/qvariantanimation.cpp", 322, __PRETTY_FUNCTION__).warning("QVariantAnimation::setValueAt: invalid step = %f", step);
-
323 return;
never executed: return;
0
324 } -
325 -
326 QVariantAnimation::KeyValue pair(step, value);
executed (the execution status of this line is deduced): QVariantAnimation::KeyValue pair(step, value);
-
327 -
328 QVariantAnimation::KeyValues::iterator result = std::lower_bound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan);
executed (the execution status of this line is deduced): QVariantAnimation::KeyValues::iterator result = std::lower_bound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan);
-
329 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
330 keyValues.insert(result, pair);
executed (the execution status of this line is deduced): keyValues.insert(result, pair);
-
331 } else {
executed: }
Execution Count:766
766
332 if (value.isValid())
evaluated: value.isValid()
TRUEFALSE
yes
Evaluation Count:53
yes
Evaluation Count:37
37-53
333 result->second = value; // replaces the previous value
executed: result->second = value;
Execution Count:53
53
334 else -
335 keyValues.erase(result); // removes the previous value
executed: keyValues.erase(result);
Execution Count:37
37
336 } -
337 -
338 recalculateCurrentInterval(/*force=*/true);
executed (the execution status of this line is deduced): recalculateCurrentInterval( true);
-
339}
executed: }
Execution Count:856
856
340 -
341void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value) -
342{ -
343 defaultStartEndValue = value;
executed (the execution status of this line is deduced): defaultStartEndValue = value;
-
344 recalculateCurrentInterval(/*force=*/true);
executed (the execution status of this line is deduced): recalculateCurrentInterval( true);
-
345}
executed: }
Execution Count:458
458
346 -
347/*! -
348 Construct a QVariantAnimation object. \a parent is passed to QAbstractAnimation's -
349 constructor. -
350*/ -
351QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent) -
352{ -
353}
executed: }
Execution Count:844
844
354 -
355/*! -
356 \internal -
357*/ -
358QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent) -
359{ -
360}
executed: }
Execution Count:474
474
361 -
362/*! -
363 Destroys the animation. -
364*/ -
365QVariantAnimation::~QVariantAnimation() -
366{ -
367} -
368 -
369/*! -
370 \property QVariantAnimation::easingCurve -
371 \brief the easing curve of the animation -
372 -
373 This property defines the easing curve of the animation. By -
374 default, a linear easing curve is used, resulting in linear -
375 interpolation. Other curves are provided, for instance, -
376 QEasingCurve::InCirc, which provides a circular entry curve. -
377 Another example is QEasingCurve::InOutElastic, which provides an -
378 elastic effect on the values of the interpolated variant. -
379 -
380 QVariantAnimation will use the QEasingCurve::valueForProgress() to -
381 transform the "normalized progress" (currentTime / totalDuration) -
382 of the animation into the effective progress actually -
383 used by the animation. It is this effective progress that will be -
384 the progress when interpolated() is called. Also, the steps in the -
385 keyValues are referring to this effective progress. -
386 -
387 The easing curve is used with the interpolator, the interpolated() -
388 virtual function, the animation's duration, and iterationCount, to -
389 control how the current value changes as the animation progresses. -
390*/ -
391QEasingCurve QVariantAnimation::easingCurve() const -
392{ -
393 Q_D(const QVariantAnimation);
executed (the execution status of this line is deduced): const QVariantAnimationPrivate * const d = d_func();
-
394 return d->easing;
executed: return d->easing;
Execution Count:2
2
395} -
396 -
397void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) -
398{ -
399 Q_D(QVariantAnimation);
executed (the execution status of this line is deduced): QVariantAnimationPrivate * const d = d_func();
-
400 d->easing = easing;
executed (the execution status of this line is deduced): d->easing = easing;
-
401 d->recalculateCurrentInterval();
executed (the execution status of this line is deduced): d->recalculateCurrentInterval();
-
402}
executed: }
Execution Count:956
956
403 -
404typedef QVector<QVariantAnimation::Interpolator> QInterpolatorVector; -
405Q_GLOBAL_STATIC(QInterpolatorVector, registeredInterpolators)
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
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
0-1602
406static QBasicMutex registeredInterpolatorsMutex; -
407 -
408/*! -
409 \fn void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) -
410 \relates QVariantAnimation -
411 \threadsafe -
412 -
413 Registers a custom interpolator \a func for the template type \c{T}. -
414 The interpolator has to be registered before the animation is constructed. -
415 To unregister (and use the default interpolator) set \a func to 0. -
416 */ -
417 -
418/*! -
419 \internal -
420 \typedef QVariantAnimation::Interpolator -
421 -
422 This is a typedef for a pointer to a function with the following -
423 signature: -
424 \code -
425 QVariant myInterpolator(const QVariant &from, const QVariant &to, qreal progress); -
426 \endcode -
427 -
428*/ -
429 -
430/*! -
431 * \internal -
432 * Registers a custom interpolator \a func for the specific \a interpolationType. -
433 * The interpolator has to be registered before the animation is constructed. -
434 * To unregister (and use the default interpolator) set \a func to 0. -
435 */ -
436void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType) -
437{ -
438 // will override any existing interpolators -
439 QInterpolatorVector *interpolators = registeredInterpolators();
executed (the execution status of this line is deduced): QInterpolatorVector *interpolators = registeredInterpolators();
-
440 // When built on solaris with GCC, the destructors can be called -
441 // in such an order that we get here with interpolators == NULL, -
442 // to continue causes the app to crash on exit with a SEGV -
443 if (interpolators) {
partially evaluated: interpolators
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
444 QMutexLocker locker(&registeredInterpolatorsMutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&registeredInterpolatorsMutex);
-
445 if (int(interpolationType) >= interpolators->count())
evaluated: int(interpolationType) >= interpolators->count()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:7
6-7
446 interpolators->resize(int(interpolationType) + 1);
executed: interpolators->resize(int(interpolationType) + 1);
Execution Count:6
6
447 interpolators->replace(interpolationType, func);
executed (the execution status of this line is deduced): interpolators->replace(interpolationType, func);
-
448 }
executed: }
Execution Count:13
13
449}
executed: }
Execution Count:13
13
450 -
451 -
452template<typename T> static inline QVariantAnimation::Interpolator castToInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) -
453{ -
454 return reinterpret_cast<QVariantAnimation::Interpolator>(func);
executed: return reinterpret_cast<QVariantAnimation::Interpolator>(func);
Execution Count:767
767
455} -
456 -
457QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) -
458{ -
459 { -
460 QInterpolatorVector *interpolators = registeredInterpolators();
executed (the execution status of this line is deduced): QInterpolatorVector *interpolators = registeredInterpolators();
-
461 QMutexLocker locker(&registeredInterpolatorsMutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&registeredInterpolatorsMutex);
-
462 QVariantAnimation::Interpolator ret = 0;
executed (the execution status of this line is deduced): QVariantAnimation::Interpolator ret = 0;
-
463 if (interpolationType < interpolators->count()) {
evaluated: interpolationType < interpolators->count()
TRUEFALSE
yes
Evaluation Count:1400
yes
Evaluation Count:189
189-1400
464 ret = interpolators->at(interpolationType);
executed (the execution status of this line is deduced): ret = interpolators->at(interpolationType);
-
465 if (ret) return ret;
executed: return ret;
Execution Count:6
evaluated: ret
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1394
6-1394
466 }
executed: }
Execution Count:1394
1394
467 } -
468 -
469 switch(interpolationType) -
470 { -
471 case QMetaType::Int: -
472 return castToInterpolator(_q_interpolateVariant<int>);
executed: return castToInterpolator(_q_interpolateVariant<int>);
Execution Count:414
414
473 case QMetaType::Double: -
474 return castToInterpolator(_q_interpolateVariant<double>);
executed: return castToInterpolator(_q_interpolateVariant<double>);
Execution Count:68
68
475 case QMetaType::Float: -
476 return castToInterpolator(_q_interpolateVariant<float>);
never executed: return castToInterpolator(_q_interpolateVariant<float>);
0
477 case QMetaType::QLine: -
478 return castToInterpolator(_q_interpolateVariant<QLine>);
never executed: return castToInterpolator(_q_interpolateVariant<QLine>);
0
479 case QMetaType::QLineF: -
480 return castToInterpolator(_q_interpolateVariant<QLineF>);
never executed: return castToInterpolator(_q_interpolateVariant<QLineF>);
0
481 case QMetaType::QPoint: -
482 return castToInterpolator(_q_interpolateVariant<QPoint>);
never executed: return castToInterpolator(_q_interpolateVariant<QPoint>);
0
483 case QMetaType::QPointF: -
484 return castToInterpolator(_q_interpolateVariant<QPointF>);
executed: return castToInterpolator(_q_interpolateVariant<QPointF>);
Execution Count:3
3
485 case QMetaType::QSize: -
486 return castToInterpolator(_q_interpolateVariant<QSize>);
never executed: return castToInterpolator(_q_interpolateVariant<QSize>);
0
487 case QMetaType::QSizeF: -
488 return castToInterpolator(_q_interpolateVariant<QSizeF>);
never executed: return castToInterpolator(_q_interpolateVariant<QSizeF>);
0
489 case QMetaType::QRect: -
490 return castToInterpolator(_q_interpolateVariant<QRect>);
executed: return castToInterpolator(_q_interpolateVariant<QRect>);
Execution Count:282
282
491 case QMetaType::QRectF: -
492 return castToInterpolator(_q_interpolateVariant<QRectF>);
never executed: return castToInterpolator(_q_interpolateVariant<QRectF>);
0
493 default: -
494 return 0; //this type is not handled
executed: return 0;
Execution Count:816
816
495 } -
496}
never executed: }
0
497 -
498/*! -
499 \property QVariantAnimation::duration -
500 \brief the duration of the animation -
501 -
502 This property describes the duration in milliseconds of the -
503 animation. The default duration is 250 milliseconds. -
504 -
505 \sa QAbstractAnimation::duration() -
506 */ -
507int QVariantAnimation::duration() const -
508{ -
509 Q_D(const QVariantAnimation);
executed (the execution status of this line is deduced): const QVariantAnimationPrivate * const d = d_func();
-
510 return d->duration;
executed: return d->duration;
Execution Count:9362
9362
511} -
512 -
513void QVariantAnimation::setDuration(int msecs) -
514{ -
515 Q_D(QVariantAnimation);
executed (the execution status of this line is deduced): QVariantAnimationPrivate * const d = d_func();
-
516 if (msecs < 0) {
evaluated: msecs < 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:533
2-533
517 qWarning("QVariantAnimation::setDuration: cannot set a negative duration");
executed (the execution status of this line is deduced): QMessageLogger("animation/qvariantanimation.cpp", 517, __PRETTY_FUNCTION__).warning("QVariantAnimation::setDuration: cannot set a negative duration");
-
518 return;
executed: return;
Execution Count:2
2
519 } -
520 if (d->duration == msecs)
evaluated: d->duration == msecs
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:520
13-520
521 return;
executed: return;
Execution Count:13
13
522 d->duration = msecs;
executed (the execution status of this line is deduced): d->duration = msecs;
-
523 d->recalculateCurrentInterval();
executed (the execution status of this line is deduced): d->recalculateCurrentInterval();
-
524}
executed: }
Execution Count:520
520
525 -
526/*! -
527 \property QVariantAnimation::startValue -
528 \brief the optional start value of the animation -
529 -
530 This property describes the optional start value of the animation. If -
531 omitted, or if a null QVariant is assigned as the start value, the -
532 animation will use the current position of the end when the animation -
533 is started. -
534 -
535 \sa endValue -
536*/ -
537QVariant QVariantAnimation::startValue() const -
538{ -
539 return keyValueAt(0);
executed: return keyValueAt(0);
Execution Count:540
540
540} -
541 -
542void QVariantAnimation::setStartValue(const QVariant &value) -
543{ -
544 setKeyValueAt(0, value);
executed (the execution status of this line is deduced): setKeyValueAt(0, value);
-
545}
executed: }
Execution Count:205
205
546 -
547/*! -
548 \property QVariantAnimation::endValue -
549 \brief the end value of the animation -
550 -
551 This property describes the end value of the animation. -
552 -
553 \sa startValue -
554 */ -
555QVariant QVariantAnimation::endValue() const -
556{ -
557 return keyValueAt(1);
executed: return keyValueAt(1);
Execution Count:546
546
558} -
559 -
560void QVariantAnimation::setEndValue(const QVariant &value) -
561{ -
562 setKeyValueAt(1, value);
executed (the execution status of this line is deduced): setKeyValueAt(1, value);
-
563}
executed: }
Execution Count:638
638
564 -
565 -
566/*! -
567 Returns the key frame value for the given \a step. The given \a step -
568 must be in the range 0 to 1. If there is no KeyValue for \a step, -
569 it returns an invalid QVariant. -
570 -
571 \sa keyValues(), setKeyValueAt() -
572*/ -
573QVariant QVariantAnimation::keyValueAt(qreal step) const -
574{ -
575 return d_func()->valueAt(step);
executed: return d_func()->valueAt(step);
Execution Count:1097
1097
576} -
577 -
578/*! -
579 \typedef QVariantAnimation::KeyValue -
580 -
581 This is a typedef for QPair<qreal, QVariant>. -
582*/ -
583/*! -
584 \typedef QVariantAnimation::KeyValues -
585 -
586 This is a typedef for QVector<KeyValue> -
587*/ -
588 -
589/*! -
590 Creates a key frame at the given \a step with the given \a value. -
591 The given \a step must be in the range 0 to 1. -
592 -
593 \sa setKeyValues(), keyValueAt() -
594*/ -
595void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value) -
596{ -
597 d_func()->setValueAt(step, value);
executed (the execution status of this line is deduced): d_func()->setValueAt(step, value);
-
598}
executed: }
Execution Count:856
856
599 -
600/*! -
601 Returns the key frames of this animation. -
602 -
603 \sa keyValueAt(), setKeyValues() -
604*/ -
605QVariantAnimation::KeyValues QVariantAnimation::keyValues() const -
606{ -
607 return d_func()->keyValues;
executed: return d_func()->keyValues;
Execution Count:9
9
608} -
609 -
610/*! -
611 Replaces the current set of key frames with the given \a keyValues. -
612 the step of the key frames must be in the range 0 to 1. -
613 -
614 \sa keyValues(), keyValueAt() -
615*/ -
616void QVariantAnimation::setKeyValues(const KeyValues &keyValues) -
617{ -
618 Q_D(QVariantAnimation);
executed (the execution status of this line is deduced): QVariantAnimationPrivate * const d = d_func();
-
619 d->keyValues = keyValues;
executed (the execution status of this line is deduced): d->keyValues = keyValues;
-
620 qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan);
executed (the execution status of this line is deduced): qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan);
-
621 d->recalculateCurrentInterval(/*force=*/true);
executed (the execution status of this line is deduced): d->recalculateCurrentInterval( true);
-
622}
executed: }
Execution Count:3
3
623 -
624/*! -
625 \property QVariantAnimation::currentValue -
626 \brief the current value of the animation. -
627 -
628 This property describes the current value; an interpolated value -
629 between the \l{startValue}{start value} and the \l{endValue}{end -
630 value}, using the current time for progress. The value itself is -
631 obtained from interpolated(), which is called repeatedly as the -
632 animation is running. -
633 -
634 QVariantAnimation calls the virtual updateCurrentValue() function -
635 when the current value changes. This is particularly useful for -
636 subclasses that need to track updates. For example, -
637 QPropertyAnimation uses this function to animate Qt \l{Qt's -
638 Property System}{properties}. -
639 -
640 \sa startValue, endValue -
641*/ -
642QVariant QVariantAnimation::currentValue() const -
643{ -
644 Q_D(const QVariantAnimation);
executed (the execution status of this line is deduced): const QVariantAnimationPrivate * const d = d_func();
-
645 if (!d->currentValue.isValid())
evaluated: !d->currentValue.isValid()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:31
7-31
646 const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();
executed: const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();
Execution Count:7
7
647 return d->currentValue;
executed: return d->currentValue;
Execution Count:38
38
648} -
649 -
650/*! -
651 \reimp -
652 */ -
653bool QVariantAnimation::event(QEvent *event) -
654{ -
655 return QAbstractAnimation::event(event);
executed: return QAbstractAnimation::event(event);
Execution Count:249
249
656} -
657 -
658/*! -
659 \reimp -
660*/ -
661void QVariantAnimation::updateState(QAbstractAnimation::State newState, -
662 QAbstractAnimation::State oldState) -
663{ -
664 Q_UNUSED(oldState);
executed (the execution status of this line is deduced): (void)oldState;;
-
665 Q_UNUSED(newState);
executed (the execution status of this line is deduced): (void)newState;;
-
666}
executed: }
Execution Count:949
949
667 -
668/*! -
669 -
670 This virtual function returns the linear interpolation between -
671 variants \a from and \a to, at \a progress, usually a value -
672 between 0 and 1. You can reimplement this function in a subclass -
673 of QVariantAnimation to provide your own interpolation algorithm. -
674 -
675 Note that in order for the interpolation to work with a -
676 QEasingCurve that return a value smaller than 0 or larger than 1 -
677 (such as QEasingCurve::InBack) you should make sure that it can -
678 extrapolate. If the semantic of the datatype does not allow -
679 extrapolation this function should handle that gracefully. -
680 -
681 You should call the QVariantAnimation implementation of this -
682 function if you want your class to handle the types already -
683 supported by Qt (see class QVariantAnimation description for a -
684 list of supported types). -
685 -
686 \sa QEasingCurve -
687 */ -
688QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -
689{ -
690 return d_func()->interpolator(from.constData(), to.constData(), progress);
executed: return d_func()->interpolator(from.constData(), to.constData(), progress);
Execution Count:3313
3313
691} -
692 -
693/*! -
694 \reimp -
695 */ -
696void QVariantAnimation::updateCurrentTime(int) -
697{ -
698 d_func()->recalculateCurrentInterval();
executed (the execution status of this line is deduced): d_func()->recalculateCurrentInterval();
-
699}
executed: }
Execution Count:2594
2594
700 -
701QT_END_NAMESPACE -
702 -
703#include "moc_qvariantanimation.cpp" -
704 -
705#endif //QT_NO_ANIMATION -
706 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial