Qt 4.8
qsignaltransition.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsignaltransition.h"
43 
44 #ifndef QT_NO_STATEMACHINE
45 
46 #include "qsignaltransition_p.h"
47 #include "qstate.h"
48 #include "qstate_p.h"
49 #include "qstatemachine.h"
50 #include "qstatemachine_p.h"
51 #include <qdebug.h>
52 
54 
122 {
123  sender = 0;
124  signalIndex = -1;
125 }
126 
128 {
129  return q->d_func();
130 }
131 
133 {
135  if ((signalIndex == -1) || !machine())
136  return;
138 }
139 
141 {
143  if (!machine() || !machine()->configuration().contains(sourceState()))
144  return;
146 }
147 
152  : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
153 {
154 }
155 
162  : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
163 {
165  d->sender = sender;
166  d->signal = signal;
167 }
168 
173 {
174 }
175 
180 {
181  Q_D(const QSignalTransition);
182  return d->sender;
183 }
184 
189 {
191  if (sender == d->sender)
192  return;
193  d->unregister();
194  d->sender = sender;
195  d->maybeRegister();
196 }
197 
202 {
203  Q_D(const QSignalTransition);
204  return d->signal;
205 }
206 
211 {
213  if (signal == d->signal)
214  return;
215  d->unregister();
216  d->signal = signal;
217  d->maybeRegister();
218 }
219 
231 {
232  Q_D(const QSignalTransition);
233  if (event->type() == QEvent::StateMachineSignal) {
234  if (d->signalIndex == -1)
235  return false;
237  return (se->sender() == d->sender)
238  && (se->signalIndex() == d->signalIndex);
239  }
240  return false;
241 }
242 
247 {
248  Q_UNUSED(event);
249 }
250 
255 {
256  return QAbstractTransition::event(e);
257 }
258 
260 {
262 
263  if (e->type() == QEvent::StateMachineSignal) {
265  int savedSignalIndex = se->m_signalIndex;
266  se->m_signalIndex = originalSignalIndex;
267  q->onTransition(e);
268  se->m_signalIndex = savedSignalIndex;
269  } else {
270  q->onTransition(e);
271  }
272 }
273 
275 
276 #endif //QT_NO_STATEMACHINE
double d
Definition: qnumeric_p.h:62
~QSignalTransition()
Destroys this signal transition.
bool event(QEvent *e)
Reimplemented Function
QObject * sender() const
Returns the object that emitted the signal.
Definition: qstatemachine.h:80
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
QSignalTransition(QState *sourceState=0)
Constructs a new signal transition with the given sourceState.
virtual void callOnTransition(QEvent *e)
void unregisterSignalTransition(QSignalTransition *transition)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int signalIndex() const
Returns the index of the signal.
Definition: qstatemachine.h:81
bool eventTest(QEvent *event)
The default implementation returns true if the event is a QStateMachine::SignalEvent object and the e...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
#define Q_Q(Class)
Definition: qglobal.h:2483
QByteArray signal() const
void registerSignalTransition(QSignalTransition *transition)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QStateMachinePrivate * get(QStateMachine *q)
The QSignalTransition class provides a transition based on a Qt signal.
void onTransition(QEvent *event)
Reimplemented Function
QState * sourceState() const
void setSenderObject(QObject *sender)
Sets the sender object associated with this signal transition.
QStateMachine * machine() const
static QSignalTransitionPrivate * get(QSignalTransition *q)
bool event(QEvent *e)
Reimplemented Function
QObject * senderObject() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The SignalEvent class represents a Qt signal event.
Definition: qstatemachine.h:73
void setSignal(const QByteArray &signal)
Sets the signal associated with this signal transition.