qabstractstate.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qabstractstate.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 "qabstractstate.h"-
35-
36#ifndef QT_NO_STATEMACHINE-
37-
38#include "qabstractstate_p.h"-
39#include "qstate.h"-
40#include "qstate_p.h"-
41#include "qstatemachine.h"-
42#include "qstatemachine_p.h"-
43-
44QT_BEGIN_NAMESPACE-
45-
46/*!-
47 \class QAbstractState-
48 \inmodule QtCore-
49-
50 \brief The QAbstractState class is the base class of states of a QStateMachine.-
51-
52 \since 4.6-
53 \ingroup statemachine-
54-
55 The QAbstractState class is the abstract base class of states that are part-
56 of a QStateMachine. It defines the interface that all state objects have in-
57 common. QAbstractState is part of \l{The State Machine Framework}.-
58-
59 The entered() signal is emitted when the state has been entered. The-
60 exited() signal is emitted when the state has been exited.-
61-
62 The parentState() function returns the state's parent state. The machine()-
63 function returns the state machine that the state is part of.-
64-
65 \section1 Subclassing-
66-
67 The onEntry() function is called when the state is entered; reimplement this-
68 function to perform custom processing when the state is entered.-
69-
70 The onExit() function is called when the state is exited; reimplement this-
71 function to perform custom processing when the state is exited.-
72*/-
73-
74/*!-
75 \property QAbstractState::active-
76 \since 5.4-
77-
78 \brief the active property of this state. A state is active between-
79 entered() and exited() signals.-
80*/-
81-
82-
83QAbstractStatePrivate::QAbstractStatePrivate(StateType type)-
84 : stateType(type), isMachine(false), active(false), parentState(0)-
85{-
86}
executed 610 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
610
87-
88QStateMachine *QAbstractStatePrivate::machine() const-
89{-
90 QObject *par = parent;-
91 while (par != 0) {
par != 0Description
TRUEevaluated 403985 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 93 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
93-403985
92 if (QStateMachine *mach = qobject_cast<QStateMachine*>(par))
QStateMachine ...Machine*>(par)Description
TRUEevaluated 402355 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 1630 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
1630-402355
93 return mach;
executed 400811 times by 2 tests: return mach;
Executed by:
  • tst_QState
  • tst_QStateMachine
400811
94 par = par->parent();-
95 }
executed 1630 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1630
96 return 0;
executed 93 times by 2 tests: return 0;
Executed by:
  • tst_QState
  • tst_QStateMachine
93
97}-
98-
99void QAbstractStatePrivate::callOnEntry(QEvent *e)-
100{-
101 Q_Q(QAbstractState);-
102 q->onEntry(e);-
103}
executed 1507 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1507
104-
105void QAbstractStatePrivate::callOnExit(QEvent *e)-
106{-
107 Q_Q(QAbstractState);-
108 q->onExit(e);-
109}
executed 1298 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1298
110-
111void QAbstractStatePrivate::emitEntered()-
112{-
113 Q_Q(QAbstractState);-
114 emit q->entered(QAbstractState::QPrivateSignal());-
115 if (!active) {
!activeDescription
TRUEevaluated 1507 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
0-1507
116 active = true;-
117 emit q->activeChanged(true);-
118 }
executed 1507 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1507
119}
executed 1507 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1507
120-
121void QAbstractStatePrivate::emitExited()-
122{-
123 Q_Q(QAbstractState);-
124 if (active) {
activeDescription
TRUEevaluated 1298 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
0-1298
125 active = false;-
126 emit q->activeChanged(false);-
127 }
executed 1298 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1298
128 emit q->exited(QAbstractState::QPrivateSignal());-
129}
executed 1298 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
1298
130-
131/*!-
132 Constructs a new state with the given \a parent state.-
133*/-
134QAbstractState::QAbstractState(QState *parent)-
135 : QObject(*new QAbstractStatePrivate(QAbstractStatePrivate::AbstractState), parent)-
136{-
137}
never executed: end of block
0
138-
139/*!-
140 \internal-
141*/-
142QAbstractState::QAbstractState(QAbstractStatePrivate &dd, QState *parent)-
143 : QObject(dd, parent)-
144{-
145}
executed 610 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
610
146-
147/*!-
148 Destroys this state.-
149*/-
150QAbstractState::~QAbstractState()-
151{-
152}-
153-
154/*!-
155 Returns this state's parent state, or 0 if the state has no parent state.-
156*/-
157QState *QAbstractState::parentState() const-
158{-
159 Q_D(const QAbstractState);-
160 if (d->parentState != parent())
d->parentState != parent()Description
TRUEevaluated 437 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 26240 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
437-26240
161 d->parentState = qobject_cast<QState*>(parent());
executed 437 times by 2 tests: d->parentState = qobject_cast<QState*>(parent());
Executed by:
  • tst_QState
  • tst_QStateMachine
437
162 return d->parentState;
executed 26677 times by 2 tests: return d->parentState;
Executed by:
  • tst_QState
  • tst_QStateMachine
26677
163}-
164-
165/*!-
166 Returns the state machine that this state is part of, or 0 if the state is-
167 not part of a state machine.-
168*/-
169QStateMachine *QAbstractState::machine() const-
170{-
171 Q_D(const QAbstractState);-
172 return d->machine();
executed 401452 times by 2 tests: return d->machine();
Executed by:
  • tst_QState
  • tst_QStateMachine
401452
173}-
174-
175/*!-
176 Returns whether this state is active.-
177-
178 \sa activeChanged(bool), entered(), exited()-
179*/-
180bool QAbstractState::active() const-
181{-
182 Q_D(const QAbstractState);-
183 return d->active;
executed 644 times by 1 test: return d->active;
Executed by:
  • tst_QStateMachine
644
184}-
185-
186/*!-
187 \fn QAbstractState::onExit(QEvent *event)-
188-
189 This function is called when the state is exited. The given \a event is what-
190 caused the state to be exited. Reimplement this function to perform custom-
191 processing when the state is exited.-
192*/-
193-
194/*!-
195 \fn QAbstractState::onEntry(QEvent *event)-
196-
197 This function is called when the state is entered. The given \a event is-
198 what caused the state to be entered. Reimplement this function to perform-
199 custom processing when the state is entered.-
200*/-
201-
202/*!-
203 \fn QAbstractState::entered()-
204-
205 This signal is emitted when the state has been entered (after onEntry() has-
206 been called).-
207*/-
208-
209/*!-
210 \fn QAbstractState::exited()-
211-
212 This signal is emitted when the state has been exited (after onExit() has-
213 been called).-
214*/-
215-
216/*!-
217 \fn QAbstractState::activeChanged(bool active)-
218 \since 5.4-
219-
220 This signal is emitted when the active property is changed with \a active as argument.-
221-
222 \sa QAbstractState::active, entered(), exited()-
223*/-
224-
225/*!-
226 \reimp-
227*/-
228bool QAbstractState::event(QEvent *e)-
229{-
230 return QObject::event(e);
executed 1166 times by 2 tests: return QObject::event(e);
Executed by:
  • tst_QState
  • tst_QStateMachine
1166
231}-
232-
233QT_END_NAMESPACE-
234-
235#endif //QT_NO_STATEMACHINE-
Source codeSwitch to Preprocessed file

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