Qt 4.8
qabstracttransition.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 "qabstracttransition.h"
43 
44 #ifndef QT_NO_STATEMACHINE
45 
46 #include "qabstracttransition_p.h"
47 #include "qabstractstate.h"
48 #include "qstate.h"
49 #include "qstatemachine.h"
50 
52 
124 {
125 }
126 
128 {
129  return q->d_func();
130 }
131 
133 {
134  QState *source = sourceState();
135  if (!source)
136  return 0;
137  return source->machine();
138 }
139 
141 {
143  return q->eventTest(e);
144 }
145 
147 {
149  q->onTransition(e);
150 }
151 
153 {
154  return qobject_cast<QState*>(parent);
155 }
156 
158 {
160  emit q->triggered();
161 }
162 
167  : QObject(*new QAbstractTransitionPrivate, sourceState)
168 {
169 }
170 
175  QState *parent)
176  : QObject(dd, parent)
177 {
178 }
179 
184 {
185 }
186 
192 {
193  Q_D(const QAbstractTransition);
194  return d->sourceState();
195 }
196 
202 {
203  Q_D(const QAbstractTransition);
204  if (d->targetStates.isEmpty())
205  return 0;
206  return d->targetStates.first().data();
207 }
208 
213 {
215  if (!target)
216  d->targetStates.clear();
217  else
219 }
220 
226 {
227  Q_D(const QAbstractTransition);
228  QList<QAbstractState*> result;
229  for (int i = 0; i < d->targetStates.size(); ++i) {
230  QAbstractState *target = d->targetStates.at(i).data();
231  if (target)
232  result.append(target);
233  }
234  return result;
235 }
236 
241 {
243 
244  for (int i = 0; i < targets.size(); ++i) {
245  QAbstractState *target = targets.at(i);
246  if (!target) {
247  qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null");
248  return;
249  }
250  }
251 
252  d->targetStates.clear();
253  for (int i = 0; i < targets.size(); ++i)
254  d->targetStates.append(targets.at(i));
255 }
256 
262 {
263  Q_D(const QAbstractTransition);
264  return d->machine();
265 }
266 
267 #ifndef QT_NO_ANIMATION
268 
276 {
278  if (!animation) {
279  qWarning("QAbstractTransition::addAnimation: cannot add null animation");
280  return;
281  }
282  d->animations.append(animation);
283 }
284 
291 {
293  if (!animation) {
294  qWarning("QAbstractTransition::removeAnimation: cannot remove null animation");
295  return;
296  }
297  d->animations.removeOne(animation);
298 }
299 
307 {
308  Q_D(const QAbstractTransition);
309  return d->animations;
310 }
311 
312 #endif
313 
344 {
345  return QObject::event(e);
346 }
347 
349 
350 #endif //QT_NO_STATEMACHINE
T qobject_cast(QObject *object)
Definition: qobject.h:375
double d
Definition: qnumeric_p.h:62
void addAnimation(QAbstractAnimation *animation)
Adds the given animation to this transition.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QStateMachine * machine() const
Returns the state machine that this state is part of, or 0 if the state is not part of a state machin...
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractState * > targetStates() const
QList< QAbstractAnimation * > animations() const
Returns the list of animations associated with this transition, or an empty list if it has no animati...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QAbstractState class is the base class of states of a QStateMachine.
static QAbstractTransitionPrivate * get(QAbstractTransition *q)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
QState * sourceState() const
The QAbstractAnimation class is the base of all animations.
void setTargetState(QAbstractState *target)
Sets the target state of this transition.
virtual void callOnTransition(QEvent *e)
QAbstractTransition(QState *sourceState=0)
Constructs a new QAbstractTransition object with the given sourceState.
virtual ~QAbstractTransition()
Destroys this transition.
QStateMachine * machine() const
QAbstractState * targetState() const
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool event(QEvent *e)
Reimplemented Function
void removeAnimation(QAbstractAnimation *animation)
Removes the given animation from this transition.
QObject * parent
Definition: qobject.h:92
QStateMachine * machine() const
Returns the state machine that this transition is part of, or 0 if the transition is not part of a st...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setTargetStates(const QList< QAbstractState *> &targets)
Sets the target states of this transition to be the given targets.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62