qsignaltransition.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qsignaltransition.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 "qsignaltransition.h"-
41-
42#ifndef QT_NO_STATEMACHINE-
43-
44#include "qsignaltransition_p.h"-
45#include "qstate.h"-
46#include "qstate_p.h"-
47#include "qstatemachine.h"-
48#include "qstatemachine_p.h"-
49#include <qdebug.h>-
50-
51QT_BEGIN_NAMESPACE-
52-
53/*!-
54 \class QSignalTransition-
55 \inmodule QtCore-
56-
57 \brief The QSignalTransition class provides a transition based on a Qt signal.-
58-
59 \since 4.6-
60 \ingroup statemachine-
61-
62 Typically you would use the overload of QState::addTransition() that takes a-
63 sender and signal as arguments, rather than creating QSignalTransition-
64 objects directly. QSignalTransition is part of \l{The State Machine-
65 Framework}.-
66-
67 You can subclass QSignalTransition and reimplement eventTest() to make a-
68 signal transition conditional; the event object passed to eventTest() will-
69 be a QStateMachine::SignalEvent object. Example:-
70-
71 \code-
72 class CheckedTransition : public QSignalTransition-
73 {-
74 public:-
75 CheckedTransition(QCheckBox *check)-
76 : QSignalTransition(check, SIGNAL(stateChanged(int))) {}-
77 protected:-
78 bool eventTest(QEvent *e) {-
79 if (!QSignalTransition::eventTest(e))-
80 return false;-
81 QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e);-
82 return (se->arguments().at(0).toInt() == Qt::Checked);-
83 }-
84 };-
85-
86 ...-
87-
88 QCheckBox *check = new QCheckBox();-
89 check->setTristate(true);-
90-
91 QState *s1 = new QState();-
92 QState *s2 = new QState();-
93 CheckedTransition *t1 = new CheckedTransition(check);-
94 t1->setTargetState(s2);-
95 s1->addTransition(t1);-
96 \endcode-
97*/-
98-
99/*!-
100 \property QSignalTransition::senderObject-
101-
102 \brief the sender object that this signal transition is associated with-
103*/-
104-
105/*!-
106 \property QSignalTransition::signal-
107-
108 \brief the signal that this signal transition is associated with-
109*/-
110-
111QSignalTransitionPrivate::QSignalTransitionPrivate()-
112{-
113 sender = 0;-
114 signalIndex = -1;-
115}
executed 74 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
74
116-
117void QSignalTransitionPrivate::unregister()-
118{-
119 Q_Q(QSignalTransition);-
120 if ((signalIndex == -1) || !machine())
(signalIndex == -1)Description
TRUEevaluated 100010 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 100003 times by 1 test
Evaluated by:
  • tst_QStateMachine
!machine()Description
TRUEnever evaluated
FALSEevaluated 100003 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-100010
121 return;
executed 100010 times by 1 test: return;
Executed by:
  • tst_QStateMachine
100010
122 QStateMachinePrivate::get(machine())->unregisterSignalTransition(q);-
123}
executed 100003 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
100003
124-
125void QSignalTransitionPrivate::maybeRegister()-
126{-
127 Q_Q(QSignalTransition);-
128 if (QStateMachine *mach = machine())
QStateMachine ...ch = machine()Description
TRUEevaluated 200010 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 71 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
71-200010
129 QStateMachinePrivate::get(mach)->maybeRegisterSignalTransition(q);
executed 200010 times by 2 tests: QStateMachinePrivate::get(mach)->maybeRegisterSignalTransition(q);
Executed by:
  • tst_QState
  • tst_QStateMachine
200010
130}
executed 200081 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
200081
131-
132/*!-
133 Constructs a new signal transition with the given \a sourceState.-
134*/-
135QSignalTransition::QSignalTransition(QState *sourceState)-
136 : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)-
137{-
138}
executed 6 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
6
139-
140/*!-
141 Constructs a new signal transition associated with the given \a signal of-
142 the given \a sender, and with the given \a sourceState.-
143*/-
144QSignalTransition::QSignalTransition(const QObject *sender, const char *signal,-
145 QState *sourceState)-
146 : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)-
147{-
148 Q_D(QSignalTransition);-
149 d->sender = sender;-
150 d->signal = signal;-
151 d->maybeRegister();-
152}
executed 68 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
68
153-
154/*!-
155 \fn QSignalTransition::QSignalTransition(const QObject *sender,-
156 PointerToMemberFunction signal, QState *sourceState)-
157 \since 5.7-
158 \overload-
159-
160 Constructs a new signal transition associated with the given \a signal of-
161 the given \a sender object and with the given \a sourceState.-
162 This constructor is enabled if the compiler supports delegating constructors,-
163 as indicated by the presence of the macro Q_COMPILER_DELEGATING_CONSTRUCTORS.-
164*/-
165-
166/*!-
167 Destroys this signal transition.-
168*/-
169QSignalTransition::~QSignalTransition()-
170{-
171}-
172-
173/*!-
174 Returns the sender object associated with this signal transition.-
175*/-
176QObject *QSignalTransition::senderObject() const-
177{-
178 Q_D(const QSignalTransition);-
179 return const_cast<QObject *>(d->sender);
executed 161 times by 2 tests: return const_cast<QObject *>(d->sender);
Executed by:
  • tst_QState
  • tst_QStateMachine
161
180}-
181-
182/*!-
183 Sets the \a sender object associated with this signal transition.-
184*/-
185void QSignalTransition::setSenderObject(const QObject *sender)-
186{-
187 Q_D(QSignalTransition);-
188 if (sender == d->sender)
sender == d->senderDescription
TRUEnever evaluated
FALSEevaluated 200004 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-200004
189 return;
never executed: return;
0
190 d->unregister();-
191 d->sender = sender;-
192 d->maybeRegister();-
193 emit senderObjectChanged(QPrivateSignal());-
194}
executed 200004 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
200004
195-
196/*!-
197 Returns the signal associated with this signal transition.-
198*/-
199QByteArray QSignalTransition::signal() const-
200{-
201 Q_D(const QSignalTransition);-
202 return d->signal;
executed 10 times by 1 test: return d->signal;
Executed by:
  • tst_QStateMachine
10
203}-
204-
205/*!-
206 Sets the \a signal associated with this signal transition.-
207*/-
208void QSignalTransition::setSignal(const QByteArray &signal)-
209{-
210 Q_D(QSignalTransition);-
211 if (signal == d->signal)
signal == d->signalDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-9
212 return;
never executed: return;
0
213 d->unregister();-
214 d->signal = signal;-
215 d->maybeRegister();-
216 emit signalChanged(QPrivateSignal());-
217}
executed 9 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
9
218-
219/*!-
220 \reimp-
221-
222 The default implementation returns \c true if the \a event is a-
223 QStateMachine::SignalEvent object and the event's sender and signal index-
224 match this transition, and returns \c false otherwise.-
225*/-
226bool QSignalTransition::eventTest(QEvent *event)-
227{-
228 Q_D(const QSignalTransition);-
229 if (event->type() == QEvent::StateMachineSignal) {
event->type() ...eMachineSignalDescription
TRUEevaluated 89 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEevaluated 2203 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
89-2203
230 if (d->signalIndex == -1)
d->signalIndex == -1Description
TRUEnever evaluated
FALSEevaluated 89 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
0-89
231 return false;
never executed: return false;
0
232 QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);-
233 return (se->sender() == d->sender)
executed 89 times by 2 tests: return (se->sender() == d->sender) && (se->signalIndex() == d->signalIndex);
Executed by:
  • tst_QState
  • tst_QStateMachine
89
234 && (se->signalIndex() == d->signalIndex);
executed 89 times by 2 tests: return (se->sender() == d->sender) && (se->signalIndex() == d->signalIndex);
Executed by:
  • tst_QState
  • tst_QStateMachine
89
235 }-
236 return false;
executed 2203 times by 2 tests: return false;
Executed by:
  • tst_QState
  • tst_QStateMachine
