OpenCoverage

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

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