Line | Source Code | Coverage |
---|
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 | /*! | - |
43 | \class QAnimationGroup | - |
44 | \inmodule QtCore | - |
45 | \brief The QAnimationGroup class is an abstract base class for groups of animations. | - |
46 | \since 4.6 | - |
47 | \ingroup animation | - |
48 | | - |
49 | An animation group is a container for animations (subclasses of | - |
50 | QAbstractAnimation). A group is usually responsible for managing | - |
51 | the \l{QAbstractAnimation::State}{state} of its animations, i.e., | - |
52 | it decides when to start, stop, resume, and pause them. Currently, | - |
53 | Qt provides two such groups: QParallelAnimationGroup and | - |
54 | QSequentialAnimationGroup. Look up their class descriptions for | - |
55 | details. | - |
56 | | - |
57 | Since QAnimationGroup inherits from QAbstractAnimation, you can | - |
58 | combine groups, and easily construct complex animation graphs. | - |
59 | You can query QAbstractAnimation for the group it belongs to | - |
60 | (using the \l{QAbstractAnimation::}{group()} function). | - |
61 | | - |
62 | To start a top-level animation group, you simply use the | - |
63 | \l{QAbstractAnimation::}{start()} function from | - |
64 | QAbstractAnimation. By a top-level animation group, we think of a | - |
65 | group that itself is not contained within another group. Starting | - |
66 | sub groups directly is not supported, and may lead to unexpected | - |
67 | behavior. | - |
68 | | - |
69 | \omit OK, we'll put in a snippet on this here \endomit | - |
70 | | - |
71 | QAnimationGroup provides methods for adding and retrieving | - |
72 | animations. Besides that, you can remove animations by calling | - |
73 | remove(), and clear the animation group by calling | - |
74 | clear(). You may keep track of changes in the group's | - |
75 | animations by listening to QEvent::ChildAdded and | - |
76 | QEvent::ChildRemoved events. | - |
77 | | - |
78 | \omit OK, let's find a snippet here as well. \endomit | - |
79 | | - |
80 | QAnimationGroup takes ownership of the animations it manages, and | - |
81 | ensures that they are deleted when the animation group is deleted. | - |
82 | | - |
83 | \sa QAbstractAnimation, QVariantAnimation, {The Animation Framework} | - |
84 | */ | - |
85 | | - |
86 | #include "qanimationgroup.h" | - |
87 | #include <QtCore/qdebug.h> | - |
88 | #include <QtCore/qcoreevent.h> | - |
89 | #include "qanimationgroup_p.h" | - |
90 | | - |
91 | #ifndef QT_NO_ANIMATION | - |
92 | | - |
93 | QT_BEGIN_NAMESPACE | - |
94 | | - |
95 | | - |
96 | /*! | - |
97 | Constructs a QAnimationGroup. | - |
98 | \a parent is passed to QObject's constructor. | - |
99 | */ | - |
100 | QAnimationGroup::QAnimationGroup(QObject *parent) | - |
101 | : QAbstractAnimation(*new QAnimationGroupPrivate, parent) | - |
102 | { | - |
103 | } executed: } Execution Count:1 | 1 |
104 | | - |
105 | /*! | - |
106 | \internal | - |
107 | */ | - |
108 | QAnimationGroup::QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent) | - |
109 | : QAbstractAnimation(dd, parent) | - |
110 | { | - |
111 | } executed: } Execution Count:145 | 145 |
112 | | - |
113 | /*! | - |
114 | Destroys the animation group. It will also destroy all its animations. | - |
115 | */ | - |
116 | QAnimationGroup::~QAnimationGroup() | - |
117 | { | - |
118 | } | - |
119 | | - |
120 | /*! | - |
121 | Returns a pointer to the animation at \a index in this group. This | - |
122 | function is useful when you need access to a particular animation. \a | - |
123 | index is between 0 and animationCount() - 1. | - |
124 | | - |
125 | \sa animationCount(), indexOfAnimation() | - |
126 | */ | - |
127 | QAbstractAnimation *QAnimationGroup::animationAt(int index) const | - |
128 | { | - |
129 | Q_D(const QAnimationGroup); executed (the execution status of this line is deduced): const QAnimationGroupPrivate * const d = d_func(); | - |
130 | | - |
131 | if (index < 0 || index >= d->animations.size()) { partially evaluated: index < 0 no Evaluation Count:0 | yes Evaluation Count:85 |
partially evaluated: index >= d->animations.size() no Evaluation Count:0 | yes Evaluation Count:85 |
| 0-85 |
132 | qWarning("QAnimationGroup::animationAt: index is out of bounds"); never executed (the execution status of this line is deduced): QMessageLogger("animation/qanimationgroup.cpp", 132, __PRETTY_FUNCTION__).warning("QAnimationGroup::animationAt: index is out of bounds"); | - |
133 | return 0; never executed: return 0; | 0 |
134 | } | - |
135 | | - |
136 | return d->animations.at(index); executed: return d->animations.at(index); Execution Count:85 | 85 |
137 | } | - |
138 | | - |
139 | | - |
140 | /*! | - |
141 | Returns the number of animations managed by this group. | - |
142 | | - |
143 | \sa indexOfAnimation(), addAnimation(), animationAt() | - |
144 | */ | - |
145 | int QAnimationGroup::animationCount() const | - |
146 | { | - |
147 | Q_D(const QAnimationGroup); executed (the execution status of this line is deduced): const QAnimationGroupPrivate * const d = d_func(); | - |
148 | return d->animations.size(); executed: return d->animations.size(); Execution Count:37 | 37 |
149 | } | - |
150 | | - |
151 | /*! | - |
152 | Returns the index of \a animation. The returned index can be passed | - |
153 | to the other functions that take an index as an argument. | - |
154 | | - |
155 | \sa insertAnimation(), animationAt(), takeAnimation() | - |
156 | */ | - |
157 | int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const | - |
158 | { | - |
159 | Q_D(const QAnimationGroup); never executed (the execution status of this line is deduced): const QAnimationGroupPrivate * const d = d_func(); | - |
160 | return d->animations.indexOf(animation); never executed: return d->animations.indexOf(animation); | 0 |
161 | } | - |
162 | | - |
163 | /*! | - |
164 | Adds \a animation to this group. This will call insertAnimation with | - |
165 | index equals to animationCount(). | - |
166 | | - |
167 | \note The group takes ownership of the animation. | - |
168 | | - |
169 | \sa removeAnimation() | - |
170 | */ | - |
171 | void QAnimationGroup::addAnimation(QAbstractAnimation *animation) | - |
172 | { | - |
173 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
174 | insertAnimation(d->animations.count(), animation); executed (the execution status of this line is deduced): insertAnimation(d->animations.count(), animation); | - |
175 | } executed: } Execution Count:335 | 335 |
176 | | - |
177 | /*! | - |
178 | Inserts \a animation into this animation group at \a index. | - |
179 | If \a index is 0 the animation is inserted at the beginning. | - |
180 | If \a index is animationCount(), the animation is inserted at the end. | - |
181 | | - |
182 | \note The group takes ownership of the animation. | - |
183 | | - |
184 | \sa takeAnimation(), addAnimation(), indexOfAnimation(), removeAnimation() | - |
185 | */ | - |
186 | void QAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation) | - |
187 | { | - |
188 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
189 | | - |
190 | if (index < 0 || index > d->animations.size()) { partially evaluated: index < 0 no Evaluation Count:0 | yes Evaluation Count:337 |
partially evaluated: index > d->animations.size() no Evaluation Count:0 | yes Evaluation Count:337 |
| 0-337 |
191 | qWarning("QAnimationGroup::insertAnimation: index is out of bounds"); never executed (the execution status of this line is deduced): QMessageLogger("animation/qanimationgroup.cpp", 191, __PRETTY_FUNCTION__).warning("QAnimationGroup::insertAnimation: index is out of bounds"); | - |
192 | return; | 0 |
193 | } | - |
194 | | - |
195 | if (QAnimationGroup *oldGroup = animation->group()) evaluated: QAnimationGroup *oldGroup = animation->group() yes Evaluation Count:2 | yes Evaluation Count:335 |
| 2-335 |
196 | oldGroup->removeAnimation(animation); executed: oldGroup->removeAnimation(animation); Execution Count:2 | 2 |
197 | | - |
198 | d->animations.insert(index, animation); executed (the execution status of this line is deduced): d->animations.insert(index, animation); | - |
199 | QAbstractAnimationPrivate::get(animation)->group = this; executed (the execution status of this line is deduced): QAbstractAnimationPrivate::get(animation)->group = this; | - |
200 | // this will make sure that ChildAdded event is sent to 'this' | - |
201 | animation->setParent(this); executed (the execution status of this line is deduced): animation->setParent(this); | - |
202 | d->animationInsertedAt(index); executed (the execution status of this line is deduced): d->animationInsertedAt(index); | - |
203 | } executed: } Execution Count:337 | 337 |
204 | | - |
205 | /*! | - |
206 | Removes \a animation from this group. The ownership of \a animation is | - |
207 | transferred to the caller. | - |
208 | | - |
209 | \sa takeAnimation(), insertAnimation(), addAnimation() | - |
210 | */ | - |
211 | void QAnimationGroup::removeAnimation(QAbstractAnimation *animation) | - |
212 | { | - |
213 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
214 | | - |
215 | if (!animation) { partially evaluated: !animation no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
216 | qWarning("QAnimationGroup::remove: cannot remove null animation"); never executed (the execution status of this line is deduced): QMessageLogger("animation/qanimationgroup.cpp", 216, __PRETTY_FUNCTION__).warning("QAnimationGroup::remove: cannot remove null animation"); | - |
217 | return; | 0 |
218 | } | - |
219 | int index = d->animations.indexOf(animation); executed (the execution status of this line is deduced): int index = d->animations.indexOf(animation); | - |
220 | if (index == -1) { partially evaluated: index == -1 no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
221 | qWarning("QAnimationGroup::remove: animation is not part of this group"); never executed (the execution status of this line is deduced): QMessageLogger("animation/qanimationgroup.cpp", 221, __PRETTY_FUNCTION__).warning("QAnimationGroup::remove: animation is not part of this group"); | - |
222 | return; | 0 |
223 | } | - |
224 | | - |
225 | takeAnimation(index); executed (the execution status of this line is deduced): takeAnimation(index); | - |
226 | } executed: } Execution Count:8 | 8 |
227 | | - |
228 | /*! | - |
229 | Returns the animation at \a index and removes it from the animation group. | - |
230 | | - |
231 | \note The ownership of the animation is transferred to the caller. | - |
232 | | - |
233 | \sa removeAnimation(), addAnimation(), insertAnimation(), indexOfAnimation() | - |
234 | */ | - |
235 | QAbstractAnimation *QAnimationGroup::takeAnimation(int index) | - |
236 | { | - |
237 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
238 | if (index < 0 || index >= d->animations.size()) { partially evaluated: index < 0 no Evaluation Count:0 | yes Evaluation Count:229 |
partially evaluated: index >= d->animations.size() no Evaluation Count:0 | yes Evaluation Count:229 |
| 0-229 |
239 | qWarning("QAnimationGroup::takeAnimation: no animation at index %d", index); never executed (the execution status of this line is deduced): QMessageLogger("animation/qanimationgroup.cpp", 239, __PRETTY_FUNCTION__).warning("QAnimationGroup::takeAnimation: no animation at index %d", index); | - |
240 | return 0; never executed: return 0; | 0 |
241 | } | - |
242 | QAbstractAnimation *animation = d->animations.at(index); executed (the execution status of this line is deduced): QAbstractAnimation *animation = d->animations.at(index); | - |
243 | QAbstractAnimationPrivate::get(animation)->group = 0; executed (the execution status of this line is deduced): QAbstractAnimationPrivate::get(animation)->group = 0; | - |
244 | // ### removing from list before doing setParent to avoid inifinite recursion | - |
245 | // in ChildRemoved event | - |
246 | d->animations.removeAt(index); executed (the execution status of this line is deduced): d->animations.removeAt(index); | - |
247 | animation->setParent(0); executed (the execution status of this line is deduced): animation->setParent(0); | - |
248 | d->animationRemoved(index, animation); executed (the execution status of this line is deduced): d->animationRemoved(index, animation); | - |
249 | return animation; executed: return animation; Execution Count:229 | 229 |
250 | } | - |
251 | | - |
252 | /*! | - |
253 | Removes and deletes all animations in this animation group, and resets the current | - |
254 | time to 0. | - |
255 | | - |
256 | \sa addAnimation(), removeAnimation() | - |
257 | */ | - |
258 | void QAnimationGroup::clear() | - |
259 | { | - |
260 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
261 | qDeleteAll(d->animations); executed (the execution status of this line is deduced): qDeleteAll(d->animations); | - |
262 | } executed: } Execution Count:5 | 5 |
263 | | - |
264 | /*! | - |
265 | \reimp | - |
266 | */ | - |
267 | bool QAnimationGroup::event(QEvent *event) | - |
268 | { | - |
269 | Q_D(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroupPrivate * const d = d_func(); | - |
270 | if (event->type() == QEvent::ChildAdded) { evaluated: event->type() == QEvent::ChildAdded yes Evaluation Count:337 | yes Evaluation Count:450 |
| 337-450 |
271 | QChildEvent *childEvent = static_cast<QChildEvent *>(event); executed (the execution status of this line is deduced): QChildEvent *childEvent = static_cast<QChildEvent *>(event); | - |
272 | if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) { partially evaluated: QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child()) yes Evaluation Count:337 | no Evaluation Count:0 |
| 0-337 |
273 | if (a->group() != this) evaluated: a->group() != this yes Evaluation Count:65 | yes Evaluation Count:272 |
| 65-272 |
274 | addAnimation(a); executed: addAnimation(a); Execution Count:65 | 65 |
275 | } executed: } Execution Count:337 | 337 |
276 | } else if (event->type() == QEvent::ChildRemoved) { executed: } Execution Count:337 partially evaluated: event->type() == QEvent::ChildRemoved yes Evaluation Count:450 | no Evaluation Count:0 |
| 0-450 |
277 | QChildEvent *childEvent = static_cast<QChildEvent *>(event); executed (the execution status of this line is deduced): QChildEvent *childEvent = static_cast<QChildEvent *>(event); | - |
278 | QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child()); executed (the execution status of this line is deduced): QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child()); | - |
279 | // You can only rely on the child being a QObject because in the QEvent::ChildRemoved | - |
280 | // case it might be called from the destructor. | - |
281 | int index = d->animations.indexOf(a); executed (the execution status of this line is deduced): int index = d->animations.indexOf(a); | - |
282 | if (index != -1) evaluated: index != -1 yes Evaluation Count:221 | yes Evaluation Count:229 |
| 221-229 |
283 | takeAnimation(index); executed: takeAnimation(index); Execution Count:221 | 221 |
284 | } executed: } Execution Count:450 | 450 |
285 | return QAbstractAnimation::event(event); executed: return QAbstractAnimation::event(event); Execution Count:787 | 787 |
286 | } | - |
287 | | - |
288 | | - |
289 | void QAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *) | - |
290 | { | - |
291 | Q_Q(QAnimationGroup); executed (the execution status of this line is deduced): QAnimationGroup * const q = q_func(); | - |
292 | Q_UNUSED(index); executed (the execution status of this line is deduced): (void)index;; | - |
293 | if (animations.isEmpty()) { evaluated: animations.isEmpty() yes Evaluation Count:77 | yes Evaluation Count:152 |
| 77-152 |
294 | currentTime = 0; executed (the execution status of this line is deduced): currentTime = 0; | - |
295 | q->stop(); executed (the execution status of this line is deduced): q->stop(); | - |
296 | } executed: } Execution Count:77 | 77 |
297 | } executed: } Execution Count:229 | 229 |
298 | | - |
299 | QT_END_NAMESPACE | - |
300 | | - |
301 | #include "moc_qanimationgroup.cpp" | - |
302 | | - |
303 | #endif //QT_NO_ANIMATION | - |
304 | | - |
| | |