/src/corelib/statemachine/qstatemachine_p.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 250 lines · 159 code · 40 blank · 51 comment · 0 complexity · 46bba4a5d966e35282b5e87e467a65d4 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the QtCore module of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #ifndef QSTATEMACHINE_P_H
  42. #define QSTATEMACHINE_P_H
  43. //
  44. // W A R N I N G
  45. // -------------
  46. //
  47. // This file is not part of the Qt API. It exists purely as an
  48. // implementation detail. This header file may change from version to
  49. // version without notice, or even be removed.
  50. //
  51. // We mean it.
  52. //
  53. #include "private/qstate_p.h"
  54. #include <QtCore/qcoreevent.h>
  55. #include <QtCore/qhash.h>
  56. #include <QtCore/qlist.h>
  57. #include <QtCore/qmutex.h>
  58. #include <QtCore/qpair.h>
  59. #include <QtCore/qset.h>
  60. #include <QtCore/qvector.h>
  61. QT_BEGIN_NAMESPACE
  62. class QEvent;
  63. #ifndef QT_NO_STATEMACHINE_EVENTFILTER
  64. class QEventTransition;
  65. #endif
  66. class QSignalEventGenerator;
  67. class QSignalTransition;
  68. class QAbstractState;
  69. class QAbstractTransition;
  70. class QFinalState;
  71. class QHistoryState;
  72. class QState;
  73. #ifndef QT_NO_ANIMATION
  74. class QAbstractAnimation;
  75. #endif
  76. class QStateMachine;
  77. class Q_CORE_EXPORT QStateMachinePrivate : public QStatePrivate
  78. {
  79. Q_DECLARE_PUBLIC(QStateMachine)
  80. public:
  81. enum State {
  82. NotRunning,
  83. Starting,
  84. Running
  85. };
  86. enum EventProcessingMode {
  87. DirectProcessing,
  88. QueuedProcessing
  89. };
  90. enum StopProcessingReason {
  91. EventQueueEmpty,
  92. Finished,
  93. Stopped
  94. };
  95. QStateMachinePrivate();
  96. ~QStateMachinePrivate();
  97. static QStateMachinePrivate *get(QStateMachine *q);
  98. QState *findLCA(const QList<QAbstractState*> &states) const;
  99. static bool stateEntryLessThan(QAbstractState *s1, QAbstractState *s2);
  100. static bool stateExitLessThan(QAbstractState *s1, QAbstractState *s2);
  101. QAbstractState *findErrorState(QAbstractState *context);
  102. void setError(QStateMachine::Error error, QAbstractState *currentContext);
  103. // private slots
  104. void _q_start();
  105. void _q_process();
  106. #ifndef QT_NO_ANIMATION
  107. void _q_animationFinished();
  108. #endif
  109. QState *rootState() const;
  110. QState *startState();
  111. void removeStartState();
  112. void clearHistory();
  113. void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
  114. bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const;
  115. QSet<QAbstractTransition*> selectTransitions(QEvent *event) const;
  116. QList<QAbstractState*> exitStates(QEvent *event, const QList<QAbstractTransition*> &transitionList);
  117. void executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &transitionList);
  118. QList<QAbstractState*> enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions);
  119. void addStatesToEnter(QAbstractState *s, QState *root,
  120. QSet<QAbstractState*> &statesToEnter,
  121. QSet<QAbstractState*> &statesForDefaultEntry);
  122. void applyProperties(const QList<QAbstractTransition*> &transitionList,
  123. const QList<QAbstractState*> &exitedStates,
  124. const QList<QAbstractState*> &enteredStates);
  125. static QState *toStandardState(QAbstractState *state);
  126. static const QState *toStandardState(const QAbstractState *state);
  127. static QFinalState *toFinalState(QAbstractState *state);
  128. static QHistoryState *toHistoryState(QAbstractState *state);
  129. bool isInFinalState(QAbstractState *s) const;
  130. static bool isFinal(const QAbstractState *s);
  131. static bool isParallel(const QAbstractState *s);
  132. bool isCompound(const QAbstractState *s) const;
  133. bool isAtomic(const QAbstractState *s) const;
  134. static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other);
  135. static QList<QState*> properAncestors(const QAbstractState *s, const QState *upperBound);
  136. void goToState(QAbstractState *targetState);
  137. void registerTransitions(QAbstractState *state);
  138. void registerSignalTransition(QSignalTransition *transition);
  139. void unregisterSignalTransition(QSignalTransition *transition);
  140. #ifndef QT_NO_STATEMACHINE_EVENTFILTER
  141. void registerEventTransition(QEventTransition *transition);
  142. void unregisterEventTransition(QEventTransition *transition);
  143. void handleFilteredEvent(QObject *watched, QEvent *event);
  144. #endif
  145. void unregisterTransition(QAbstractTransition *transition);
  146. void unregisterAllTransitions();
  147. void handleTransitionSignal(QObject *sender, int signalIndex,
  148. void **args);
  149. void postInternalEvent(QEvent *e);
  150. void postExternalEvent(QEvent *e);
  151. QEvent *dequeueInternalEvent();
  152. QEvent *dequeueExternalEvent();
  153. bool isInternalEventQueueEmpty();
  154. bool isExternalEventQueueEmpty();
  155. void processEvents(EventProcessingMode processingMode);
  156. void cancelAllDelayedEvents();
  157. #ifndef QT_NO_PROPERTIES
  158. typedef QPair<QObject *, QByteArray> RestorableId;
  159. QHash<RestorableId, QVariant> registeredRestorables;
  160. void registerRestorable(QObject *object, const QByteArray &propertyName);
  161. void unregisterRestorable(QObject *object, const QByteArray &propertyName);
  162. bool hasRestorable(QObject *object, const QByteArray &propertyName) const;
  163. QVariant restorableValue(QObject *object, const QByteArray &propertyName) const;
  164. QList<QPropertyAssignment> restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const;
  165. #endif
  166. State state;
  167. QState *_startState;
  168. bool processing;
  169. bool processingScheduled;
  170. bool stop;
  171. StopProcessingReason stopProcessingReason;
  172. QSet<QAbstractState*> configuration;
  173. QList<QEvent*> internalEventQueue;
  174. QList<QEvent*> externalEventQueue;
  175. QMutex internalEventMutex;
  176. QMutex externalEventMutex;
  177. QStateMachine::Error error;
  178. QStateMachine::RestorePolicy globalRestorePolicy;
  179. QString errorString;
  180. QSet<QAbstractState *> pendingErrorStates;
  181. QSet<QAbstractState *> pendingErrorStatesForDefaultEntry;
  182. #ifndef QT_NO_ANIMATION
  183. bool animated;
  184. QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> >
  185. initializeAnimation(QAbstractAnimation *abstractAnimation,
  186. const QPropertyAssignment &prop);
  187. QHash<QAbstractState*, QList<QAbstractAnimation*> > animationsForState;
  188. QHash<QAbstractAnimation*, QPropertyAssignment> propertyForAnimation;
  189. QHash<QAbstractAnimation*, QAbstractState*> stateForAnimation;
  190. QSet<QAbstractAnimation*> resetAnimationEndValues;
  191. QList<QAbstractAnimation *> defaultAnimations;
  192. QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForSource;
  193. QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForTarget;
  194. #endif // QT_NO_ANIMATION
  195. QSignalEventGenerator *signalEventGenerator;
  196. QHash<const QObject*, QVector<int> > connections;
  197. #ifndef QT_NO_STATEMACHINE_EVENTFILTER
  198. QHash<QObject*, QHash<QEvent::Type, int> > qobjectEvents;
  199. #endif
  200. QHash<int, QEvent*> delayedEvents;
  201. QMutex delayedEventsMutex;
  202. typedef QEvent* (*f_cloneEvent)(QEvent*);
  203. struct Handler {
  204. f_cloneEvent cloneEvent;
  205. };
  206. static const Handler *handler;
  207. };
  208. Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler();
  209. QT_END_NAMESPACE
  210. #endif