src/corelib/statemachine/qabstractstate.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    76 
    76 
    77   The onExit() function is called when the state is exited; reimplement this
    77   The onExit() function is called when the state is exited; reimplement this
    78   function to perform custom processing when the state is exited.
    78   function to perform custom processing when the state is exited.
    79 */
    79 */
    80 
    80 
    81 QAbstractStatePrivate::QAbstractStatePrivate()    
    81 QAbstractStatePrivate::QAbstractStatePrivate(StateType type)
       
    82     : stateType(type), isMachine(false), parentState(0)
    82 {
    83 {
    83 }
    84 }
    84 
    85 
    85 QAbstractStatePrivate *QAbstractStatePrivate::get(QAbstractState *q)
    86 QAbstractStatePrivate *QAbstractStatePrivate::get(QAbstractState *q)
       
    87 {
       
    88     return q->d_func();
       
    89 }
       
    90 
       
    91 const QAbstractStatePrivate *QAbstractStatePrivate::get(const QAbstractState *q)
    86 {
    92 {
    87     return q->d_func();
    93     return q->d_func();
    88 }
    94 }
    89 
    95 
    90 QStateMachine *QAbstractStatePrivate::machine() const
    96 QStateMachine *QAbstractStatePrivate::machine() const
   124 
   130 
   125 /*!
   131 /*!
   126   Constructs a new state with the given \a parent state.
   132   Constructs a new state with the given \a parent state.
   127 */
   133 */
   128 QAbstractState::QAbstractState(QState *parent)
   134 QAbstractState::QAbstractState(QState *parent)
   129     : QObject(*new QAbstractStatePrivate, parent)
   135     : QObject(*new QAbstractStatePrivate(QAbstractStatePrivate::AbstractState), parent)
   130 {
   136 {
   131 }
   137 }
   132 
   138 
   133 /*!
   139 /*!
   134   \internal
   140   \internal
   148 /*!
   154 /*!
   149   Returns this state's parent state, or 0 if the state has no parent state.
   155   Returns this state's parent state, or 0 if the state has no parent state.
   150 */
   156 */
   151 QState *QAbstractState::parentState() const
   157 QState *QAbstractState::parentState() const
   152 {
   158 {
   153     return qobject_cast<QState*>(parent());
   159     Q_D(const QAbstractState);
       
   160     if (d->parentState != parent())
       
   161         d->parentState = qobject_cast<QState*>(parent());
       
   162     return d->parentState;
   154 }
   163 }
   155 
   164 
   156 /*!
   165 /*!
   157   Returns the state machine that this state is part of, or 0 if the state is
   166   Returns the state machine that this state is part of, or 0 if the state is
   158   not part of a state machine.
   167   not part of a state machine.