Qt 4.8
qstatemachine.h
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 #ifndef QSTATEMACHINE_H
43 #define QSTATEMACHINE_H
44 
45 #include <QtCore/qstate.h>
46 
47 #include <QtCore/qcoreevent.h>
48 #include <QtCore/qlist.h>
49 #include <QtCore/qobject.h>
50 #include <QtCore/qset.h>
51 #include <QtCore/qvariant.h>
52 
54 
56 
57 QT_MODULE(Core)
58 
59 #ifndef QT_NO_STATEMACHINE
60 
62 class QAbstractAnimation;
64 {
65  Q_OBJECT
69 #ifndef QT_NO_ANIMATION
70  bool animated;
71 #endif
72 public:
74  {
75  public:
76  SignalEvent(QObject *sender, int signalIndex,
77  const QList<QVariant> &arguments);
78  ~SignalEvent();
79 
80  inline QObject *sender() const { return m_sender; }
81  inline int signalIndex() const { return m_signalIndex; }
82  inline QList<QVariant> arguments() const { return m_arguments; }
83 
84  private:
88 
90  };
91 
93  {
94  public:
95  WrappedEvent(QObject *object, QEvent *event);
96  ~WrappedEvent();
97 
98  inline QObject *object() const { return m_object; }
99  inline QEvent *event() const { return m_event; }
100 
101  private:
104  };
105 
108  HighPriority
109  };
110 
113  RestoreProperties
114  };
115 
116  enum Error {
120  NoCommonAncestorForTransitionError
121  };
122 
123  QStateMachine(QObject *parent = 0);
124  ~QStateMachine();
125 
126  void addState(QAbstractState *state);
127  void removeState(QAbstractState *state);
128 
129  Error error() const;
130  QString errorString() const;
131  void clearError();
132 
133  bool isRunning() const;
134 
135 #ifndef QT_NO_ANIMATION
136  bool isAnimated() const;
137  void setAnimated(bool enabled);
138 
139  void addDefaultAnimation(QAbstractAnimation *animation);
140  QList<QAbstractAnimation *> defaultAnimations() const;
141  void removeDefaultAnimation(QAbstractAnimation *animation);
142 #endif // QT_NO_ANIMATION
143 
144  QStateMachine::RestorePolicy globalRestorePolicy() const;
145  void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy);
146 
147  void postEvent(QEvent *event, EventPriority priority = NormalPriority);
148  int postDelayedEvent(QEvent *event, int delay);
149  bool cancelDelayedEvent(int id);
150 
151  QSet<QAbstractState*> configuration() const;
152 
153 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
154  bool eventFilter(QObject *watched, QEvent *event);
155 #endif
156 
157 public Q_SLOTS:
158  void start();
159  void stop();
160 
161 Q_SIGNALS:
162  void started();
163  void stopped();
164 
165 protected:
166  void onEntry(QEvent *event);
167  void onExit(QEvent *event);
168 
169  virtual void beginSelectTransitions(QEvent *event);
170  virtual void endSelectTransitions(QEvent *event);
171 
172  virtual void beginMicrostep(QEvent *event);
173  virtual void endMicrostep(QEvent *event);
174 
175  bool event(QEvent *e);
176 
177 protected:
179 
180 private:
183  Q_PRIVATE_SLOT(d_func(), void _q_start())
184  Q_PRIVATE_SLOT(d_func(), void _q_process())
185 #ifndef QT_NO_ANIMATION
186  Q_PRIVATE_SLOT(d_func(), void _q_animationFinished())
187 #endif
188 };
189 
190 #endif //QT_NO_STATEMACHINE
191 
193 
195 
196 #endif
QObject * sender() const
Returns the object that emitted the signal.
Definition: qstatemachine.h:80
The WrappedEvent class inherits QEvent and holds a clone of an event associated with a QObject...
Definition: qstatemachine.h:92
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString errorString
the error string of this state machine
Definition: qstatemachine.h:66
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define error(msg)
QList< QVariant > arguments() const
Returns the arguments of the signal.
Definition: qstatemachine.h:82
int signalIndex() const
Returns the index of the signal.
Definition: qstatemachine.h:81
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
QObject * object() const
Returns the object that the event is associated with.
Definition: qstatemachine.h:98
RestorePolicy
This enum specifies the restore policy type.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QAbstractState class is the base class of states of a QStateMachine.
The QAbstractAnimation class is the base of all animations.
#define Q_OBJECT
Definition: qobjectdefs.h:157
QList< QVariant > m_arguments
Definition: qstatemachine.h:87
Error
This enum type defines errors that can occur in the state machine at run time.
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
EventPriority
This enum type specifies the priority of an event posted to the state machine using postEvent()...
bool animated
whether animations are enabled
Definition: qstatemachine.h:70
RestorePolicy globalRestorePolicy
the restore policy for states of this state machine.
Definition: qstatemachine.h:67
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
The SignalEvent class represents a Qt signal event.
Definition: qstatemachine.h:73
#define enabled
QEvent * event() const
Returns a clone of the original event.
Definition: qstatemachine.h:99