qstate.cpp

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

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