Qt 4.8
qstatemachine_p.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_P_H
43 #define QSTATEMACHINE_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "private/qstate_p.h"
57 
58 #include <QtCore/qcoreevent.h>
59 #include <QtCore/qhash.h>
60 #include <QtCore/qlist.h>
61 #include <QtCore/qmutex.h>
62 #include <QtCore/qpair.h>
63 #include <QtCore/qset.h>
64 #include <QtCore/qvector.h>
65 
67 
68 class QEvent;
69 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
70 class QEventTransition;
71 #endif
73 class QSignalTransition;
74 class QAbstractState;
76 class QFinalState;
77 class QHistoryState;
78 class QState;
79 
80 #ifndef QT_NO_ANIMATION
81 class QAbstractAnimation;
82 #endif
83 
84 class QStateMachine;
86 {
88 public:
89  enum State {
92  Running
93  };
96  QueuedProcessing
97  };
101  Stopped
102  };
103 
106 
107  static QStateMachinePrivate *get(QStateMachine *q);
108 
109  QState *findLCA(const QList<QAbstractState*> &states) const;
110 
111  static bool stateEntryLessThan(QAbstractState *s1, QAbstractState *s2);
112  static bool stateExitLessThan(QAbstractState *s1, QAbstractState *s2);
113 
114  QAbstractState *findErrorState(QAbstractState *context);
115  void setError(QStateMachine::Error error, QAbstractState *currentContext);
116 
117  // private slots
118  void _q_start();
119  void _q_process();
120 #ifndef QT_NO_ANIMATION
121  void _q_animationFinished();
122 #endif
123 
124  QState *rootState() const;
125 
126  QState *startState();
127  void removeStartState();
128 
129  void clearHistory();
130 
131  void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
132  bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const;
133  QSet<QAbstractTransition*> selectTransitions(QEvent *event) const;
134  QList<QAbstractState*> exitStates(QEvent *event, const QList<QAbstractTransition*> &transitionList);
135  void executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &transitionList);
136  QList<QAbstractState*> enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions);
137  void addStatesToEnter(QAbstractState *s, QState *root,
138  QSet<QAbstractState*> &statesToEnter,
139  QSet<QAbstractState*> &statesForDefaultEntry);
140 
141  void applyProperties(const QList<QAbstractTransition*> &transitionList,
142  const QList<QAbstractState*> &exitedStates,
143  const QList<QAbstractState*> &enteredStates);
144 
145  static QState *toStandardState(QAbstractState *state);
146  static const QState *toStandardState(const QAbstractState *state);
147  static QFinalState *toFinalState(QAbstractState *state);
148  static QHistoryState *toHistoryState(QAbstractState *state);
149 
150  bool isInFinalState(QAbstractState *s) const;
151  static bool isFinal(const QAbstractState *s);
152  static bool isParallel(const QAbstractState *s);
153  bool isCompound(const QAbstractState *s) const;
154  bool isAtomic(const QAbstractState *s) const;
155  static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other);
156  static QList<QState*> properAncestors(const QAbstractState *s, const QState *upperBound);
157 
158  void goToState(QAbstractState *targetState);
159 
160  void registerTransitions(QAbstractState *state);
161  void registerSignalTransition(QSignalTransition *transition);
162  void unregisterSignalTransition(QSignalTransition *transition);
163 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
164  void registerEventTransition(QEventTransition *transition);
165  void unregisterEventTransition(QEventTransition *transition);
166  void handleFilteredEvent(QObject *watched, QEvent *event);
167 #endif
168  void unregisterTransition(QAbstractTransition *transition);
169  void unregisterAllTransitions();
170  void handleTransitionSignal(QObject *sender, int signalIndex,
171  void **args);
172 
173  void postInternalEvent(QEvent *e);
174  void postExternalEvent(QEvent *e);
175  QEvent *dequeueInternalEvent();
176  QEvent *dequeueExternalEvent();
177  bool isInternalEventQueueEmpty();
178  bool isExternalEventQueueEmpty();
179  void processEvents(EventProcessingMode processingMode);
180  void cancelAllDelayedEvents();
181 
182 #ifndef QT_NO_PROPERTIES
185  void registerRestorable(QObject *object, const QByteArray &propertyName);
186  void unregisterRestorable(QObject *object, const QByteArray &propertyName);
187  bool hasRestorable(QObject *object, const QByteArray &propertyName) const;
188  QVariant restorableValue(QObject *object, const QByteArray &propertyName) const;
189  QList<QPropertyAssignment> restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const;
190 #endif
191 
196  bool stop;
203 
206 
210 
211 #ifndef QT_NO_ANIMATION
212  bool animated;
213 
215  initializeAnimation(QAbstractAnimation *abstractAnimation,
216  const QPropertyAssignment &prop);
217 
222 
226 
227 #endif // QT_NO_ANIMATION
228 
230 
232 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
234 #endif
237 
238  typedef QEvent* (*f_cloneEvent)(QEvent*);
239  struct Handler {
240  f_cloneEvent cloneEvent;
241  };
242 
243  static const Handler *handler;
244 };
245 
247 
249 
250 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
QStateMachine::RestorePolicy globalRestorePolicy
Q_CORE_EXPORT const QStateMachinePrivate::Handler * qcoreStateMachineHandler()
QStateMachine::Error error
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
EventRef event
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
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QPair< QObject *, QByteArray > RestorableId
StopProcessingReason stopProcessingReason
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForTarget
QSet< QAbstractState * > configuration
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
QHash< QObject *, QHash< QEvent::Type, int > > qobjectEvents
RestorePolicy
This enum specifies the restore policy type.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QEventTransition class provides a QObject-specific transition for Qt events.
QHash< QAbstractAnimation *, QPropertyAssignment > propertyForAnimation
QSet< QAbstractState * > pendingErrorStates
The QAbstractState class is the base class of states of a QStateMachine.
The QSignalTransition class provides a transition based on a Qt signal.
The QFinalState class provides a final state.
Definition: qfinalstate.h:56
QHash< int, QEvent * > delayedEvents
QSignalEventGenerator * signalEventGenerator
QList< QEvent * > externalEventQueue
The State element defines configurations of objects and properties.
The QAbstractAnimation class is the base of all animations.
QList< QAbstractAnimation * > defaultAnimations
The QHistoryState class provides a means of returning to a previously active substate.
Definition: qhistorystate.h:56
QHash< const QObject *, QVector< int > > connections
Error
This enum type defines errors that can occur in the state machine at run time.
QHash< RestorableId, QVariant > registeredRestorables
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QList< QEvent * > internalEventQueue
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
QHash< QAbstractAnimation *, QAbstractState * > stateForAnimation
QSet< QAbstractAnimation * > resetAnimationEndValues
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForSource
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QSet< QAbstractState * > pendingErrorStatesForDefaultEntry
static const Handler * handler
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QHash< QAbstractState *, QList< QAbstractAnimation * > > animationsForState