qeventtransition.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qeventtransition.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 "qeventtransition.h"-
35-
36#ifndef QT_NO_STATEMACHINE-
37-
38#include "qeventtransition_p.h"-
39#include "qstate.h"-
40#include "qstate_p.h"-
41#include "qstatemachine.h"-
42#include "qstatemachine_p.h"-
43#include <qdebug.h>-
44-
45QT_BEGIN_NAMESPACE-
46-
47/*!-
48 \class QEventTransition-
49 \inmodule QtCore-
50-
51 \brief The QEventTransition class provides a QObject-specific transition for Qt events.-
52-
53 \since 4.6-
54 \ingroup statemachine-
55-
56 A QEventTransition object binds an event to a particular QObject.-
57 QEventTransition is part of \l{The State Machine Framework}.-
58-
59 Example:-
60-
61 \code-
62 QPushButton *button = ...;-
63 QState *s1 = ...;-
64 QState *s2 = ...;-
65 // If in s1 and the button receives an Enter event, transition to s2-
66 QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);-
67 enterTransition->setTargetState(s2);-
68 s1->addTransition(enterTransition);-
69 // If in s2 and the button receives an Exit event, transition back to s1-
70 QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);-
71 leaveTransition->setTargetState(s1);-
72 s2->addTransition(leaveTransition);-
73 \endcode-
74-
75 \section1 Subclassing-
76-
77 When reimplementing the eventTest() function, you should first call the base-
78 implementation to verify that the event is a QStateMachine::WrappedEvent for-
79 the proper object and event type. You may then cast the event to a-
80 QStateMachine::WrappedEvent and get the original event by calling-
81 QStateMachine::WrappedEvent::event(), and perform additional checks on that-
82 object.-
83-
84 \sa QState::addTransition()-
85*/-
86-
87/*!-
88 \property QEventTransition::eventSource-
89-
90 \brief the event source that this event transition is associated with-
91*/-
92-
93/*!-
94 \property QEventTransition::eventType-
95-
96 \brief the type of event that this event transition is associated with-
97*/-
98QEventTransitionPrivate::QEventTransitionPrivate()-
99{-
100 object = 0;-
101 eventType = QEvent::None;-
102 registered = false;-
103}
executed 18 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
18
104-
105QEventTransitionPrivate::~QEventTransitionPrivate()-
106{-
107}-
108-
109void QEventTransitionPrivate::unregister()-
110{-
111 Q_Q(QEventTransition);-
112 if (!registered || !machine())
!registeredDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QStateMachine
!machine()Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-10
113 return;
executed 10 times by 1 test: return;
Executed by:
  • tst_QStateMachine
10
114 QStateMachinePrivate::get(machine())->unregisterEventTransition(q);-
115}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
3
116-
117void QEventTransitionPrivate::maybeRegister()-
118{-
119 Q_Q(QEventTransition);-
120 if (QStateMachine *mach = machine())
QStateMachine ...ch = machine()Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QStateMachine
7-18
121 QStateMachinePrivate::get(mach)->maybeRegisterEventTransition(q);
executed 7 times by 1 test: QStateMachinePrivate::get(mach)->maybeRegisterEventTransition(q);
Executed by:
  • tst_QStateMachine
7
122}
executed 25 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
25
123-
124/*!-
125 Constructs a new QEventTransition object with the given \a sourceState.-
126*/-
127QEventTransition::QEventTransition(QState *sourceState)-
128 : QAbstractTransition(*new QEventTransitionPrivate, sourceState)-
129{-
130}
executed 4 times by 2 tests: end of block
Executed by:
  • tst_QState
  • tst_QStateMachine
