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 | #include "qstate.h" | - |
43 | | - |
44 | #ifndef QT_NO_STATEMACHINE | - |
45 | | - |
46 | #include "qstate_p.h" | - |
47 | #include "qhistorystate.h" | - |
48 | #include "qhistorystate_p.h" | - |
49 | #include "qabstracttransition.h" | - |
50 | #include "qabstracttransition_p.h" | - |
51 | #include "qsignaltransition.h" | - |
52 | #include "qstatemachine.h" | - |
53 | #include "qstatemachine_p.h" | - |
54 | | - |
55 | QT_BEGIN_NAMESPACE | - |
56 | | - |
57 | /*! | - |
58 | \class QState | - |
59 | \inmodule QtCore | - |
60 | | - |
61 | \brief The QState class provides a general-purpose state for QStateMachine. | - |
62 | | - |
63 | \since 4.6 | - |
64 | \ingroup statemachine | - |
65 | | - |
66 | QState objects can have child states, and can have transitions to other | - |
67 | states. QState is part of \l{The State Machine Framework}. | - |
68 | | - |
69 | The addTransition() function adds a transition. The removeTransition() | - |
70 | function removes a transition. The transitions() function returns the | - |
71 | state's outgoing transitions. | - |
72 | | - |
73 | The assignProperty() function is used for defining property assignments that | - |
74 | should be performed when a state is entered. | - |
75 | | - |
76 | Top-level states must be passed a QStateMachine object as their parent | - |
77 | state, or added to a state machine using QStateMachine::addState(). | - |
78 | | - |
79 | \section1 States with Child States | - |
80 | | - |
81 | The childMode property determines how child states are treated. For | - |
82 | non-parallel state groups, the setInitialState() function must be called to | - |
83 | set the initial state. The child states are mutually exclusive states, and | - |
84 | the state machine needs to know which child state to enter when the parent | - |
85 | state is the target of a transition. | - |
86 | | - |
87 | The state emits the QState::finished() signal when a final child state | - |
88 | (QFinalState) is entered. | - |
89 | | - |
90 | The setErrorState() sets the state's error state. The error state is the | - |
91 | state that the state machine will transition to if an error is detected when | - |
92 | attempting to enter the state (e.g. because no initial state has been set). | - |
93 | | - |
94 | */ | - |
95 | | - |
96 | /*! | - |
97 | \property QState::initialState | - |
98 | | - |
99 | \brief the initial state of this state (one of its child states) | - |
100 | */ | - |
101 | | - |
102 | /*! | - |
103 | \property QState::errorState | - |
104 | | - |
105 | \brief the error state of this state | - |
106 | */ | - |
107 | | - |
108 | /*! | - |
109 | \property QState::childMode | - |
110 | | - |
111 | \brief the child mode of this state | - |
112 | | - |
113 | The default value of this property is QState::ExclusiveStates. | - |
114 | */ | - |
115 | | - |
116 | /*! | - |
117 | \enum QState::ChildMode | - |
118 | | - |
119 | This enum specifies how a state's child states are treated. | - |
120 | | - |
121 | \value ExclusiveStates The child states are mutually exclusive and an | - |
122 | initial state must be set by calling QState::setInitialState(). | - |
123 | | - |
124 | \value ParallelStates The child states are parallel. When the parent state | - |
125 | is entered, all its child states are entered in parallel. | - |
126 | */ | - |
127 | | - |
128 | /*! | - |
129 | \enum QState::RestorePolicy | - |
130 | | - |
131 | This enum specifies the restore policy type. The restore policy | - |
132 | takes effect when the machine enters a state which sets one or more | - |
133 | properties. If the restore policy is set to RestoreProperties, | - |
134 | the state machine will save the original value of the property before the | - |
135 | new value is set. | - |
136 | | - |
137 | Later, when the machine either enters a state which does not set | - |
138 | a value for the given property, the property will automatically be restored | - |
139 | to its initial value. | - |
140 | | - |
141 | Only one initial value will be saved for any given property. If a value for a property has | - |
142 | already been saved by the state machine, it will not be overwritten until the property has been | - |
143 | successfully restored. | - |
144 | | - |
145 | \value DontRestoreProperties The state machine should not save the initial values of properties | - |
146 | and restore them later. | - |
147 | \value RestoreProperties The state machine should save the initial values of properties | - |
148 | and restore them later. | - |
149 | | - |
150 | \sa QStateMachine::globalRestorePolicy, QState::assignProperty() | - |
151 | */ | - |
152 | | - |
153 | QStatePrivate::QStatePrivate() | - |
154 | : QAbstractStatePrivate(StandardState), | - |
155 | errorState(0), initialState(0), childMode(QState::ExclusiveStates), | - |
156 | childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) | - |
157 | { | - |
158 | } executed: } Execution Count:473 | 473 |
159 | | - |
160 | QStatePrivate::~QStatePrivate() | - |
161 | { | - |
162 | } | - |
163 | | - |
164 | void QStatePrivate::emitFinished() | - |
165 | { | - |
166 | Q_Q(QState); executed (the execution status of this line is deduced): QState * const q = q_func(); | - |
167 | emit q->finished(QState::QPrivateSignal()); executed (the execution status of this line is deduced): q->finished(QState::QPrivateSignal()); | - |
168 | } executed: } Execution Count:72 | 72 |
169 | | - |
170 | void QStatePrivate::emitPropertiesAssigned() | - |
171 | { | - |
172 | Q_Q(QState); executed (the execution status of this line is deduced): QState * const q = q_func(); | - |
173 | emit q->propertiesAssigned(QState::QPrivateSignal()); executed (the execution status of this line is deduced): q->propertiesAssigned(QState::QPrivateSignal()); | - |
174 | } executed: } Execution Count:1352 | 1352 |
175 | | - |
176 | /*! | - |
177 | Constructs a new state with the given \a parent state. | - |
178 | */ | - |
179 | QState::QState(QState *parent) | - |
180 | : QAbstractState(*new QStatePrivate, parent) | - |
181 | { | - |
182 | } executed: } Execution Count:334 | 334 |
183 | | - |
184 | /*! | - |
185 | Constructs a new state with the given \a childMode and the given \a parent | - |
186 | state. | - |
187 | */ | - |
188 | QState::QState(ChildMode childMode, QState *parent) | - |
189 | : QAbstractState(*new QStatePrivate, parent) | - |
190 | { | - |
191 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
192 | d->childMode = childMode; executed (the execution status of this line is deduced): d->childMode = childMode; | - |
193 | } executed: } Execution Count:5 | 5 |
194 | | - |
195 | /*! | - |
196 | \internal | - |
197 | */ | - |
198 | QState::QState(QStatePrivate &dd, QState *parent) | - |
199 | : QAbstractState(dd, parent) | - |
200 | { | - |
201 | } executed: } Execution Count:134 | 134 |
202 | | - |
203 | /*! | - |
204 | Destroys this state. | - |
205 | */ | - |
206 | QState::~QState() | - |
207 | { | - |
208 | } | - |
209 | | - |
210 | QList<QAbstractState*> QStatePrivate::childStates() const | - |
211 | { | - |
212 | if (childStatesListNeedsRefresh) { evaluated: childStatesListNeedsRefresh yes Evaluation Count:327 | yes Evaluation Count:6162 |
| 327-6162 |
213 | childStatesList.clear(); executed (the execution status of this line is deduced): childStatesList.clear(); | - |
214 | QList<QObject*>::const_iterator it; executed (the execution status of this line is deduced): QList<QObject*>::const_iterator it; | - |
215 | for (it = children.constBegin(); it != children.constEnd(); ++it) { evaluated: it != children.constEnd() yes Evaluation Count:349 | yes Evaluation Count:327 |
| 327-349 |
216 | QAbstractState *s = qobject_cast<QAbstractState*>(*it); executed (the execution status of this line is deduced): QAbstractState *s = qobject_cast<QAbstractState*>(*it); | - |
217 | if (!s || qobject_cast<QHistoryState*>(s)) evaluated: !s yes Evaluation Count:231 | yes Evaluation Count:118 |
evaluated: qobject_cast<QHistoryState*>(s) yes Evaluation Count:5 | yes Evaluation Count:113 |
| 5-231 |
218 | continue; executed: continue; Execution Count:236 | 236 |
219 | childStatesList.append(s); executed (the execution status of this line is deduced): childStatesList.append(s); | - |
220 | } executed: } Execution Count:113 | 113 |
221 | childStatesListNeedsRefresh = false; executed (the execution status of this line is deduced): childStatesListNeedsRefresh = false; | - |
222 | } executed: } Execution Count:327 | 327 |
223 | return childStatesList; executed: return childStatesList; Execution Count:6489 | 6489 |
224 | } | - |
225 | | - |
226 | QList<QHistoryState*> QStatePrivate::historyStates() const | - |
227 | { | - |
228 | QList<QHistoryState*> result; executed (the execution status of this line is deduced): QList<QHistoryState*> result; | - |
229 | QList<QObject*>::const_iterator it; executed (the execution status of this line is deduced): QList<QObject*>::const_iterator it; | - |
230 | for (it = children.constBegin(); it != children.constEnd(); ++it) { evaluated: it != children.constEnd() yes Evaluation Count:2405 | yes Evaluation Count:1265 |
| 1265-2405 |
231 | QHistoryState *h = qobject_cast<QHistoryState*>(*it); executed (the execution status of this line is deduced): QHistoryState *h = qobject_cast<QHistoryState*>(*it); | - |
232 | if (h) evaluated: h yes Evaluation Count:8 | yes Evaluation Count:2397 |
| 8-2397 |
233 | result.append(h); executed: result.append(h); Execution Count:8 | 8 |
234 | } executed: } Execution Count:2405 | 2405 |
235 | return result; executed: return result; Execution Count:1265 | 1265 |
236 | } | - |
237 | | - |
238 | QList<QAbstractTransition*> QStatePrivate::transitions() const | - |
239 | { | - |
240 | if (transitionsListNeedsRefresh) { evaluated: transitionsListNeedsRefresh yes Evaluation Count:451 | yes Evaluation Count:9447 |
| 451-9447 |
241 | transitionsList.clear(); executed (the execution status of this line is deduced): transitionsList.clear(); | - |
242 | QList<QObject*>::const_iterator it; executed (the execution status of this line is deduced): QList<QObject*>::const_iterator it; | - |
243 | for (it = children.constBegin(); it != children.constEnd(); ++it) { evaluated: it != children.constEnd() yes Evaluation Count:730 | yes Evaluation Count:451 |
| 451-730 |
244 | QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); executed (the execution status of this line is deduced): QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); | - |
245 | if (t) evaluated: t yes Evaluation Count:222 | yes Evaluation Count:508 |
| 222-508 |
246 | transitionsList.append(t); executed: transitionsList.append(t); Execution Count:222 | 222 |
247 | } executed: } Execution Count:730 | 730 |
248 | transitionsListNeedsRefresh = false; executed (the execution status of this line is deduced): transitionsListNeedsRefresh = false; | - |
249 | } executed: } Execution Count:451 | 451 |
250 | return transitionsList; executed: return transitionsList; Execution Count:9898 | 9898 |
251 | } | - |
252 | | - |
253 | #ifndef QT_NO_PROPERTIES | - |
254 | | - |
255 | /*! | - |
256 | Instructs this state to set the property with the given \a name of the given | - |
257 | \a object to the given \a value when the state is entered. | - |
258 | | - |
259 | \sa propertiesAssigned() | - |
260 | */ | - |
261 | void QState::assignProperty(QObject *object, const char *name, | - |
262 | const QVariant &value) | - |
263 | { | - |
264 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
265 | if (!object) { evaluated: !object yes Evaluation Count:1 | yes Evaluation Count:103 |
| 1-103 |
266 | qWarning("QState::assignProperty: cannot assign property '%s' of null object", name); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 266, __PRETTY_FUNCTION__).warning("QState::assignProperty: cannot assign property '%s' of null object", name); | - |
267 | return; executed: return; Execution Count:1 | 1 |
268 | } | - |
269 | for (int i = 0; i < d->propertyAssignments.size(); ++i) { evaluated: i < d->propertyAssignments.size() yes Evaluation Count:15 | yes Evaluation Count:101 |
| 15-101 |
270 | QPropertyAssignment &assn = d->propertyAssignments[i]; executed (the execution status of this line is deduced): QPropertyAssignment &assn = d->propertyAssignments[i]; | - |
271 | if (assn.hasTarget(object, name)) { evaluated: assn.hasTarget(object, name) yes Evaluation Count:2 | yes Evaluation Count:13 |
| 2-13 |
272 | assn.value = value; executed (the execution status of this line is deduced): assn.value = value; | - |
273 | return; executed: return; Execution Count:2 | 2 |
274 | } | - |
275 | } executed: } Execution Count:13 | 13 |
276 | d->propertyAssignments.append(QPropertyAssignment(object, name, value)); executed (the execution status of this line is deduced): d->propertyAssignments.append(QPropertyAssignment(object, name, value)); | - |
277 | } executed: } Execution Count:101 | 101 |
278 | | - |
279 | #endif // QT_NO_PROPERTIES | - |
280 | | - |
281 | /*! | - |
282 | Returns this state's error state. | - |
283 | | - |
284 | \sa QStateMachine::error() | - |
285 | */ | - |
286 | QAbstractState *QState::errorState() const | - |
287 | { | - |
288 | Q_D(const QState); executed (the execution status of this line is deduced): const QStatePrivate * const d = d_func(); | - |
289 | return d->errorState; executed: return d->errorState; Execution Count:44 | 44 |
290 | } | - |
291 | | - |
292 | /*! | - |
293 | Sets this state's error state to be the given \a state. If the error state | - |
294 | is not set, or if it is set to 0, the state will inherit its parent's error | - |
295 | state recursively. If no error state is set for the state itself or any of | - |
296 | its ancestors, an error will cause the machine to stop executing and an error | - |
297 | will be printed to the console. | - |
298 | */ | - |
299 | void QState::setErrorState(QAbstractState *state) | - |
300 | { | - |
301 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
302 | if (state != 0 && qobject_cast<QStateMachine*>(state)) { evaluated: state != 0 yes Evaluation Count:14 | yes Evaluation Count:1 |
evaluated: qobject_cast<QStateMachine*>(state) yes Evaluation Count:1 | yes Evaluation Count:13 |
| 1-14 |
303 | qWarning("QStateMachine::setErrorState: root state cannot be error state"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 303, __PRETTY_FUNCTION__).warning("QStateMachine::setErrorState: root state cannot be error state"); | - |
304 | return; executed: return; Execution Count:1 | 1 |
305 | } | - |
306 | if (state != 0 && (!state->machine() || ((state->machine() != machine()) && !qobject_cast<QStateMachine*>(this)))) { evaluated: state != 0 yes Evaluation Count:13 | yes Evaluation Count:1 |
evaluated: !state->machine() yes Evaluation Count:1 | yes Evaluation Count:12 |
evaluated: (state->machine() != machine()) yes Evaluation Count:8 | yes Evaluation Count:4 |
evaluated: !qobject_cast<QStateMachine*>(this) yes Evaluation Count:1 | yes Evaluation Count:7 |
| 1-13 |
307 | qWarning("QState::setErrorState: error state cannot belong " executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 307, __PRETTY_FUNCTION__).warning("QState::setErrorState: error state cannot belong " | - |
308 | "to a different state machine"); executed (the execution status of this line is deduced): "to a different state machine"); | - |
309 | return; executed: return; Execution Count:2 | 2 |
310 | } | - |
311 | | - |
312 | d->errorState = state; executed (the execution status of this line is deduced): d->errorState = state; | - |
313 | } executed: } Execution Count:12 | 12 |
314 | | - |
315 | /*! | - |
316 | Adds the given \a transition. The transition has this state as the source. | - |
317 | This state takes ownership of the transition. | - |
318 | */ | - |
319 | void QState::addTransition(QAbstractTransition *transition) | - |
320 | { | - |
321 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
322 | if (!transition) { evaluated: !transition yes Evaluation Count:1 | yes Evaluation Count:215 |
| 1-215 |
323 | qWarning("QState::addTransition: cannot add null transition"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 323, __PRETTY_FUNCTION__).warning("QState::addTransition: cannot add null transition"); | - |
324 | return ; executed: return ; Execution Count:1 | 1 |
325 | } | - |
326 | | - |
327 | transition->setParent(this); executed (the execution status of this line is deduced): transition->setParent(this); | - |
328 | const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; executed (the execution status of this line is deduced): const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; | - |
329 | for (int i = 0; i < targets.size(); ++i) { evaluated: i < targets.size() yes Evaluation Count:208 | yes Evaluation Count:215 |
| 208-215 |
330 | QAbstractState *t = targets.at(i).data(); executed (the execution status of this line is deduced): QAbstractState *t = targets.at(i).data(); | - |
331 | if (!t) { partially evaluated: !t no Evaluation Count:0 | yes Evaluation Count:208 |
| 0-208 |
332 | qWarning("QState::addTransition: cannot add transition to null state"); never executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 332, __PRETTY_FUNCTION__).warning("QState::addTransition: cannot add transition to null state"); | - |
333 | return ; | 0 |
334 | } | - |
335 | if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) evaluated: (QAbstractStatePrivate::get(t)->machine() != d->machine()) yes Evaluation Count:4 | yes Evaluation Count:204 |
| 4-204 |
336 | && QAbstractStatePrivate::get(t)->machine() && d->machine()) { evaluated: QAbstractStatePrivate::get(t)->machine() yes Evaluation Count:1 | yes Evaluation Count:3 |
partially evaluated: d->machine() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-3 |
337 | qWarning("QState::addTransition: cannot add transition " never executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 337, __PRETTY_FUNCTION__).warning("QState::addTransition: cannot add transition " | - |
338 | "to a state in a different state machine"); never executed (the execution status of this line is deduced): "to a state in a different state machine"); | - |
339 | return ; | 0 |
340 | } | - |
341 | } executed: } Execution Count:208 | 208 |
342 | if (QStateMachine *mach = machine()) evaluated: QStateMachine *mach = machine() yes Evaluation Count:207 | yes Evaluation Count:8 |
| 8-207 |
343 | QStateMachinePrivate::get(mach)->maybeRegisterTransition(transition); executed: QStateMachinePrivate::get(mach)->maybeRegisterTransition(transition); Execution Count:207 | 207 |
344 | } executed: } Execution Count:215 | 215 |
345 | | - |
346 | /*! | - |
347 | Adds a transition associated with the given \a signal of the given \a sender | - |
348 | object, and returns the new QSignalTransition object. The transition has | - |
349 | this state as the source, and the given \a target as the target state. | - |
350 | */ | - |
351 | QSignalTransition *QState::addTransition(const QObject *sender, const char *signal, | - |
352 | QAbstractState *target) | - |
353 | { | - |
354 | if (!sender) { evaluated: !sender yes Evaluation Count:1 | yes Evaluation Count:51 |
| 1-51 |
355 | qWarning("QState::addTransition: sender cannot be null"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 355, __PRETTY_FUNCTION__).warning("QState::addTransition: sender cannot be null"); | - |
356 | return 0; executed: return 0; Execution Count:1 | 1 |
357 | } | - |
358 | if (!signal) { evaluated: !signal yes Evaluation Count:1 | yes Evaluation Count:50 |
| 1-50 |
359 | qWarning("QState::addTransition: signal cannot be null"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 359, __PRETTY_FUNCTION__).warning("QState::addTransition: signal cannot be null"); | - |
360 | return 0; executed: return 0; Execution Count:1 | 1 |
361 | } | - |
362 | if (!target) { evaluated: !target yes Evaluation Count:1 | yes Evaluation Count:49 |
| 1-49 |
363 | qWarning("QState::addTransition: cannot add transition to null state"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 363, __PRETTY_FUNCTION__).warning("QState::addTransition: cannot add transition to null state"); | - |
364 | return 0; executed: return 0; Execution Count:1 | 1 |
365 | } | - |
366 | int offset = (*signal == '0'+QSIGNAL_CODE) ? 1 : 0; evaluated: (*signal == '0'+2) yes Evaluation Count:48 | yes Evaluation Count:1 |
| 1-48 |
367 | const QMetaObject *meta = sender->metaObject(); executed (the execution status of this line is deduced): const QMetaObject *meta = sender->metaObject(); | - |
368 | if (meta->indexOfSignal(signal+offset) == -1) { evaluated: meta->indexOfSignal(signal+offset) == -1 yes Evaluation Count:1 | yes Evaluation Count:48 |
| 1-48 |
369 | if (meta->indexOfSignal(QMetaObject::normalizedSignature(signal+offset)) == -1) { partially evaluated: meta->indexOfSignal(QMetaObject::normalizedSignature(signal+offset)) == -1 yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
370 | qWarning("QState::addTransition: no such signal %s::%s", executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 370, __PRETTY_FUNCTION__).warning("QState::addTransition: no such signal %s::%s", | - |
371 | meta->className(), signal+offset); executed (the execution status of this line is deduced): meta->className(), signal+offset); | - |
372 | return 0; executed: return 0; Execution Count:1 | 1 |
373 | } | - |
374 | } | 0 |
375 | QSignalTransition *trans = new QSignalTransition(sender, signal); executed (the execution status of this line is deduced): QSignalTransition *trans = new QSignalTransition(sender, signal); | - |
376 | trans->setTargetState(target); executed (the execution status of this line is deduced): trans->setTargetState(target); | - |
377 | addTransition(trans); executed (the execution status of this line is deduced): addTransition(trans); | - |
378 | return trans; executed: return trans; Execution Count:48 | 48 |
379 | } | - |
380 | | - |
381 | namespace { | - |
382 | | - |
383 | // ### Make public? | - |
384 | class UnconditionalTransition : public QAbstractTransition | - |
385 | { | - |
386 | public: | - |
387 | UnconditionalTransition(QAbstractState *target) | - |
388 | : QAbstractTransition() | - |
389 | { setTargetState(target); } executed: } Execution Count:15 | 15 |
390 | protected: | - |
391 | void onTransition(QEvent *) {} | - |
392 | bool eventTest(QEvent *) { return true; } executed: return true; Execution Count:18 | 18 |
393 | }; | - |
394 | | - |
395 | } // namespace | - |
396 | | - |
397 | /*! | - |
398 | Adds an unconditional transition from this state to the given \a target | - |
399 | state, and returns then new transition object. | - |
400 | */ | - |
401 | QAbstractTransition *QState::addTransition(QAbstractState *target) | - |
402 | { | - |
403 | if (!target) { evaluated: !target yes Evaluation Count:1 | yes Evaluation Count:15 |
| 1-15 |
404 | qWarning("QState::addTransition: cannot add transition to null state"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 404, __PRETTY_FUNCTION__).warning("QState::addTransition: cannot add transition to null state"); | - |
405 | return 0; executed: return 0; Execution Count:1 | 1 |
406 | } | - |
407 | UnconditionalTransition *trans = new UnconditionalTransition(target); executed (the execution status of this line is deduced): UnconditionalTransition *trans = new UnconditionalTransition(target); | - |
408 | addTransition(trans); executed (the execution status of this line is deduced): addTransition(trans); | - |
409 | return trans; executed: return trans; Execution Count:15 | 15 |
410 | } | - |
411 | | - |
412 | /*! | - |
413 | Removes the given \a transition from this state. The state releases | - |
414 | ownership of the transition. | - |
415 | | - |
416 | \sa addTransition() | - |
417 | */ | - |
418 | void QState::removeTransition(QAbstractTransition *transition) | - |
419 | { | - |
420 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
421 | if (!transition) { evaluated: !transition yes Evaluation Count:1 | yes Evaluation Count:7 |
| 1-7 |
422 | qWarning("QState::removeTransition: cannot remove null transition"); executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 422, __PRETTY_FUNCTION__).warning("QState::removeTransition: cannot remove null transition"); | - |
423 | return; executed: return; Execution Count:1 | 1 |
424 | } | - |
425 | if (transition->sourceState() != this) { evaluated: transition->sourceState() != this yes Evaluation Count:1 | yes Evaluation Count:6 |
| 1-6 |
426 | qWarning("QState::removeTransition: transition %p's source state (%p)" executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 426, __PRETTY_FUNCTION__).warning("QState::removeTransition: transition %p's source state (%p)" | - |
427 | " is different from this state (%p)", executed (the execution status of this line is deduced): " is different from this state (%p)", | - |
428 | transition, transition->sourceState(), this); executed (the execution status of this line is deduced): transition, transition->sourceState(), this); | - |
429 | return; executed: return; Execution Count:1 | 1 |
430 | } | - |
431 | QStateMachinePrivate *mach = QStateMachinePrivate::get(d->machine()); executed (the execution status of this line is deduced): QStateMachinePrivate *mach = QStateMachinePrivate::get(d->machine()); | - |
432 | if (mach) evaluated: mach yes Evaluation Count:5 | yes Evaluation Count:1 |
| 1-5 |
433 | mach->unregisterTransition(transition); executed: mach->unregisterTransition(transition); Execution Count:5 | 5 |
434 | transition->setParent(0); executed (the execution status of this line is deduced): transition->setParent(0); | - |
435 | } executed: } Execution Count:6 | 6 |
436 | | - |
437 | /*! | - |
438 | \since 4.7 | - |
439 | | - |
440 | Returns this state's outgoing transitions (i.e. transitions where | - |
441 | this state is the \l{QAbstractTransition::sourceState()}{source | - |
442 | state}), or an empty list if this state has no outgoing transitions. | - |
443 | | - |
444 | \sa addTransition() | - |
445 | */ | - |
446 | QList<QAbstractTransition*> QState::transitions() const | - |
447 | { | - |
448 | Q_D(const QState); executed (the execution status of this line is deduced): const QStatePrivate * const d = d_func(); | - |
449 | return d->transitions(); executed: return d->transitions(); Execution Count:13 | 13 |
450 | } | - |
451 | | - |
452 | /*! | - |
453 | \reimp | - |
454 | */ | - |
455 | void QState::onEntry(QEvent *event) | - |
456 | { | - |
457 | Q_UNUSED(event); executed (the execution status of this line is deduced): (void)event;; | - |
458 | } executed: } Execution Count:349 | 349 |
459 | | - |
460 | /*! | - |
461 | \reimp | - |
462 | */ | - |
463 | void QState::onExit(QEvent *event) | - |
464 | { | - |
465 | Q_UNUSED(event); executed (the execution status of this line is deduced): (void)event;; | - |
466 | } executed: } Execution Count:251 | 251 |
467 | | - |
468 | /*! | - |
469 | Returns this state's initial state, or 0 if the state has no initial state. | - |
470 | */ | - |
471 | QAbstractState *QState::initialState() const | - |
472 | { | - |
473 | Q_D(const QState); executed (the execution status of this line is deduced): const QStatePrivate * const d = d_func(); | - |
474 | return d->initialState; executed: return d->initialState; Execution Count:345 | 345 |
475 | } | - |
476 | | - |
477 | /*! | - |
478 | Sets this state's initial state to be the given \a state. | - |
479 | \a state has to be a child of this state. | - |
480 | */ | - |
481 | void QState::setInitialState(QAbstractState *state) | - |
482 | { | - |
483 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
484 | if (d->childMode == QState::ParallelStates) { evaluated: d->childMode == QState::ParallelStates yes Evaluation Count:1 | yes Evaluation Count:161 |
| 1-161 |
485 | qWarning("QState::setInitialState: ignoring attempt to set initial state " executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 485, __PRETTY_FUNCTION__).warning("QState::setInitialState: ignoring attempt to set initial state " | - |
486 | "of parallel state group %p", this); executed (the execution status of this line is deduced): "of parallel state group %p", this); | - |
487 | return; executed: return; Execution Count:1 | 1 |
488 | } | - |
489 | if (state && (state->parentState() != this)) { partially evaluated: state yes Evaluation Count:161 | no Evaluation Count:0 |
evaluated: (state->parentState() != this) yes Evaluation Count:1 | yes Evaluation Count:160 |
| 0-161 |
490 | qWarning("QState::setInitialState: state %p is not a child of this state (%p)", executed (the execution status of this line is deduced): QMessageLogger("statemachine/qstate.cpp", 490, __PRETTY_FUNCTION__).warning("QState::setInitialState: state %p is not a child of this state (%p)", | - |
491 | state, this); executed (the execution status of this line is deduced): state, this); | - |
492 | return; executed: return; Execution Count:1 | 1 |
493 | } | - |
494 | d->initialState = state; executed (the execution status of this line is deduced): d->initialState = state; | - |
495 | } executed: } Execution Count:160 | 160 |
496 | | - |
497 | /*! | - |
498 | Returns the child mode of this state. | - |
499 | */ | - |
500 | QState::ChildMode QState::childMode() const | - |
501 | { | - |
502 | Q_D(const QState); executed (the execution status of this line is deduced): const QStatePrivate * const d = d_func(); | - |
503 | return d->childMode; executed: return d->childMode; Execution Count:365 | 365 |
504 | } | - |
505 | | - |
506 | /*! | - |
507 | Sets the child \a mode of this state. | - |
508 | */ | - |
509 | void QState::setChildMode(ChildMode mode) | - |
510 | { | - |
511 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
512 | d->childMode = mode; executed (the execution status of this line is deduced): d->childMode = mode; | - |
513 | } executed: } Execution Count:5 | 5 |
514 | | - |
515 | /*! | - |
516 | \reimp | - |
517 | */ | - |
518 | bool QState::event(QEvent *e) | - |
519 | { | - |
520 | Q_D(QState); executed (the execution status of this line is deduced): QStatePrivate * const d = d_func(); | - |
521 | if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) { evaluated: (e->type() == QEvent::ChildAdded) yes Evaluation Count:703 | yes Evaluation Count:295 |
evaluated: (e->type() == QEvent::ChildRemoved) yes Evaluation Count:13 | yes Evaluation Count:282 |
| 13-703 |
522 | d->childStatesListNeedsRefresh = true; executed (the execution status of this line is deduced): d->childStatesListNeedsRefresh = true; | - |
523 | d->transitionsListNeedsRefresh = true; executed (the execution status of this line is deduced): d->transitionsListNeedsRefresh = true; | - |
524 | if ((e->type() == QEvent::ChildRemoved) && (static_cast<QChildEvent *>(e)->child() == d->initialState)) evaluated: (e->type() == QEvent::ChildRemoved) yes Evaluation Count:13 | yes Evaluation Count:703 |
evaluated: (static_cast<QChildEvent *>(e)->child() == d->initialState) yes Evaluation Count:1 | yes Evaluation Count:12 |
| 1-703 |
525 | d->initialState = 0; executed: d->initialState = 0; Execution Count:1 | 1 |
526 | } executed: } Execution Count:716 | 716 |
527 | return QAbstractState::event(e); executed: return QAbstractState::event(e); Execution Count:998 | 998 |
528 | } | - |
529 | | - |
530 | /*! | - |
531 | \fn QState::finished() | - |
532 | | - |
533 | This signal is emitted when a final child state of this state is entered. | - |
534 | | - |
535 | \sa QFinalState | - |
536 | */ | - |
537 | | - |
538 | /*! | - |
539 | \fn QState::propertiesAssigned() | - |
540 | | - |
541 | This signal is emitted when all properties have been assigned their final value. If the state | - |
542 | assigns a value to one or more properties for which an animation exists (either set on the | - |
543 | transition or as a default animation on the state machine), then the signal will not be emitted | - |
544 | until all such animations have finished playing. | - |
545 | | - |
546 | If there are no relevant animations, or no property assignments defined for the state, then | - |
547 | the signal will be emitted immediately before the state is entered. | - |
548 | | - |
549 | \sa QState::assignProperty(), QAbstractTransition::addAnimation() | - |
550 | */ | - |
551 | | - |
552 | QT_END_NAMESPACE | - |
553 | | - |
554 | #endif //QT_NO_STATEMACHINE | - |
555 | | - |
| | |