OpenCoverage

qhistorystate.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qhistorystate.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 "qhistorystate.h"-
41-
42#ifndef QT_NO_STATEMACHINE-
43-
44#include "qhistorystate_p.h"-
45-
46QT_BEGIN_NAMESPACE-
47-
48/*!-
49 \class QHistoryState-
50 \inmodule QtCore-
51-
52 \brief The QHistoryState class provides a means of returning to a previously active substate.-
53-
54 \since 4.6-
55 \ingroup statemachine-
56-
57 A history state is a pseudo-state that represents the child state that the-
58 parent state was in the last time the parent state was exited. A transition-
59 with a history state as its target is in fact a transition to one or more-
60 other child states of the parent state. QHistoryState is part of \l{The-
61 State Machine Framework}.-
62-
63 Use the setDefaultState() function to set the state that should be entered-
64 if the parent state has never been entered. Example:-
65-
66 \code-
67 QStateMachine machine;-
68-
69 QState *s1 = new QState();-
70 QState *s11 = new QState(s1);-
71 QState *s12 = new QState(s1);-
72-
73 QHistoryState *s1h = new QHistoryState(s1);-
74 s1h->setDefaultState(s11);-
75-
76 machine.addState(s1);-
77-
78 QState *s2 = new QState();-
79 machine.addState(s2);-
80-
81 QPushButton *button = new QPushButton();-
82 // Clicking the button will cause the state machine to enter the child state-
83 // that s1 was in the last time s1 was exited, or the history state's default-
84 // state if s1 has never been entered.-
85 s1->addTransition(button, SIGNAL(clicked()), s1h);-
86 \endcode-
87-
88 If more than one default state has to be entered, or if the transition to the default state(s)-
89 has to be acted upon, the defaultTransition should be set instead. Note that the eventTest()-
90 method of that transition will never be called: the selection and execution of the transition is-
91 done automatically when entering the history state.-
92-
93 By default a history state is shallow, meaning that it won't remember nested-
94 states. This can be configured through the historyType property.-
95*/-
96-
97/*!-
98 \property QHistoryState::defaultTransition-
99-
100 \brief the default transition of this history state-
101*/-
102-
103/*!-
104 \property QHistoryState::defaultState-
105-
106 \brief the default state of this history state-
107*/-
108-
109/*!-
110 \property QHistoryState::historyType-
111-
112 \brief the type of history that this history state records-
113-
114 The default value of this property is QHistoryState::ShallowHistory.-
115*/-
116-
117/*!-
118 \enum QHistoryState::HistoryType-
119-
120 This enum specifies the type of history that a QHistoryState records.-
121-
122 \value ShallowHistory Only the immediate child states of the parent state-
123 are recorded. In this case a transition with the history state as its-
124 target will end up in the immediate child state that the parent was in the-
125 last time it was exited. This is the default.-
126-
127 \value DeepHistory Nested states are recorded. In this case a transition-
128 with the history state as its target will end up in the most deeply nested-
129 descendant state the parent was in the last time it was exited.-
130*/-
131-
132QHistoryStatePrivate::QHistoryStatePrivate()-
133 : QAbstractStatePrivate(HistoryState)-
134 , defaultTransition(0)-
135 , historyType(QHistoryState::ShallowHistory)-
136{-
137}
executed 9 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
9
138-
139DefaultStateTransition::DefaultStateTransition(QHistoryState *source, QAbstractState *target)-
140 : QAbstractTransition()-
141{-
142 setParent(source);-
143 setTargetState(target);-
144}
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
7
145-
146/*!-
147 Constructs a new shallow history state with the given \a parent state.-
148*/-
149QHistoryState::QHistoryState(QState *parent)-
150 : QAbstractState(*new QHistoryStatePrivate, parent)-
151{-
152}
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
7
153/*!-
154 Constructs a new history state of the given \a type, with the given \a-
155 parent state.-
156*/-
157QHistoryState::QHistoryState(HistoryType type, QState *parent)-
158 : QAbstractState(*new QHistoryStatePrivate, parent)-
159{-
160 Q_D(QHistoryState);-
161 d->historyType = type;-
162}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
2
163-
164/*!-
165 Destroys this history state.-
166*/-
167QHistoryState::~QHistoryState()-
168{-
169}-
170-
171/*!-
172 Returns this history state's default transition. The default transition is-
173 taken when the history state has never been entered before. The target states-
174 of the default transition therefore make up the default state.-
175-
176 \since 5.6-
177*/-
178QAbstractTransition *QHistoryState::defaultTransition() const-
179{-
180 Q_D(const QHistoryState);-
181 return d->defaultTransition;
executed 4 times by 1 test: return d->defaultTransition;
Executed by:
  • tst_QStateMachine
4
182}-
183-
184/*!-
185 Sets this history state's default transition to be the given \a transition.-
186 This will set the source state of the \a transition to the history state.-
187-
188 Note that the eventTest method of the \a transition will never be called.-
189-
190 \since 5.6-
191*/-
192void QHistoryState::setDefaultTransition(QAbstractTransition *transition)-
193{-
194 Q_D(QHistoryState);-
195 if (d->defaultTransition != transition) {
d->defaultTran... != transitionDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEnever evaluated
0-1
196 d->defaultTransition = transition;-
197 transition->setParent(this);-
198 emit defaultTransitionChanged(QHistoryState::QPrivateSignal());-
199 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
200}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QStateMachine
1
201-
202/*!-
203 Returns this history state's default state. The default state indicates the-
204 state to transition to if the parent state has never been entered before.-
205*/-
206QAbstractState *QHistoryState::defaultState() const-
207{-
208 Q_D(const QHistoryState);-
209 return d->defaultTransition ? d->defaultTransition->targetState() : Q_NULLPTR;
executed 4 times by 1 test: return d->defaultTransition ? d->defaultTransition->targetState() : nullptr;
Executed by:
  • tst_QStateMachine
4
210}-
211-
212static inline bool isSoleEntry(const QList<QAbstractState*> &states, const QAbstractState * state)-
213{-
214 return states.size() == 1 && states.first() == state;
never executed: return states.size() == 1 && states.first() == state;
0
215}-
216-
217/*!-
218 Sets this history state's default state to be the given \a state.-
219 \a state must be a sibling of this history state.-
220-
221 Note that this function does not set \a state as the initial state-
222 of its parent.-
223*/-
224void QHistoryState::setDefaultState(QAbstractState *state)-
225{-
226 Q_D(QHistoryState);-
227 if (state && state->parentState() != parentState()) {
stateDescription
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
state->parentS... parentState()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
0-9
228 qWarning("QHistoryState::setDefaultState: state %p does not belong "-
229 "to this history state's group (%p)", state, parentState());-
230 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QStateMachine
2
231 }-
232 if (!d->defaultTransition || !isSoleEntry(d->defaultTransition->targetStates(), state)) {
!d->defaultTransitionDescription
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
!isSoleEntry(d...ates(), state)Description
TRUEnever evaluated
FALSEnever evaluated
0-7
233 if (!d->defaultTransition || !qobject_cast<DefaultStateTransition*>(d->defaultTransition)) {
!d->defaultTransitionDescription
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
!qobject_cast<...ultTransition)Description
TRUEnever evaluated
FALSEnever evaluated
0-7
234 d->defaultTransition = new DefaultStateTransition(this, state);-
235 emit defaultTransitionChanged(QHistoryState::QPrivateSignal());-
236 } else {
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
7
237 d->defaultTransition->setTargetState(state);-
238 }
never executed: end of block
0
239 emit defaultStateChanged(QHistoryState::QPrivateSignal());-
240 }
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
7
241}
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
7
242-
243/*!-
244 Returns the type of history that this history state records.-
245*/-
246QHistoryState::HistoryType QHistoryState::historyType() const-
247{-
248 Q_D(const QHistoryState);-
249 return d->historyType;
executed 5 times by 1 test: return d->historyType;
Executed by:
  • tst_QStateMachine
5
250}-
251-
252/*!-
253 Sets the \a type of history that this history state records.-
254*/-
255void QHistoryState::setHistoryType(HistoryType type)-
256{-
257 Q_D(QHistoryState);-
258 if (d->historyType != type) {
d->historyType != typeDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEnever evaluated
0-3
259 d->historyType = type;-
260 emit historyTypeChanged(QHistoryState::QPrivateSignal());-
261 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
3
262}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
3
263-
264/*!-
265 \reimp-
266*/-
267void QHistoryState::onEntry(QEvent *event)-
268{-
269 Q_UNUSED(event);-
270}
never executed: end of block
0
271-
272/*!-
273 \reimp-
274*/-
275void QHistoryState::onExit(QEvent *event)-
276{-
277 Q_UNUSED(event);-
278}
never executed: end of block
0
279-
280/*!-
281 \reimp-
282*/-
283bool QHistoryState::event(QEvent *e)-
284{-
285 return QAbstractState::event(e);
executed 9 times by 2 tests: return QAbstractState::event(e);
Executed by:
  • tst_QState
  • tst_QStateMachine
9
286}-
287-
288/*!-
289 \fn QHistoryState::defaultStateChanged()-
290 \since 5.4-
291-
292 This signal is emitted when the defaultState property is changed.-
293-
294 \sa QHistoryState::defaultState-
295*/-
296-
297/*!-
298 \fn QHistoryState::historyTypeChanged()-
299 \since 5.4-
300-
301 This signal is emitted when the historyType property is changed.-
302-
303 \sa QHistoryState::historyType-
304*/-
305-
306/*!-
307 \fn QHistoryState::defaultTransitionChanged()-
308 \since 5.6-
309-
310 This signal is emitted when the defaultTransition property is changed.-
311-
312 \sa QHistoryState::defaultTransition-
313*/-
314-
315QT_END_NAMESPACE-
316-
317#endif //QT_NO_STATEMACHINE-
Source codeSwitch to Preprocessed file

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