statemachine/qabstracttransition.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 "qabstracttransition.h" -
43 -
44#ifndef QT_NO_STATEMACHINE -
45 -
46#include "qabstracttransition_p.h" -
47#include "qabstractstate.h" -
48#include "qstate.h" -
49#include "qstatemachine.h" -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53/*! -
54 \class QAbstractTransition -
55 \inmodule QtCore -
56 -
57 \brief The QAbstractTransition class is the base class of transitions between QAbstractState objects. -
58 -
59 \since 4.6 -
60 \ingroup statemachine -
61 -
62 The QAbstractTransition class is the abstract base class of transitions -
63 between states (QAbstractState objects) of a -
64 QStateMachine. QAbstractTransition is part of \l{The State Machine -
65 Framework}. -
66 -
67 The sourceState() function returns the source of the transition. The -
68 targetStates() function returns the targets of the transition. The machine() -
69 function returns the state machine that the transition is part of. -
70 -
71 The triggered() signal is emitted when the transition has been triggered. -
72 -
73 Transitions can cause animations to be played. Use the addAnimation() -
74 function to add an animation to the transition. -
75 -
76 \section1 Subclassing -
77 -
78 The eventTest() function is called by the state machine to determine whether -
79 an event should trigger the transition. In your reimplementation you -
80 typically check the event type and cast the event object to the proper type, -
81 and check that one or more properties of the event meet your criteria. -
82 -
83 The onTransition() function is called when the transition is triggered; -
84 reimplement this function to perform custom processing for the transition. -
85*/ -
86 -
87/*! -
88 \property QAbstractTransition::sourceState -
89 -
90 \brief the source state (parent) of this transition -
91*/ -
92 -
93/*! -
94 \property QAbstractTransition::targetState -
95 -
96 \brief the target state of this transition -
97 -
98 If a transition has no target state, the transition may still be -
99 triggered, but this will not cause the state machine's configuration to -
100 change (i.e. the current state will not be exited and re-entered). -
101*/ -
102 -
103/*! -
104 \property QAbstractTransition::targetStates -
105 -
106 \brief the target states of this transition -
107 -
108 If multiple states are specified, all must be descendants of the same -
109 parallel group state. -
110*/ -
111 -
112QAbstractTransitionPrivate::QAbstractTransitionPrivate() -
113{ -
114} -
115 -
116QAbstractTransitionPrivate *QAbstractTransitionPrivate::get(QAbstractTransition *q) -
117{ -
118 return q->d_func();
executed: return q->d_func();
Execution Count:10839
10839
119} -
120 -
121QStateMachine *QAbstractTransitionPrivate::machine() const -
122{ -
123 QState *source = sourceState();
executed (the execution status of this line is deduced): QState *source = sourceState();
-
124 if (!source)
evaluated: !source
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:400147
76-400147
125 return 0;
executed: return 0;
Execution Count:76
76
126 return source->machine();
executed: return source->machine();
Execution Count:400152
400152
127} -
128 -
129bool QAbstractTransitionPrivate::callEventTest(QEvent *e) -
130{ -
131 Q_Q(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransition * const q = q_func();
-
132 return q->eventTest(e);
executed: return q->eventTest(e);
Execution Count:7888
7888
133} -
134 -
135void QAbstractTransitionPrivate::callOnTransition(QEvent *e) -
136{ -
137 Q_Q(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransition * const q = q_func();
-
138 q->onTransition(e);
executed (the execution status of this line is deduced): q->onTransition(e);
-
139}
executed: }
Execution Count:1307
1307
140 -
141QState *QAbstractTransitionPrivate::sourceState() const -
142{ -
143 return qobject_cast<QState*>(parent);
executed: return qobject_cast<QState*>(parent);
Execution Count:604242
604242
144} -
145 -
146void QAbstractTransitionPrivate::emitTriggered() -
147{ -
148 Q_Q(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransition * const q = q_func();
-
149 emit q->triggered(QAbstractTransition::QPrivateSignal());
executed (the execution status of this line is deduced): q->triggered(QAbstractTransition::QPrivateSignal());
-
150}
executed: }
Execution Count:1368
1368
151 -
152/*! -
153 Constructs a new QAbstractTransition object with the given \a sourceState. -
154*/ -
155QAbstractTransition::QAbstractTransition(QState *sourceState) -
156 : QObject(*new QAbstractTransitionPrivate, sourceState) -
157{ -
158}
executed: }
Execution Count:282
282
159 -
160/*! -
161 \internal -
162*/ -
163QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd, -
164 QState *parent) -
165 : QObject(dd, parent) -
166{ -
167}
executed: }
Execution Count:82
82
168 -
169/*! -
170 Destroys this transition. -
171*/ -
172QAbstractTransition::~QAbstractTransition() -
173{ -
174} -
175 -
176/*! -
177 Returns the source state of this transition, or 0 if this transition has no -
178 source state. -
179*/ -
180QState *QAbstractTransition::sourceState() const -
181{ -
182 Q_D(const QAbstractTransition);
executed (the execution status of this line is deduced): const QAbstractTransitionPrivate * const d = d_func();
-
183 return d->sourceState();
executed: return d->sourceState();
Execution Count:204011
204011
184} -
185 -
186/*! -
187 Returns the target state of this transition, or 0 if the transition has no -
188 target. -
189*/ -
190QAbstractState *QAbstractTransition::targetState() const -
191{ -
192 Q_D(const QAbstractTransition);
executed (the execution status of this line is deduced): const QAbstractTransitionPrivate * const d = d_func();
-
193 if (d->targetStates.isEmpty())
evaluated: d->targetStates.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:15
2-15
194 return 0;
executed: return 0;
Execution Count:2
2
195 return d->targetStates.first().data();
executed: return d->targetStates.first().data();
Execution Count:15
15
196} -
197 -
198/*! -
199 Sets the \a target state of this transition. -
200*/ -
201void QAbstractTransition::setTargetState(QAbstractState* target) -
202{ -
203 Q_D(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransitionPrivate * const d = d_func();
-
204 if (!target)
evaluated: !target
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:210
3-210
205 d->targetStates.clear();
executed: d->targetStates.clear();
Execution Count:3
3
206 else -
207 setTargetStates(QList<QAbstractState*>() << target);
executed: setTargetStates(QList<QAbstractState*>() << target);
Execution Count:210
210
208} -
209 -
210/*! -
211 Returns the target states of this transition, or an empty list if this -
212 transition has no target states. -
213*/ -
214QList<QAbstractState*> QAbstractTransition::targetStates() const -
215{ -
216 Q_D(const QAbstractTransition);
executed (the execution status of this line is deduced): const QAbstractTransitionPrivate * const d = d_func();
-
217 QList<QAbstractState*> result;
executed (the execution status of this line is deduced): QList<QAbstractState*> result;
-
218 for (int i = 0; i < d->targetStates.size(); ++i) {
evaluated: i < d->targetStates.size()
TRUEFALSE
yes
Evaluation Count:3970
yes
Evaluation Count:3978
3970-3978
219 QAbstractState *target = d->targetStates.at(i).data();
executed (the execution status of this line is deduced): QAbstractState *target = d->targetStates.at(i).data();
-
220 if (target)
evaluated: target
TRUEFALSE
yes
Evaluation Count:3969
yes
Evaluation Count:1
1-3969
221 result.append(target);
executed: result.append(target);
Execution Count:3969
3969
222 }
executed: }
Execution Count:3970
3970
223 return result;
executed: return result;
Execution Count:3978
3978
224} -
225 -
226/*! -
227 Sets the target states of this transition to be the given \a targets. -
228*/ -
229void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets) -
230{ -
231 Q_D(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransitionPrivate * const d = d_func();
-
232 -
233 for (int i = 0; i < targets.size(); ++i) {
evaluated: i < targets.size()
TRUEFALSE
yes
Evaluation Count:358
yes
Evaluation Count:355
355-358
234 QAbstractState *target = targets.at(i);
executed (the execution status of this line is deduced): QAbstractState *target = targets.at(i);
-
235 if (!target) {
evaluated: !target
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:357
1-357
236 qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null");
executed (the execution status of this line is deduced): QMessageLogger("statemachine/qabstracttransition.cpp", 236, __PRETTY_FUNCTION__).warning("QAbstractTransition::setTargetStates: target state(s) cannot be null");
-
237 return;
executed: return;
Execution Count:1
1
238 } -
239 }
executed: }
Execution Count:357
357
240 -
241 d->targetStates.clear();
executed (the execution status of this line is deduced): d->targetStates.clear();
-
242 for (int i = 0; i < targets.size(); ++i)
evaluated: i < targets.size()
TRUEFALSE
yes
Evaluation Count:357
yes
Evaluation Count:355
355-357
243 d->targetStates.append(targets.at(i));
executed: d->targetStates.append(targets.at(i));
Execution Count:357
357
244}
executed: }
Execution Count:355
355
245 -
246/*! -
247 Returns the state machine that this transition is part of, or 0 if the -
248 transition is not part of a state machine. -
249*/ -
250QStateMachine *QAbstractTransition::machine() const -
251{ -
252 Q_D(const QAbstractTransition);
executed (the execution status of this line is deduced): const QAbstractTransitionPrivate * const d = d_func();
-
253 return d->machine();
executed: return d->machine();
Execution Count:133
133
254} -
255 -
256#ifndef QT_NO_ANIMATION -
257 -
258/*! -
259 Adds the given \a animation to this transition. -
260 The transition does not take ownership of the animation. -
261 -
262 \sa removeAnimation(), animations() -
263*/ -
264void QAbstractTransition::addAnimation(QAbstractAnimation *animation) -
265{ -
266 Q_D(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransitionPrivate * const d = d_func();
-
267 if (!animation) {
evaluated: !animation
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:26
1-26
268 qWarning("QAbstractTransition::addAnimation: cannot add null animation");
executed (the execution status of this line is deduced): QMessageLogger("statemachine/qabstracttransition.cpp", 268, __PRETTY_FUNCTION__).warning("QAbstractTransition::addAnimation: cannot add null animation");
-
269 return;
executed: return;
Execution Count:1
1
270 } -
271 d->animations.append(animation);
executed (the execution status of this line is deduced): d->animations.append(animation);
-
272}
executed: }
Execution Count:26
26
273 -
274/*! -
275 Removes the given \a animation from this transition. -
276 -
277 \sa addAnimation() -
278*/ -
279void QAbstractTransition::removeAnimation(QAbstractAnimation *animation) -
280{ -
281 Q_D(QAbstractTransition);
executed (the execution status of this line is deduced): QAbstractTransitionPrivate * const d = d_func();
-
282 if (!animation) {
evaluated: !animation
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
283 qWarning("QAbstractTransition::removeAnimation: cannot remove null animation");
executed (the execution status of this line is deduced): QMessageLogger("statemachine/qabstracttransition.cpp", 283, __PRETTY_FUNCTION__).warning("QAbstractTransition::removeAnimation: cannot remove null animation");
-
284 return;
executed: return;
Execution Count:1
1
285 } -
286 d->animations.removeOne(animation);
executed (the execution status of this line is deduced): d->animations.removeOne(animation);
-
287}
executed: }
Execution Count:1
1
288 -
289/*! -
290 Returns the list of animations associated with this transition, or an empty -
291 list if it has no animations. -
292 -
293 \sa addAnimation() -
294*/ -
295QList<QAbstractAnimation*> QAbstractTransition::animations() const -
296{ -
297 Q_D(const QAbstractTransition);
executed (the execution status of this line is deduced): const QAbstractTransitionPrivate * const d = d_func();
-
298 return d->animations;
executed: return d->animations;
Execution Count:1374
1374
299} -
300 -
301#endif -
302 -
303/*! -
304 \fn QAbstractTransition::eventTest(QEvent *event) -
305 -
306 This function is called to determine whether the given \a event should cause -
307 this transition to trigger. Reimplement this function and return true if the -
308 event should trigger the transition, otherwise return false. -
309*/ -
310 -
311/*! -
312 \fn QAbstractTransition::onTransition(QEvent *event) -
313 -
314 This function is called when the transition is triggered. The given \a event -
315 is what caused the transition to trigger. Reimplement this function to -
316 perform custom processing when the transition is triggered. -
317*/ -
318 -
319/*! -
320 \fn QAbstractTransition::triggered() -
321 -
322 This signal is emitted when the transition has been triggered (after -
323 onTransition() has been called). -
324*/ -
325 -
326/*! -
327 \reimp -
328*/ -
329bool QAbstractTransition::event(QEvent *e) -
330{ -
331 return QObject::event(e);
executed: return QObject::event(e);
Execution Count:4
4
332} -
333 -
334QT_END_NAMESPACE -
335 -
336#endif //QT_NO_STATEMACHINE -
337 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial