src/corelib/statemachine/qstatemachine_p.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    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/qpair.h>
       
    62 #include <QtCore/qset.h>
       
    63 #include <QtCore/qvector.h>
       
    64 
       
    65 QT_BEGIN_NAMESPACE
       
    66 
       
    67 class QEvent;
       
    68 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
       
    69 class QEventTransition;
       
    70 #endif
       
    71 class QSignalEventGenerator;
       
    72 class QSignalTransition;
       
    73 class QAbstractState;
       
    74 class QAbstractTransition;
       
    75 class QState;
       
    76 
       
    77 #ifndef QT_NO_ANIMATION
       
    78 class QAbstractAnimation;
       
    79 #endif
       
    80 
       
    81 class QStateMachine;
       
    82 class Q_CORE_EXPORT QStateMachinePrivate : public QStatePrivate
       
    83 {
       
    84     Q_DECLARE_PUBLIC(QStateMachine)
       
    85 public:
       
    86     enum State {
       
    87         NotRunning,
       
    88         Starting,
       
    89         Running
       
    90     };
       
    91     enum EventProcessingMode {
       
    92         DirectProcessing,
       
    93         QueuedProcessing
       
    94     };
       
    95     enum StopProcessingReason {
       
    96         EventQueueEmpty,
       
    97         Finished,
       
    98         Stopped
       
    99     };
       
   100 
       
   101     QStateMachinePrivate();
       
   102     ~QStateMachinePrivate();
       
   103 
       
   104     static QStateMachinePrivate *get(QStateMachine *q);
       
   105 
       
   106     QState *findLCA(const QList<QAbstractState*> &states) const;
       
   107 
       
   108     static bool stateEntryLessThan(QAbstractState *s1, QAbstractState *s2);
       
   109     static bool stateExitLessThan(QAbstractState *s1, QAbstractState *s2);
       
   110 
       
   111     QAbstractState *findErrorState(QAbstractState *context);
       
   112     void setError(QStateMachine::Error error, QAbstractState *currentContext);
       
   113 
       
   114     // private slots
       
   115     void _q_start();
       
   116     void _q_process();
       
   117 #ifndef QT_NO_ANIMATION
       
   118     void _q_animationFinished();
       
   119 #endif
       
   120 
       
   121     QState *rootState() const;
       
   122 
       
   123     QState *startState();
       
   124     void removeStartState();
       
   125 
       
   126     void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
       
   127     bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const;
       
   128     QSet<QAbstractTransition*> selectTransitions(QEvent *event) const;
       
   129     QList<QAbstractState*> exitStates(QEvent *event, const QList<QAbstractTransition*> &transitionList);
       
   130     void executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &transitionList);
       
   131     QList<QAbstractState*> enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions);
       
   132     void addStatesToEnter(QAbstractState *s, QState *root,
       
   133                           QSet<QAbstractState*> &statesToEnter,
       
   134                           QSet<QAbstractState*> &statesForDefaultEntry);
       
   135 
       
   136     void applyProperties(const QList<QAbstractTransition*> &transitionList,
       
   137                          const QList<QAbstractState*> &exitedStates,
       
   138                          const QList<QAbstractState*> &enteredStates);
       
   139 
       
   140     bool isInFinalState(QAbstractState *s) const;
       
   141     static bool isFinal(const QAbstractState *s);
       
   142     static bool isParallel(const QAbstractState *s);
       
   143     bool isCompound(const QAbstractState *s) const;
       
   144     bool isAtomic(const QAbstractState *s) const;
       
   145     static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other);
       
   146     static QList<QState*> properAncestors(const QAbstractState *s, const QState *upperBound);
       
   147 
       
   148     void goToState(QAbstractState *targetState);
       
   149 
       
   150     void registerTransitions(QAbstractState *state);
       
   151     void registerSignalTransition(QSignalTransition *transition);
       
   152     void unregisterSignalTransition(QSignalTransition *transition);
       
   153 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
       
   154     void registerEventTransition(QEventTransition *transition);
       
   155     void unregisterEventTransition(QEventTransition *transition);
       
   156     void handleFilteredEvent(QObject *watched, QEvent *event);
       
   157 #endif
       
   158     void unregisterTransition(QAbstractTransition *transition);
       
   159     void unregisterAllTransitions();
       
   160     void handleTransitionSignal(QObject *sender, int signalIndex,
       
   161                                 void **args);    
       
   162     void processEvents(EventProcessingMode processingMode);
       
   163     void cancelAllDelayedEvents();
       
   164     
       
   165 #ifndef QT_NO_PROPERTIES
       
   166     typedef QPair<QObject *, QByteArray> RestorableId;
       
   167     QHash<RestorableId, QVariant> registeredRestorables;
       
   168     void registerRestorable(QObject *object, const QByteArray &propertyName);
       
   169     void unregisterRestorable(QObject *object, const QByteArray &propertyName);
       
   170     bool hasRestorable(QObject *object, const QByteArray &propertyName) const;
       
   171     QVariant restorableValue(QObject *object, const QByteArray &propertyName) const;
       
   172     QList<QPropertyAssignment> restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const;
       
   173 #endif
       
   174 
       
   175     State state;
       
   176     QState *_startState;
       
   177     bool processing;
       
   178     bool processingScheduled;
       
   179     bool stop;
       
   180     StopProcessingReason stopProcessingReason;
       
   181     QSet<QAbstractState*> configuration;
       
   182     QList<QEvent*> internalEventQueue;
       
   183     QList<QEvent*> externalEventQueue;
       
   184 
       
   185     QStateMachine::Error error;
       
   186     QStateMachine::RestorePolicy globalRestorePolicy;
       
   187 
       
   188     QString errorString;
       
   189     QSet<QAbstractState *> pendingErrorStates;
       
   190     QSet<QAbstractState *> pendingErrorStatesForDefaultEntry;
       
   191 
       
   192 #ifndef QT_NO_ANIMATION
       
   193     bool animationsEnabled;
       
   194 
       
   195     QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> >
       
   196         initializeAnimation(QAbstractAnimation *abstractAnimation, 
       
   197                             const QPropertyAssignment &prop);
       
   198 
       
   199     QHash<QAbstractState*, QList<QAbstractAnimation*> > animationsForState;
       
   200     QHash<QAbstractAnimation*, QPropertyAssignment> propertyForAnimation;
       
   201     QHash<QAbstractAnimation*, QAbstractState*> stateForAnimation;
       
   202     QSet<QAbstractAnimation*> resetAnimationEndValues;
       
   203 
       
   204     QList<QAbstractAnimation *> defaultAnimations;
       
   205     QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForSource;
       
   206     QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForTarget;
       
   207 
       
   208 #endif // QT_NO_ANIMATION
       
   209 
       
   210     QSignalEventGenerator *signalEventGenerator;
       
   211 
       
   212     QHash<const QObject*, QVector<int> > connections;
       
   213 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
       
   214     QHash<QObject*, QHash<QEvent::Type, int> > qobjectEvents;
       
   215 #endif
       
   216     QHash<int, QEvent*> delayedEvents;
       
   217   
       
   218     typedef QEvent* (*f_cloneEvent)(QEvent*);
       
   219     struct Handler {
       
   220         f_cloneEvent cloneEvent;
       
   221     };
       
   222 
       
   223     static const Handler *handler;
       
   224 };
       
   225 
       
   226 Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler();
       
   227 
       
   228 QT_END_NAMESPACE
       
   229 
       
   230 #endif