qanimationgroup.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/animation/qanimationgroup.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34/*!-
35 \class QAnimationGroup-
36 \inmodule QtCore-
37 \brief The QAnimationGroup class is an abstract base class for groups of animations.-
38 \since 4.6-
39 \ingroup animation-
40-
41 An animation group is a container for animations (subclasses of-
42 QAbstractAnimation). A group is usually responsible for managing-
43 the \l{QAbstractAnimation::State}{state} of its animations, i.e.,-
44 it decides when to start, stop, resume, and pause them. Currently,-
45 Qt provides two such groups: QParallelAnimationGroup and-
46 QSequentialAnimationGroup. Look up their class descriptions for-
47 details.-
48-
49 Since QAnimationGroup inherits from QAbstractAnimation, you can-
50 combine groups, and easily construct complex animation graphs.-
51 You can query QAbstractAnimation for the group it belongs to-
52 (using the \l{QAbstractAnimation::}{group()} function).-
53-
54 To start a top-level animation group, you simply use the-
55 \l{QAbstractAnimation::}{start()} function from-
56 QAbstractAnimation. By a top-level animation group, we think of a-
57 group that itself is not contained within another group. Starting-
58 sub groups directly is not supported, and may lead to unexpected-
59 behavior.-
60-
61 \omit OK, we'll put in a snippet on this here \endomit-
62-
63 QAnimationGroup provides methods for adding and retrieving-
64 animations. Besides that, you can remove animations by calling-
65 \l removeAnimation(), and clear the animation group by calling-
66 clear(). You may keep track of changes in the group's-
67 animations by listening to QEvent::ChildAdded and-
68 QEvent::ChildRemoved events.-
69-
70 \omit OK, let's find a snippet here as well. \endomit-
71-
72 QAnimationGroup takes ownership of the animations it manages, and-
73 ensures that they are deleted when the animation group is deleted.-
74-
75 \sa QAbstractAnimation, QVariantAnimation, {The Animation Framework}-
76*/-
77-
78#include "qanimationgroup.h"-
79#include <QtCore/qdebug.h>-
80#include <QtCore/qcoreevent.h>-
81#include "qanimationgroup_p.h"-
82-
83#ifndef QT_NO_ANIMATION-
84-
85#include <algorithm>-
86-
87QT_BEGIN_NAMESPACE-
88-
89-
90/*!-
91 Constructs a QAnimationGroup.-
92 \a parent is passed to QObject's constructor.-
93*/-
94QAnimationGroup::QAnimationGroup(QObject *parent)-
95 : QAbstractAnimation(*new QAnimationGroupPrivate, parent)-
96{-
97}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QAbstractAnimation
1
98-
99/*!-
100 \internal-
101*/-
102QAnimationGroup::QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent)-
103 : QAbstractAnimation(dd, parent)-
104{-
105}
executed 145 times by 6 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
145
106-
107/*!-
108 Destroys the animation group. It will also destroy all its animations.-
109*/-
110QAnimationGroup::~QAnimationGroup()-
111{-
112}-
113-
114/*!-
115 Returns a pointer to the animation at \a index in this group. This-
116 function is useful when you need access to a particular animation. \a-
117 index is between 0 and animationCount() - 1.-
118-
119 \sa animationCount(), indexOfAnimation()-
120*/-
121QAbstractAnimation *QAnimationGroup::animationAt(int index) const-
122{-
123 Q_D(const QAnimationGroup);-
124-
125 if (index < 0 || index >= d->animations.size()) {
index < 0Description
TRUEnever evaluated
FALSEevaluated 85 times by 4 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
index >= d->animations.size()Description
TRUEnever evaluated
FALSEevaluated 85 times by 4 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
0-85
126 qWarning("QAnimationGroup::animationAt: index is out of bounds");-
127 return 0;
never executed: return 0;
0
128 }-
129-
130 return d->animations.at(index);
executed 85 times by 4 tests: return d->animations.at(index);
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
85
131}-
132-
133-
134/*!-
135 Returns the number of animations managed by this group.-
136-
137 \sa indexOfAnimation(), addAnimation(), animationAt()-
138*/-
139int QAnimationGroup::animationCount() const-
140{-
141 Q_D(const QAnimationGroup);-
142 return d->animations.size();
executed 38 times by 4 tests: return d->animations.size();
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
38
143}-
144-
145/*!-
146 Returns the index of \a animation. The returned index can be passed-
147 to the other functions that take an index as an argument.-
148-
149 \sa insertAnimation(), animationAt(), takeAnimation()-
150*/-
151int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const-
152{-
153 Q_D(const QAnimationGroup);-
154 return d->animations.indexOf(animation);
never executed: return d->animations.indexOf(animation);
0
155}-
156-
157/*!-
158 Adds \a animation to this group. This will call insertAnimation with-
159 index equals to animationCount().-
160-
161 \note The group takes ownership of the animation.-
162-
163 \sa removeAnimation()-
164*/-
165void QAnimationGroup::addAnimation(QAbstractAnimation *animation)-
166{-
167 Q_D(QAnimationGroup);-
168 insertAnimation(d->animations.count(), animation);-
169}
executed 335 times by 7 tests: end of block
Executed by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
335
170-
171/*!-
172 Inserts \a animation into this animation group at \a index.-
173 If \a index is 0 the animation is inserted at the beginning.-
174 If \a index is animationCount(), the animation is inserted at the end.-
175-
176 \note The group takes ownership of the animation.-
177-
178 \sa takeAnimation(), addAnimation(), indexOfAnimation(), removeAnimation()-
179*/-
180void QAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation)-
181{-
182 Q_D(QAnimationGroup);-
183-
184 if (index < 0 || index > d->animations.size()) {
index < 0Description
TRUEnever evaluated
FALSEevaluated 337 times by 7 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
index > d->animations.size()Description
TRUEnever evaluated
FALSEevaluated 337 times by 7 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
0-337
185 qWarning("QAnimationGroup::insertAnimation: index is out of bounds");-
186 return;
never executed: return;
0
187 }-
188-
189 if (QAnimationGroup *oldGroup = animation->group())
QAnimationGrou...ation->group()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QAnimationGroup
FALSEevaluated 335 times by 7 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
2-335
190 oldGroup->removeAnimation(animation);
executed 2 times by 1 test: oldGroup->removeAnimation(animation);
Executed by:
  • tst_QAnimationGroup
2
191-
192 d->animations.insert(index, animation);-
193 QAbstractAnimationPrivate::get(animation)->group = this;-
194 // this will make sure that ChildAdded event is sent to 'this'-
195 animation->setParent(this);-
196 d->animationInsertedAt(index);-
197}
executed 337 times by 7 tests: end of block
Executed by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
337
198-
199/*!-
200 Removes \a animation from this group. The ownership of \a animation is-
201 transferred to the caller.-
202-
203 \sa takeAnimation(), insertAnimation(), addAnimation()-
204*/-
205void QAnimationGroup::removeAnimation(QAbstractAnimation *animation)-
206{-
207 Q_D(QAnimationGroup);-
208-
209 if (!animation) {
!animationDescription
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
0-8
210 qWarning("QAnimationGroup::remove: cannot remove null animation");-
211 return;
never executed: return;
0
212 }-
213 int index = d->animations.indexOf(animation);-
214 if (index == -1) {
index == -1Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
0-8
215 qWarning("QAnimationGroup::remove: animation is not part of this group");-
216 return;
never executed: return;
0
217 }-
218-
219 takeAnimation(index);-
220}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
8
221-
222/*!-
223 Returns the animation at \a index and removes it from the animation group.-
224-
225 \note The ownership of the animation is transferred to the caller.-
226-
227 \sa removeAnimation(), addAnimation(), insertAnimation(), indexOfAnimation()-
228*/-
229QAbstractAnimation *QAnimationGroup::takeAnimation(int index)-
230{-
231 Q_D(QAnimationGroup);-
232 if (index < 0 || index >= d->animations.size()) {
index < 0Description
TRUEnever evaluated
FALSEevaluated 229 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
index >= d->animations.size()Description
TRUEnever evaluated
FALSEevaluated 229 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
0-229
233 qWarning("QAnimationGroup::takeAnimation: no animation at index %d", index);-
234 return 0;
never executed: return 0;
0
235 }-
236 QAbstractAnimation *animation = d->animations.at(index);-
237 QAbstractAnimationPrivate::get(animation)->group = 0;-
238 // ### removing from list before doing setParent to avoid inifinite recursion-
239 // in ChildRemoved event-
240 d->animations.removeAt(index);-
241 animation->setParent(0);-
242 d->animationRemoved(index, animation);-
243 return animation;
executed 229 times by 5 tests: return animation;
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
229
244}-
245-
246/*!-
247 Removes and deletes all animations in this animation group, and resets the current-
248 time to 0.-
249-
250 \sa addAnimation(), removeAnimation()-
251*/-
252void QAnimationGroup::clear()-
253{-
254 Q_D(QAnimationGroup);-
255 qDeleteAll(d->animations);-
256}
executed 5 times by 3 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QSequentialAnimationGroup
5
257-
258/*!-
259 \reimp-
260*/-
261bool QAnimationGroup::event(QEvent *event)-
262{-
263 Q_D(QAnimationGroup);-
264 if (event->type() == QEvent::ChildAdded) {
event->type() ...nt::ChildAddedDescription
TRUEevaluated 337 times by 7 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
FALSEevaluated 450 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
337-450
265 QChildEvent *childEvent = static_cast<QChildEvent *>(event);-
266 if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
QAbstractAnima...vent->child())Description
TRUEevaluated 337 times by 7 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
FALSEnever evaluated
0-337
267 if (a->group() != this)
a->group() != thisDescription
TRUEevaluated 65 times by 4 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QSequentialAnimationGroup
FALSEevaluated 272 times by 6 tests
Evaluated by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
65-272
268 addAnimation(a);
executed 65 times by 4 tests: addAnimation(a);
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QSequentialAnimationGroup
65
269 }
executed 337 times by 7 tests: end of block
Executed by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
337
270 } else if (event->type() == QEvent::ChildRemoved) {
executed 337 times by 7 tests: end of block
Executed by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
event->type() ...::ChildRemovedDescription
TRUEevaluated 450 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
FALSEnever evaluated
0-450
271 QChildEvent *childEvent = static_cast<QChildEvent *>(event);-
272 // You can only rely on the child being a QObject because in the QEvent::ChildRemoved-
273 // case it might be called from the destructor. Casting down to QAbstractAnimation then-
274 // entails undefined behavior, so compare items as QObjects (which std::find does internally):-
275 const QList<QAbstractAnimation *>::const_iterator it-
276 = std::find(d->animations.cbegin(), d->animations.cend(), childEvent->child());-
277 if (it != d->animations.cend())
it != d->animations.cend()Description
TRUEevaluated 221 times by 4 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QSequentialAnimationGroup
FALSEevaluated 229 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
221-229
278 takeAnimation(it - d->animations.cbegin());
executed 221 times by 4 tests: takeAnimation(it - d->animations.cbegin());
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QSequentialAnimationGroup
221
279 }
executed 450 times by 5 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
450
280 return QAbstractAnimation::event(event);
executed 787 times by 7 tests: return QAbstractAnimation::event(event);
Executed by:
  • tst_QAbstractAnimation
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
  • tst_QStateMachine
787
281}-
282-
283-
284void QAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *)-
285{-
286 Q_Q(QAnimationGroup);-
287 Q_UNUSED(index);-
288 if (animations.isEmpty()) {
animations.isEmpty()Description
TRUEevaluated 77 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
FALSEevaluated 152 times by 5 tests
Evaluated by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
77-152
289 currentTime = 0;-
290 q->stop();-
291 }
executed 77 times by 5 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
77
292}
executed 229 times by 5 tests: end of block
Executed by:
  • tst_QAnimationGroup
  • tst_QParallelAnimationGroup
  • tst_QPauseAnimation
  • tst_QPropertyAnimation
  • tst_QSequentialAnimationGroup
229
293-
294QT_END_NAMESPACE-
295-
296#include "moc_qanimationgroup.cpp"-
297-
298#endif //QT_NO_ANIMATION-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9