2203
237}-
238-
239/*!-
240 \reimp-
241*/-
242void QSignalTransition::onTransition(QEvent *event)-
243{-
244 Q_UNUSED(event);-
245}
executed 71 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
71
246-
247/*!-
248 \reimp-
249*/-
250bool QSignalTransition::event(QEvent *e)-
251{-
252 return QAbstractTransition::event(e);
executed 2 times by 1 test: return QAbstractTransition::event(e);
Executed by:
  • tst_QStateMachine
2
253}-
254-
255/*!-
256 \fn QSignalTransition::senderObjectChanged()-
257 \since 5.4-
258-
259 This signal is emitted when the senderObject property is changed.-
260-
261 \sa QSignalTransition::senderObject-
262*/-
263-
264/*!-
265 \fn QSignalTransition::signalChanged()-
266 \since 5.4-
267-
268 This signal is emitted when the signal property is changed.-
269-
270 \sa QSignalTransition::signal-
271*/-
272-
273void QSignalTransitionPrivate::callOnTransition(QEvent *e)-
274{-
275 Q_Q(QSignalTransition);-
276-
277 if (e->type() == QEvent::StateMachineSignal) {
e->type() == Q...eMachineSignalDescription
TRUEevaluated 71 times by 2 tests
Evaluated by:
  • tst_QState
  • tst_QStateMachine
FALSEnever evaluated
0-71
278 QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent *>(e);-
279 int savedSignalIndex = se->m_signalIndex;-
280 se->m_signalIndex = originalSignalIndex;-
281 q->onTransition(e);-
282 se->m_signalIndex = savedSignalIndex;-
283 } else {
executed 71 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
71
284 q->onTransition(e);-
285 }
never executed: end of block
0
286}-
287-
288-
289QT_END_NAMESPACE-
290-
291#endif //QT_NO_STATEMACHINE-
Source codeSwitch to Preprocessed file

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