4
131-
132/*!-
133 Constructs a new QEventTransition object associated with events of the given-
134 \a type for the given \a object, and with the given \a sourceState.-
135*/-
136QEventTransition::QEventTransition(QObject *object, QEvent::Type type,-
137 QState *sourceState)-
138 : QAbstractTransition(*new QEventTransitionPrivate, sourceState)-
139{-
140 Q_D(QEventTransition);-
141 d->registered = false;-
142 d->object = object;-
143 d->eventType = type;-
144 d->maybeRegister();-
145}
executed 10 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
10
146-
147/*!-
148 \internal-
149*/-
150QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)-
151 : QAbstractTransition(dd, parent)-
152{-
153}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
2
154-
155/*!-
156 \internal-
157*/-
158QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,-
159 QEvent::Type type, QState *parent)-
160 : QAbstractTransition(dd, parent)-
161{-
162 Q_D(QEventTransition);-
163 d->registered = false;-
164 d->object = object;-
165 d->eventType = type;-
166 d->maybeRegister();-
167}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
2
168-
169/*!-
170 Destroys this QObject event transition.-
171*/-
172QEventTransition::~QEventTransition()-
173{-
174}-
175-
176/*!-
177 Returns the event type that this event transition is associated with.-
178*/-
179QEvent::Type QEventTransition::eventType() const-
180{-
181 Q_D(const QEventTransition);-
182 return d->eventType;
executed 120 times by 1 test: return d->eventType;
Executed by:
  • tst_QStateMachine
120
183}-
184-
185/*!-
186 Sets the event \a type that this event transition is associated with.-
187*/-
188void QEventTransition::setEventType(QEvent::Type type)-
189{-
190 Q_D(QEventTransition);-
191 if (d->eventType == type)
d->eventType == typeDescription
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-7
192 return;
never executed: return;
0
193 d->unregister();-
194 d->eventType = type;-
195 d->maybeRegister();-
196}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
7
197-
198/*!-
199 Returns the event source associated with this event transition.-
200*/-
201QObject *QEventTransition::eventSource() const-
202{-
203 Q_D(const QEventTransition);-
204 return d->object;
executed 5 times by 1 test: return d->object;
Executed by:
  • tst_QStateMachine
5
205}-
206-
207/*!-
208 Sets the event source associated with this event transition to be the given-
209 \a object.-
210*/-
211void QEventTransition::setEventSource(QObject *object)-
212{-
213 Q_D(QEventTransition);-
214 if (d->object == object)
d->object == objectDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QStateMachine
0-6
215 return;
never executed: return;
0
216 d->unregister();-
217 d->object = object;-
218 d->maybeRegister();-
219}
executed 6 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
6
220-
221/*!-
222 \reimp-
223*/-
224bool QEventTransition::eventTest(QEvent *event)-
225{-
226 Q_D(const QEventTransition);-
227 if (event->type() == QEvent::StateMachineWrapped) {
event->type() ...MachineWrappedDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 42 times by 1 test
Evaluated by:
  • tst_QStateMachine
21-42
228 QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event);-
229 return (we->object() == d->object)
executed 21 times by 1 test: return (we->object() == d->object) && (we->event()->type() == d->eventType);
Executed by:
  • tst_QStateMachine
(we->object() == d->object)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEnever evaluated
0-21
230 && (we->event()->type() == d->eventType);
executed 21 times by 1 test: return (we->object() == d->object) && (we->event()->type() == d->eventType);
Executed by:
  • tst_QStateMachine
(we->event()->... d->eventType)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • tst_QStateMachine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QStateMachine
1-21
231 }-
232 return false;
executed 42 times by 1 test: return false;
Executed by:
  • tst_QStateMachine
42
233}-
234-
235/*!-
236 \reimp-
237*/-
238void QEventTransition::onTransition(QEvent *event)-
239{-
240 Q_UNUSED(event);-
241}
executed 20 times by 1 test: end of block
Executed by:
  • tst_QStateMachine
20
242-
243/*!-
244 \reimp-
245*/-
246bool QEventTransition::event(QEvent *e)-
247{-
248 return QAbstractTransition::event(e);
never executed: return QAbstractTransition::event(e);
0
249}-
250-
251QT_END_NAMESPACE-
252-
253#endif //QT_NO_STATEMACHINE-
Source codeSwitch to Preprocessed file

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