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

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