qabstracttransition.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qabstracttransition.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#include "qabstracttransition.h"-
35-
36#ifndef QT_NO_STATEMACHINE-
37-
38#include "qabstracttransition_p.h"-
39#include "qabstractstate.h"-
40#include "qhistorystate.h"-
41#include "qstate.h"-
42#include "qstatemachine.h"-
43-
44QT_BEGIN_NAMESPACE-
45-
46/*!-
47 \class QAbstractTransition-
48 \inmodule QtCore-
49-
50 \brief The QAbstractTransition class is the base class of transitions between QAbstractState objects.-
51-
52 \since 4.6-
53 \ingroup statemachine-
54-
55 The QAbstractTransition class is the abstract base class of transitions-
56 between states (QAbstractState objects) of a-
57 QStateMachine. QAbstractTransition is part of \l{The State Machine-
58 Framework}.-
59-
60 The sourceState() function returns the source of the transition. The-
61 targetStates() function returns the targets of the transition. The machine()-
62 function returns the state machine that the transition is part of.-
63-
64 The triggered() signal is emitted when the transition has been triggered.-
65-
66 Transitions can cause animations to be played. Use the addAnimation()-
67 function to add an animation to the transition.-
68-
69 \section1 Subclassing-
70-
71 The eventTest() function is called by the state machine to determine whether-
72 an event should trigger the transition. In your reimplementation you-
73 typically check the event type and cast the event object to the proper type,-
74 and check that one or more properties of the event meet your criteria.-
75-
76 The onTransition() function is called when the transition is triggered;-
77 reimplement this function to perform custom processing for the transition.-
78*/-
79-
80/*!-
81 \property QAbstractTransition::sourceState-
82-
83 \brief the source state (parent) of this transition-
84*/-
85-
86/*!-
87 \property QAbstractTransition::targetState-
88-
89 \brief the target state of this transition-
90-
91 If a transition has no target state, the transition may still be-
92 triggered, but this will not cause the state machine's configuration to-
93 change (i.e. the current state will not be exited and re-entered).-
94*/-
95-
96/*!-
97 \property QAbstractTransition::targetStates-
98-
99 \brief the target states of this transition-
100-
101 If multiple states are specified, all must be descendants of the same-
102 parallel group state.-
103*/-
104-
105/*!-
106 \property QAbstractTransition::transitionType-
107-
108 \brief indicates whether this transition is an internal transition, or an external transition.-
109-
110 Internal and external transitions behave the same, except for the case of a transition whose-
111 source state is a compound state and whose target(s) is a descendant of the source. In such a-
112 case, an internal transition will not exit and re-enter its source state, while an external one-
113 will.-
114-
115 By default, the type is an external transition.-
116*/-
117-
118/*!-
119 \enum QAbstractTransition::TransitionType-
120-
121 This enum specifies the kind of transition. By default, the type is an external transition.-
122-
123 \value ExternalTransition Any state that is the source state of a transition (which is not a-
124 target-less transition) is left, and re-entered when necessary.-
125 \value InternalTransition If the target state of a transition is a sub-state of a compound state,-
126 and that compound state is the source state, an internal transition will-
127 not leave the source state.-
128-
129 \sa QAbstractTransition::transitionType-
130*/-
131-
132QAbstractTransitionPrivate::QAbstractTransitionPrivate()-
133 : transitionType(QAbstractTransition::ExternalTransition)-
134{-
135}
executed 400 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
400
136-
137QStateMachine *QAbstractTransitionPrivate::machine() const-
138{-
139 if (QState *source = sourceState())
QState *source = sourceState()Description
TRUEevaluated 400175 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 90 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
90-400175
140 return source->machine();
executed 398627 times by 2 tests: return source->machine();
Executed by:
  • tst_QState
  • tst_QStateMachine
398627
141 Q_Q(const QAbstractTransition);-
142 if (QHistoryState *parent = qobject_cast<QHistoryState *>(q->parent()))
QHistoryState ...>(q->parent())Description
TRUEnever evaluated
FALSEevaluated 90 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
0-90
143 return parent->machine();
never executed: return parent->machine();
0
144 return 0;
executed 90 times by 2 tests: return 0;
Executed by:
  • tst_QState
  • tst_QStateMachine
90
145}-
146-
147bool QAbstractTransitionPrivate::callEventTest(QEvent *e)-
148{-
149 Q_Q(QAbstractTransition);-
150 return q->eventTest(e);
executed 5952 times by 2 tests: return q->eventTest(e);
Executed by:
  • tst_QState
  • tst_QStateMachine
5952
151}-
152-
153void QAbstractTransitionPrivate::callOnTransition(QEvent *e)-
154{-
155 Q_Q(QAbstractTransition);-
156 q->onTransition(e);-
157}
executed 1320 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1320
158-
159QState *QAbstractTransitionPrivate::sourceState() const-
160{-
161 return qobject_cast<QState*>(parent);
executed 600782 times by 2 tests: return qobject_cast<QState*>(parent);
Executed by:
  • tst_QState
  • tst_QStateMachine
600782
162}-
163-
164void QAbstractTransitionPrivate::emitTriggered()-
165{-
166 Q_Q(QAbstractTransition);-
167 emit q->triggered(QAbstractTransition::QPrivateSignal());-
168}
executed 1391 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1391
169-
170/*!-
171 Constructs a new QAbstractTransition object with the given \a sourceState.-
172*/-
173QAbstractTransition::QAbstractTransition(QState *sourceState)-
174 : QObject(*new QAbstractTransitionPrivate, sourceState)-
175{-
176}
executed 304 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
304
177-
178/*!-
179 \internal-
180*/-
181QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,-
182 QState *parent)-
183 : QObject(dd, parent)-
184{-
185}
executed 96 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
96
186-
187/*!-
188 Destroys this transition.-
189*/-
190QAbstractTransition::~QAbstractTransition()-
191{-
192}-
193-
194/*!-
195 Returns the source state of this transition, or 0 if this transition has no-
196 source state.-
197*/-
198QState *QAbstractTransition::sourceState() const-
199{-
200 Q_D(const QAbstractTransition);-
201 return d->sourceState();
executed 202875 times by 2 tests: return d->sourceState();
Executed by:
  • tst_QState
  • tst_QStateMachine
202875
202}-
203-
204/*!-
205 Returns the target state of this transition, or 0 if the transition has no-
206 target.-
207*/-
208QAbstractState *QAbstractTransition::targetState() const-
209{-
210 Q_D(const QAbstractTransition);-
211 if (d->targetStates.isEmpty())
d->targetStates.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 17 times by 1 test
Evaluated by:
  • tst_QStateMachine
2-17
212 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QStateMachine
2
213 return d->targetStates.first().data();
executed 17 times by 1 test: return d->targetStates.first().data();
Executed by:
  • tst_QStateMachine
17
214}-
215-
216/*!-
217 Sets the \a target state of this transition.-
218*/-
219void QAbstractTransition::setTargetState(QAbstractState* target)-
220{-
221 Q_D(QAbstractTransition);-
222 if ((d->targetStates.size() == 1 && target == d->targetStates.at(0).data()) ||
d->targetStates.size() == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 236 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
target == d->t...s.at(0).data()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1-236
223 (d->targetStates.isEmpty() && target == 0)) {
d->targetStates.isEmpty()Description
TRUEevaluated 236 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
target == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 234 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1-236
224 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QStateMachine
3
225 }-
226 if (!target)
!targetDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 234 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1-234
227 d->targetStates.clear();
executed 1 time by 1 test: d->targetStates.clear();
Executed by:
  • tst_QStateMachine
1
228 else-
229 setTargetStates(QList<QAbstractState*>() << target);
executed 234 times by 2 tests: setTargetStates(QList<QAbstractState*>() << target);
Executed by:
  • tst_QState
  • tst_QStateMachine
234
230 emit targetStateChanged(QPrivateSignal());-
231}
executed 235 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
235
232-
233/*!-
234 Returns the target states of this transition, or an empty list if this-
235 transition has no target states.-
236*/-
237QList<QAbstractState*> QAbstractTransition::targetStates() const-
238{-
239 Q_D(const QAbstractTransition);-
240 QList<QAbstractState*> result;-
241 for (int i = 0; i < d->targetStates.size(); ++i) {
i < d->targetStates.size()Description
TRUEevaluated 4184 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 4201 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
4184-4201
242 QAbstractState *target = d->targetStates.at(i).data();-
243 if (target)
targetDescription
TRUEevaluated 4183 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1-4183
244 result.append(target);
executed 4183 times by 2 tests: result.append(target);
Executed by:
  • tst_QState
  • tst_QStateMachine
4183
245 }
executed 4184 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
4184
246 return result;
executed 4201 times by 2 tests: return result;
Executed by:
  • tst_QState
  • tst_QStateMachine
4201
247}-
248-
249/*!-
250 Sets the target states of this transition to be the given \a targets.-
251*/-
252void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets)-
253{-
254 Q_D(QAbstractTransition);-
255-
256 // Verify if any of the new target states is a null-pointer:-
257 for (int i = 0; i < targets.size(); ++i) {
i < targets.size()Description
TRUEevaluated 392 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 389 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
389-392
258 if (targets.at(i) == Q_NULLPTR) {
targets.at(i) == nullptrDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 391 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1-391
259 qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null");-
260 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QStateMachine
1
261 }-
262 }
executed 391 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
391
263-
264 // First clean out any target states that got destroyed, but for which we still have a QPointer-
265 // around.-
266 for (int i = 0; i < d->targetStates.size(); ) {
i < d->targetStates.size()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 389 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1-389
267 if (d->targetStates.at(i).isNull()) {
d->targetStates.at(i).isNull()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
0-1
268 d->targetStates.remove(i);-
269 } else {
never executed: end of block
0
270 ++i;-
271 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
272 }-
273-
274 // Easy check: if both lists are empty, we're done.-
275 if (targets.isEmpty() && d->targetStates.isEmpty())
targets.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 389 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
d->targetStates.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0-389
276 return;
never executed: return;
0
277-
278 bool sameList = true;-
279-
280 if (targets.size() != d->targetStates.size()) {
targets.size()...tStates.size()Description
TRUEevaluated 388 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1-388
281 // If the sizes of the lists are different, we don't need to be smart: they're different. So-
282 // we can just set the new list as the targetStates.-
283 sameList = false;-
284 } else {
executed 388 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
388
285 QVector<QPointer<QAbstractState> > copy(d->targetStates);-
286 for (int i = 0; i < targets.size(); ++i) {
i < targets.size()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1
287 sameList &= copy.removeOne(targets.at(i));-
288 if (!sameList)
!sameListDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
0-1
289 break; // ok, we now know the lists are not the same, so stop the loop.
never executed: break;
0
290 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
291-
292 sameList &= copy.isEmpty();-
293 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
294-
295 if (sameList)
sameListDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 388 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1-388
296 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QStateMachine
1
297-
298 d->targetStates.resize(targets.size());-
299 for (int i = 0; i < targets.size(); ++i) {
i < targets.size()Description
TRUEevaluated 390 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 388 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
388-390
300 d->targetStates[i] = targets.at(i);-
301 }
executed 390 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
390
302-
303 emit targetStatesChanged(QPrivateSignal());-
304}
executed 388 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
388
305-
306/*!-
307 Returns the type of the transition.-
308*/-
309QAbstractTransition::TransitionType QAbstractTransition::transitionType() const-
310{-
311 Q_D(const QAbstractTransition);-
312 return d->transitionType;
executed 1389 times by 2 tests: return d->transitionType;
Executed by:
  • tst_QState
  • tst_QStateMachine
1389
313}-
314-
315/*!-
316 Sets the type of the transition to \a type.-
317*/-
318void QAbstractTransition::setTransitionType(TransitionType type)-
319{-
320 Q_D(QAbstractTransition);-
321 d->transitionType = type;-
322}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
323-
324/*!-
325 Returns the state machine that this transition is part of, or 0 if the-
326 transition is not part of a state machine.-
327*/-
328QStateMachine *QAbstractTransition::machine() const-
329{-
330 Q_D(const QAbstractTransition);-
331 return d->machine();
executed 147 times by 2 tests: return d->machine();
Executed by:
  • tst_QState
  • tst_QStateMachine
147
332}-
333-
334#ifndef QT_NO_ANIMATION-
335-
336/*!-
337 Adds the given \a animation to this transition.-
338 The transition does not take ownership of the animation.-
339-
340 \sa removeAnimation(), animations()-
341*/-
342void QAbstractTransition::addAnimation(QAbstractAnimation *animation)-
343{-
344 Q_D(QAbstractTransition);-
345 if (!animation) {
!animationDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 26 times by 1 test
Evaluated by:
  • tst_QStateMachine
1-26
346 qWarning("QAbstractTransition::addAnimation: cannot add null animation");-
347 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QStateMachine
1
348 }-
349 d->animations.append(animation);-
350}
executed 26 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
26
351-
352/*!-
353 Removes the given \a animation from this transition.-
354-
355 \sa addAnimation()-
356*/-
357void QAbstractTransition::removeAnimation(QAbstractAnimation *animation)-
358{-
359 Q_D(QAbstractTransition);-
360 if (!animation) {
!animationDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1
361 qWarning("QAbstractTransition::removeAnimation: cannot remove null animation");-
362 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QStateMachine
1
363 }-
364 d->animations.removeOne(animation);-
365}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
366-
367/*!-
368 Returns the list of animations associated with this transition, or an empty-
369 list if it has no animations.-
370-
371 \sa addAnimation()-
372*/-
373QList<QAbstractAnimation*> QAbstractTransition::animations() const-
374{-
375 Q_D(const QAbstractTransition);-
376 return d->animations;
executed 1397 times by 2 tests: return d->animations;
Executed by:
  • tst_QState
  • tst_QStateMachine
1397
377}-
378-
379#endif-
380-
381/*!-
382 \fn QAbstractTransition::eventTest(QEvent *event)-
383-
384 This function is called to determine whether the given \a event should cause-
385 this transition to trigger. Reimplement this function and return true if the-
386 event should trigger the transition, otherwise return false.-
387*/-
388-
389/*!-
390 \fn QAbstractTransition::onTransition(QEvent *event)-
391-
392 This function is called when the transition is triggered. The given \a event-
393 is what caused the transition to trigger. Reimplement this function to-
394 perform custom processing when the transition is triggered.-
395*/-
396-
397/*!-
398 \fn QAbstractTransition::triggered()-
399-
400 This signal is emitted when the transition has been triggered (after-
401 onTransition() has been called).-
402*/-
403-
404/*!-
405 \fn QAbstractTransition::targetStateChanged()-
406 \since 5.4-
407-
408 This signal is emitted when the targetState property is changed.-
409-
410 \sa QAbstractTransition::targetState-
411*/-
412-
413/*!-
414 \fn QAbstractTransition::targetStatesChanged()-
415 \since 5.4-
416-
417 This signal is emitted when the targetStates property is changed.-
418-
419 \sa QAbstractTransition::targetStates-
420*/-
421-
422/*!-
423 \reimp-
424*/-
425bool QAbstractTransition::event(QEvent *e)-
426{-
427 return QObject::event(e);
executed 4 times by 1 test: return QObject::event(e);
Executed by:
  • tst_QStateMachine
4
428}-
429-
430QT_END_NAMESPACE-
431-
432#endif //QT_NO_STATEMACHINE-
Source codeSwitch to Preprocessed file

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