Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/animation/qparallelanimationgroup.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | typedef QList<QAbstractAnimation *>::ConstIterator AnimationListConstIt; | - | ||||||||||||
8 | typedef QHash<QAbstractAnimation*, int>::Iterator AnimationTimeHashIt; | - | ||||||||||||
9 | typedef QHash<QAbstractAnimation*, int>::ConstIterator AnimationTimeHashConstIt; | - | ||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | - | |||||||||||||
15 | QParallelAnimationGroup::QParallelAnimationGroup(QObject *parent) | - | ||||||||||||
16 | : QAnimationGroup(*new QParallelAnimationGroupPrivate, parent) | - | ||||||||||||
17 | { | - | ||||||||||||
18 | } executed 81 times by 5 tests: end of block Executed by:
| 81 | ||||||||||||
19 | - | |||||||||||||
20 | - | |||||||||||||
21 | - | |||||||||||||
22 | - | |||||||||||||
23 | QParallelAnimationGroup::QParallelAnimationGroup(QParallelAnimationGroupPrivate &dd, | - | ||||||||||||
24 | QObject *parent) | - | ||||||||||||
25 | : QAnimationGroup(dd, parent) | - | ||||||||||||
26 | { | - | ||||||||||||
27 | } never executed: end of block | 0 | ||||||||||||
28 | - | |||||||||||||
29 | - | |||||||||||||
30 | - | |||||||||||||
31 | - | |||||||||||||
32 | QParallelAnimationGroup::~QParallelAnimationGroup() | - | ||||||||||||
33 | { | - | ||||||||||||
34 | } | - | ||||||||||||
35 | - | |||||||||||||
36 | - | |||||||||||||
37 | - | |||||||||||||
38 | - | |||||||||||||
39 | int QParallelAnimationGroup::duration() const | - | ||||||||||||
40 | { | - | ||||||||||||
41 | const QParallelAnimationGroupPrivate * const d = d_func(); | - | ||||||||||||
42 | int ret = 0; | - | ||||||||||||
43 | - | |||||||||||||
44 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 505-1359 | ||||||||||||
45 | const int currentDuration = (*it)->totalDuration(); | - | ||||||||||||
46 | if (currentDuration == -1
| 9-1350 | ||||||||||||
47 | return executed 9 times by 2 tests: -1;return -1; Executed by:
executed 9 times by 2 tests: return -1; Executed by:
| 9 | ||||||||||||
48 | - | |||||||||||||
49 | ret = qMax(ret, currentDuration); | - | ||||||||||||
50 | } executed 1350 times by 5 tests: end of block Executed by:
| 1350 | ||||||||||||
51 | - | |||||||||||||
52 | return executed 505 times by 5 tests: ret;return ret; Executed by:
executed 505 times by 5 tests: return ret; Executed by:
| 505 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | - | |||||||||||||
56 | - | |||||||||||||
57 | - | |||||||||||||
58 | void QParallelAnimationGroup::updateCurrentTime(int currentTime) | - | ||||||||||||
59 | { | - | ||||||||||||
60 | QParallelAnimationGroupPrivate * const d = d_func(); | - | ||||||||||||
61 | if (d->animations.isEmpty()
| 0-325 | ||||||||||||
62 | return; never executed: return; | 0 | ||||||||||||
63 | - | |||||||||||||
64 | if (d->currentLoop > d->lastLoop
| 45-280 | ||||||||||||
65 | - | |||||||||||||
66 | int dura = duration(); | - | ||||||||||||
67 | if (dura > 0
| 0-45 | ||||||||||||
68 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 45-136 | ||||||||||||
69 | QAbstractAnimation *animation = (*it); | - | ||||||||||||
70 | if (animation->state() != QAbstractAnimation::Stopped
| 52-84 | ||||||||||||
71 | animation->setCurrentTime(dura); executed 52 times by 2 tests: animation->setCurrentTime(dura); Executed by:
| 52 | ||||||||||||
72 | } executed 136 times by 2 tests: end of block Executed by:
| 136 | ||||||||||||
73 | } executed 45 times by 2 tests: end of block Executed by:
| 45 | ||||||||||||
74 | } executed 45 times by 2 tests: else if (d->currentLoop < d->lastLoopend of block Executed by:
| 28-252 | ||||||||||||
75 | - | |||||||||||||
76 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 28-84 | ||||||||||||
77 | QAbstractAnimation *animation = *it; | - | ||||||||||||
78 | - | |||||||||||||
79 | - | |||||||||||||
80 | d->applyGroupState(animation); | - | ||||||||||||
81 | animation->setCurrentTime(0); | - | ||||||||||||
82 | animation->stop(); | - | ||||||||||||
83 | } executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||
84 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||
85 | - | |||||||||||||
86 | - | |||||||||||||
87 | - | |||||||||||||
88 | - | |||||||||||||
89 | - | |||||||||||||
90 | - | |||||||||||||
91 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 325-947 | ||||||||||||
92 | QAbstractAnimation *animation = *it; | - | ||||||||||||
93 | const int dura = animation->totalDuration(); | - | ||||||||||||
94 | - | |||||||||||||
95 | if (d->currentLoop > d->lastLoop
| 136-811 | ||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | || d->shouldAnimationStart(animation, d->lastCurrentTime > dura )
| 260-551 | ||||||||||||
99 | d->applyGroupState(animation); | - | ||||||||||||
100 | } executed 687 times by 5 tests: end of block Executed by:
| 687 | ||||||||||||
101 | - | |||||||||||||
102 | if (animation->state() == state()
| 180-767 | ||||||||||||
103 | animation->setCurrentTime(currentTime); | - | ||||||||||||
104 | if (dura > 0
| 33-655 | ||||||||||||
105 | animation->stop(); executed 33 times by 3 tests: animation->stop(); Executed by:
| 33 | ||||||||||||
106 | } executed 767 times by 5 tests: end of block Executed by:
| 767 | ||||||||||||
107 | } executed 947 times by 5 tests: end of block Executed by:
| 947 | ||||||||||||
108 | d->lastLoop = d->currentLoop; | - | ||||||||||||
109 | d->lastCurrentTime = currentTime; | - | ||||||||||||
110 | } executed 325 times by 5 tests: end of block Executed by:
| 325 | ||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | void QParallelAnimationGroup::updateState(QAbstractAnimation::State newState, | - | ||||||||||||
116 | QAbstractAnimation::State oldState) | - | ||||||||||||
117 | { | - | ||||||||||||
118 | QParallelAnimationGroupPrivate * const d = d_func(); | - | ||||||||||||
119 | QAnimationGroup::updateState(newState, oldState); | - | ||||||||||||
120 | - | |||||||||||||
121 | switch (newState) { | - | ||||||||||||
122 | case executed 57 times by 3 tests: Stopped:case Stopped: Executed by:
executed 57 times by 3 tests: case Stopped: Executed by:
| 57 | ||||||||||||
123 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 41-57 | ||||||||||||
124 | (* executed 41 times by 3 tests: it)->stop();(*it)->stop(); Executed by:
executed 41 times by 3 tests: (*it)->stop(); Executed by:
| 41 | ||||||||||||
125 | d->disconnectUncontrolledAnimations(); | - | ||||||||||||
126 | break; executed 57 times by 3 tests: break; Executed by:
| 57 | ||||||||||||
127 | case executed 4 times by 2 tests: Paused:case Paused: Executed by:
executed 4 times by 2 tests: case Paused: Executed by:
| 4 | ||||||||||||
128 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 4-6 | ||||||||||||
129 | if ((*
| 1-5 | ||||||||||||
130 | (* executed 5 times by 2 tests: it)->pause();(*it)->pause(); Executed by:
executed 5 times by 2 tests: (*it)->pause(); Executed by:
| 5 | ||||||||||||
131 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||
132 | break; executed 4 times by 2 tests: break; Executed by:
| 4 | ||||||||||||
133 | case executed 62 times by 4 tests: Running:case Running: Executed by:
executed 62 times by 4 tests: case Running: Executed by:
| 62 | ||||||||||||
134 | d->connectUncontrolledAnimations(); | - | ||||||||||||
135 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 62-168 | ||||||||||||
136 | QAbstractAnimation *animation = *it; | - | ||||||||||||
137 | if (oldState == Stopped
| 4-164 | ||||||||||||
138 | animation->stop(); executed 164 times by 4 tests: animation->stop(); Executed by:
| 164 | ||||||||||||
139 | animation->setDirection(d->direction); | - | ||||||||||||
140 | if (d->shouldAnimationStart(animation, oldState == Stopped)
| 54-114 | ||||||||||||
141 | animation->start(); executed 114 times by 4 tests: animation->start(); Executed by:
| 114 | ||||||||||||
142 | } executed 168 times by 4 tests: end of block Executed by:
| 168 | ||||||||||||
143 | break; executed 62 times by 4 tests: break; Executed by:
| 62 | ||||||||||||
144 | } | - | ||||||||||||
145 | } executed 123 times by 4 tests: end of block Executed by:
| 123 | ||||||||||||
146 | - | |||||||||||||
147 | void QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished() | - | ||||||||||||
148 | { | - | ||||||||||||
149 | QParallelAnimationGroup * const q = q_func(); | - | ||||||||||||
150 | - | |||||||||||||
151 | QAbstractAnimation *animation = qobject_cast<QAbstractAnimation *>(q->sender()); | - | ||||||||||||
152 | ((!(animation)) ? qt_assert("animation",__FILE__,218) : qt_noop()); | - | ||||||||||||
153 | - | |||||||||||||
154 | int uncontrolledRunningCount = 0; | - | ||||||||||||
155 | if (animation->duration() == -1
| 0-1 | ||||||||||||
156 | for (AnimationTimeHashIt it = uncontrolledFinishTime.begin(), cend = uncontrolledFinishTime.end(); it != cend
| 2-4 | ||||||||||||
157 | if (it.key() == animation
| 2 | ||||||||||||
158 | *it = animation->currentTime(); | - | ||||||||||||
159 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
160 | if (it.value() == -1
| 1-3 | ||||||||||||
161 | ++ executed 1 time by 1 test: uncontrolledRunningCount;++uncontrolledRunningCount; Executed by:
executed 1 time by 1 test: ++uncontrolledRunningCount; Executed by:
| 1 | ||||||||||||
162 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
163 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
164 | - | |||||||||||||
165 | if (uncontrolledRunningCount > 0
| 1 | ||||||||||||
166 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||
167 | - | |||||||||||||
168 | int maxDuration = 0; | - | ||||||||||||
169 | for (AnimationListConstIt it = animations.constBegin(), cend = animations.constEnd(); it != cend
| 1-3 | ||||||||||||
170 | maxDuration = qMax(maxDuration, (*it)->totalDuration()); executed 3 times by 1 test: maxDuration = qMax(maxDuration, (*it)->totalDuration()); Executed by:
| 3 | ||||||||||||
171 | - | |||||||||||||
172 | if (currentTime >= maxDuration
| 0-1 | ||||||||||||
173 | q->stop(); executed 1 time by 1 test: q->stop(); Executed by:
| 1 | ||||||||||||
174 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
175 | - | |||||||||||||
176 | void QParallelAnimationGroupPrivate::disconnectUncontrolledAnimations() | - | ||||||||||||
177 | { | - | ||||||||||||
178 | for (AnimationTimeHashConstIt it = uncontrolledFinishTime.constBegin(), cend = uncontrolledFinishTime.constEnd(); it != cend
| 3-57 | ||||||||||||
179 | disconnectUncontrolledAnimation(it.key()); executed 3 times by 1 test: disconnectUncontrolledAnimation(it.key()); Executed by:
| 3 | ||||||||||||
180 | - | |||||||||||||
181 | uncontrolledFinishTime.clear(); | - | ||||||||||||
182 | } executed 57 times by 3 tests: end of block Executed by:
| 57 | ||||||||||||
183 | - | |||||||||||||
184 | void QParallelAnimationGroupPrivate::connectUncontrolledAnimations() | - | ||||||||||||
185 | { | - | ||||||||||||
186 | for (AnimationListConstIt it = animations.constBegin(), cend = animations.constEnd(); it != cend
| 62-168 | ||||||||||||
187 | QAbstractAnimation *animation = *it; | - | ||||||||||||
188 | if (animation->duration() == -1
| 1-167 | ||||||||||||
189 | uncontrolledFinishTime[animation] = -1; | - | ||||||||||||
190 | connectUncontrolledAnimation(animation); | - | ||||||||||||
191 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
192 | } executed 168 times by 4 tests: end of block Executed by:
| 168 | ||||||||||||
193 | } executed 62 times by 4 tests: end of block Executed by:
| 62 | ||||||||||||
194 | - | |||||||||||||
195 | bool QParallelAnimationGroupPrivate::shouldAnimationStart(QAbstractAnimation *animation, bool startIfAtEnd) const | - | ||||||||||||
196 | { | - | ||||||||||||
197 | const int dura = animation->totalDuration(); | - | ||||||||||||
198 | if (dura == -1
| 20-959 | ||||||||||||
199 | return executed 20 times by 2 tests: !isUncontrolledAnimationFinished(animation);return !isUncontrolledAnimationFinished(animation); Executed by:
executed 20 times by 2 tests: return !isUncontrolledAnimationFinished(animation); Executed by:
| 20 | ||||||||||||
200 | if (startIfAtEnd
| 331-628 | ||||||||||||
201 | return executed 331 times by 4 tests: currentTime <= dura;return currentTime <= dura; Executed by:
executed 331 times by 4 tests: return currentTime <= dura; Executed by:
| 331 | ||||||||||||
202 | if (direction == QAbstractAnimation::Forward
| 63-565 | ||||||||||||
203 | return executed 565 times by 5 tests: currentTime < dura;return currentTime < dura; Executed by:
executed 565 times by 5 tests: return currentTime < dura; Executed by:
| 565 | ||||||||||||
204 | else | - | ||||||||||||
205 | return executed 63 times by 1 test: currentTimereturn currentTime && currentTime <= dura; Executed by:
executed 63 times by 1 test: return currentTime && currentTime <= dura; Executed by:
| 2-63 | ||||||||||||
206 | } | - | ||||||||||||
207 | - | |||||||||||||
208 | void QParallelAnimationGroupPrivate::applyGroupState(QAbstractAnimation *animation) | - | ||||||||||||
209 | { | - | ||||||||||||
210 | switch (state) | - | ||||||||||||
211 | { | - | ||||||||||||
212 | case executed 634 times by 4 tests: QAbstractAnimation::Running:case QAbstractAnimation::Running: Executed by:
executed 634 times by 4 tests: case QAbstractAnimation::Running: Executed by:
| 634 | ||||||||||||
213 | animation->start(); | - | ||||||||||||
214 | break; executed 634 times by 4 tests: break; Executed by:
| 634 | ||||||||||||
215 | case never executed: QAbstractAnimation::Paused:case QAbstractAnimation::Paused: never executed: case QAbstractAnimation::Paused: | 0 | ||||||||||||
216 | animation->pause(); | - | ||||||||||||
217 | break; never executed: break; | 0 | ||||||||||||
218 | case executed 137 times by 2 tests: QAbstractAnimation::Stopped:case QAbstractAnimation::Stopped: Executed by:
executed 137 times by 2 tests: case QAbstractAnimation::Stopped: Executed by:
| 137 | ||||||||||||
219 | default never executed: :default: never executed: default: | 0 | ||||||||||||
220 | break; executed 137 times by 2 tests: break; Executed by:
| 137 | ||||||||||||
221 | } | - | ||||||||||||
222 | } | - | ||||||||||||
223 | - | |||||||||||||
224 | - | |||||||||||||
225 | bool QParallelAnimationGroupPrivate::isUncontrolledAnimationFinished(QAbstractAnimation *anim) const | - | ||||||||||||
226 | { | - | ||||||||||||
227 | return executed 20 times by 2 tests: uncontrolledFinishTime.value(anim, -1) >= 0;return uncontrolledFinishTime.value(anim, -1) >= 0; Executed by:
executed 20 times by 2 tests: return uncontrolledFinishTime.value(anim, -1) >= 0; Executed by:
| 20 | ||||||||||||
228 | } | - | ||||||||||||
229 | - | |||||||||||||
230 | void QParallelAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *anim) | - | ||||||||||||
231 | { | - | ||||||||||||
232 | QAnimationGroupPrivate::animationRemoved(index, anim); | - | ||||||||||||
233 | disconnectUncontrolledAnimation(anim); | - | ||||||||||||
234 | uncontrolledFinishTime.remove(anim); | - | ||||||||||||
235 | } executed 164 times by 2 tests: end of block Executed by:
| 164 | ||||||||||||
236 | - | |||||||||||||
237 | - | |||||||||||||
238 | - | |||||||||||||
239 | - | |||||||||||||
240 | void QParallelAnimationGroup::updateDirection(QAbstractAnimation::Direction direction) | - | ||||||||||||
241 | { | - | ||||||||||||
242 | QParallelAnimationGroupPrivate * const d = d_func(); | - | ||||||||||||
243 | - | |||||||||||||
244 | if (state() != Stopped
| 0-19 | ||||||||||||
245 | for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend
| 0 | ||||||||||||
246 | (* never executed: it)->setDirection(direction);(*it)->setDirection(direction); never executed: (*it)->setDirection(direction); | 0 | ||||||||||||
247 | } never executed: else {end of block | 0 | ||||||||||||
248 | if (direction == Forward
| 0-19 | ||||||||||||
249 | d->lastLoop = 0; | - | ||||||||||||
250 | d->lastCurrentTime = 0; | - | ||||||||||||
251 | } never executed: else {end of block | 0 | ||||||||||||
252 | - | |||||||||||||
253 | d->lastLoop = (d->loopCount == -1
| 3-16 | ||||||||||||
254 | d->lastCurrentTime = duration(); | - | ||||||||||||
255 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||
256 | } | - | ||||||||||||
257 | } | - | ||||||||||||
258 | - | |||||||||||||
259 | - | |||||||||||||
260 | - | |||||||||||||
261 | - | |||||||||||||
262 | bool QParallelAnimationGroup::event(QEvent *event) | - | ||||||||||||
263 | { | - | ||||||||||||
264 | return executed 520 times by 5 tests: QAnimationGroup::event(event);return QAnimationGroup::event(event); Executed by:
executed 520 times by 5 tests: return QAnimationGroup::event(event); Executed by:
| 520 | ||||||||||||
265 | } | - | ||||||||||||
266 | - | |||||||||||||
267 | - | |||||||||||||
268 | - | |||||||||||||
Switch to Source code | Preprocessed file |