summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r--src/corelib/statemachine/qabstractstate.cpp22
-rw-r--r--src/corelib/statemachine/qabstractstate.h4
-rw-r--r--src/corelib/statemachine/qabstractstate_p.h4
-rw-r--r--src/corelib/statemachine/qabstracttransition.cpp11
-rw-r--r--src/corelib/statemachine/qabstracttransition.h2
-rw-r--r--src/corelib/statemachine/qabstracttransition_p.h2
-rw-r--r--src/corelib/statemachine/qeventtransition.cpp3
-rw-r--r--src/corelib/statemachine/qeventtransition.h2
-rw-r--r--src/corelib/statemachine/qfinalstate.cpp6
-rw-r--r--src/corelib/statemachine/qfinalstate.h4
-rw-r--r--src/corelib/statemachine/qhistorystate.cpp4
-rw-r--r--src/corelib/statemachine/qhistorystate.h4
-rw-r--r--src/corelib/statemachine/qsignaltransition.cpp3
-rw-r--r--src/corelib/statemachine/qsignaltransition.h2
-rw-r--r--src/corelib/statemachine/qstate.cpp8
-rw-r--r--src/corelib/statemachine/qstate.h4
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp41
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h8
18 files changed, 72 insertions, 62 deletions
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index cc6f0f9..3f84314 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -101,16 +101,16 @@ QStateMachine *QAbstractStatePrivate::machine() const
return 0;
}
-void QAbstractStatePrivate::callOnEntry()
+void QAbstractStatePrivate::callOnEntry(QEvent *e)
{
Q_Q(QAbstractState);
- q->onEntry();
+ q->onEntry(e);
}
-void QAbstractStatePrivate::callOnExit()
+void QAbstractStatePrivate::callOnExit(QEvent *e)
{
Q_Q(QAbstractState);
- q->onExit();
+ q->onExit(e);
}
void QAbstractStatePrivate::emitEntered()
@@ -190,17 +190,19 @@ QStateMachine *QAbstractState::machine() const
}
/*!
- \fn QAbstractState::onExit()
+ \fn QAbstractState::onExit(QEvent *event)
- This function is called when the state is exited. Reimplement this function
- to perform custom processing when the state is exited.
+ This function is called when the state is exited. The given \a event is what
+ caused the state to be exited. Reimplement this function to perform custom
+ processing when the state is exited.
*/
/*!
- \fn QAbstractState::onEntry()
+ \fn QAbstractState::onEntry(QEvent *event)
- This function is called when the state is entered. Reimplement this function
- to perform custom processing when the state is entered.
+ This function is called when the state is entered. The given \a event is
+ what caused the state to be entered. Reimplement this function to perform
+ custom processing when the state is entered.
*/
/*!
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index 30a68ff..f6b4b21 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -70,8 +70,8 @@ Q_SIGNALS:
protected:
QAbstractState(QState *parent = 0);
- virtual void onEntry() = 0;
- virtual void onExit() = 0;
+ virtual void onEntry(QEvent *event) = 0;
+ virtual void onExit(QEvent *event) = 0;
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index bbe12d6..6c09696 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -77,8 +77,8 @@ public:
QStateMachine *machine() const;
- void callOnEntry();
- void callOnExit();
+ void callOnEntry(QEvent *e);
+ void callOnExit(QEvent *e);
void emitEntered();
void emitExited();
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp
index 5fa1742..1897aa6 100644
--- a/src/corelib/statemachine/qabstracttransition.cpp
+++ b/src/corelib/statemachine/qabstracttransition.cpp
@@ -131,10 +131,10 @@ bool QAbstractTransitionPrivate::callEventTest(QEvent *e) const
return q->eventTest(e);
}
-void QAbstractTransitionPrivate::callOnTransition()
+void QAbstractTransitionPrivate::callOnTransition(QEvent *e)
{
Q_Q(QAbstractTransition);
- q->onTransition();
+ q->onTransition(e);
}
QState *QAbstractTransitionPrivate::sourceState() const
@@ -353,10 +353,11 @@ QList<QAbstractAnimation*> QAbstractTransition::animations() const
*/
/*!
- \fn QAbstractTransition::onTransition()
+ \fn QAbstractTransition::onTransition(QEvent *event)
- This function is called when the transition is triggered. Reimplement this
- function to perform custom processing when the transition is triggered.
+ This function is called when the transition is triggered. The given \a event
+ is what caused the transition to trigger. Reimplement this function to
+ perform custom processing when the transition is triggered.
*/
/*!
diff --git a/src/corelib/statemachine/qabstracttransition.h b/src/corelib/statemachine/qabstracttransition.h
index 79ab808..e207944 100644
--- a/src/corelib/statemachine/qabstracttransition.h
+++ b/src/corelib/statemachine/qabstracttransition.h
@@ -90,7 +90,7 @@ public:
protected:
virtual bool eventTest(QEvent *event) const = 0;
- virtual void onTransition() = 0;
+ virtual void onTransition(QEvent *event) = 0;
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qabstracttransition_p.h b/src/corelib/statemachine/qabstracttransition_p.h
index a48a09c..b4e1c88 100644
--- a/src/corelib/statemachine/qabstracttransition_p.h
+++ b/src/corelib/statemachine/qabstracttransition_p.h
@@ -79,7 +79,7 @@ public:
static const QAbstractTransitionPrivate *get(const QAbstractTransition *q);
bool callEventTest(QEvent *e) const;
- void callOnTransition();
+ void callOnTransition(QEvent *e);
QState *sourceState() const;
QStateMachine *machine() const;
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp
index cbd03bd..86259e4 100644
--- a/src/corelib/statemachine/qeventtransition.cpp
+++ b/src/corelib/statemachine/qeventtransition.cpp
@@ -270,8 +270,9 @@ bool QEventTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QEventTransition::onTransition()
+void QEventTransition::onTransition(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h
index 484602c..a128cee 100644
--- a/src/corelib/statemachine/qeventtransition.h
+++ b/src/corelib/statemachine/qeventtransition.h
@@ -78,7 +78,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
- void onTransition();
+ void onTransition(QEvent *event);
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
index 6a1b608..772ec87 100644
--- a/src/corelib/statemachine/qfinalstate.cpp
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -108,15 +108,17 @@ QFinalState::~QFinalState()
/*!
\reimp
*/
-void QFinalState::onEntry()
+void QFinalState::onEntry(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
\reimp
*/
-void QFinalState::onExit()
+void QFinalState::onExit(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
diff --git a/src/corelib/statemachine/qfinalstate.h b/src/corelib/statemachine/qfinalstate.h
index 726a399..eb8aa0f 100644
--- a/src/corelib/statemachine/qfinalstate.h
+++ b/src/corelib/statemachine/qfinalstate.h
@@ -63,8 +63,8 @@ public:
~QFinalState();
protected:
- void onEntry();
- void onExit();
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qhistorystate.cpp b/src/corelib/statemachine/qhistorystate.cpp
index 4e3db08..fd6f53d 100644
--- a/src/corelib/statemachine/qhistorystate.cpp
+++ b/src/corelib/statemachine/qhistorystate.cpp
@@ -200,14 +200,14 @@ void QHistoryState::setHistoryType(HistoryType type)
/*!
\reimp
*/
-void QHistoryState::onEntry()
+void QHistoryState::onEntry(QEvent *event)
{
}
/*!
\reimp
*/
-void QHistoryState::onExit()
+void QHistoryState::onExit(QEvent *event)
{
}
diff --git a/src/corelib/statemachine/qhistorystate.h b/src/corelib/statemachine/qhistorystate.h
index c7648bc..d0f75de 100644
--- a/src/corelib/statemachine/qhistorystate.h
+++ b/src/corelib/statemachine/qhistorystate.h
@@ -78,8 +78,8 @@ public:
void setHistoryType(HistoryType type);
protected:
- void onEntry();
- void onExit();
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp
index e9e248f..d5833bd 100644
--- a/src/corelib/statemachine/qsignaltransition.cpp
+++ b/src/corelib/statemachine/qsignaltransition.cpp
@@ -245,8 +245,9 @@ bool QSignalTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QSignalTransition::onTransition()
+void QSignalTransition::onTransition(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h
index b8e8fc6..98a9ae7 100644
--- a/src/corelib/statemachine/qsignaltransition.h
+++ b/src/corelib/statemachine/qsignaltransition.h
@@ -77,7 +77,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
- void onTransition();
+ void onTransition(QEvent *event);
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index a431888..3220619 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -339,7 +339,7 @@ public:
UnconditionalTransition(QAbstractState *target)
: QAbstractTransition(QList<QAbstractState*>() << target) {}
protected:
- void onTransition() {}
+ void onTransition(QEvent *) {}
bool eventTest(QEvent *) const { return true; }
};
@@ -384,15 +384,17 @@ void QState::removeTransition(QAbstractTransition *transition)
/*!
\reimp
*/
-void QState::onEntry()
+void QState::onEntry(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
\reimp
*/
-void QState::onExit()
+void QState::onExit(QEvent *event)
{
+ Q_UNUSED(event);
}
/*!
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 9faef26..73955d7 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -97,8 +97,8 @@ Q_SIGNALS:
void polished();
protected:
- void onEntry();
- void onExit();
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 0ebc993..8b0b4f3 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -369,18 +369,18 @@ QSet<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *event
return enabledTransitions;
}
-void QStateMachinePrivate::microstep(const QList<QAbstractTransition*> &enabledTransitions)
+void QStateMachinePrivate::microstep(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
{
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": begin microstep( enabledTransitions:" << enabledTransitions << ")";
qDebug() << q_func() << ": configuration before exiting states:" << configuration;
#endif
- QList<QAbstractState*> exitedStates = exitStates(enabledTransitions);
+ QList<QAbstractState*> exitedStates = exitStates(event, enabledTransitions);
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": configuration after exiting states:" << configuration;
#endif
- executeTransitionContent(enabledTransitions);
- QList<QAbstractState*> enteredStates = enterStates(enabledTransitions);
+ executeTransitionContent(event, enabledTransitions);
+ QList<QAbstractState*> enteredStates = enterStates(event, enabledTransitions);
applyProperties(enabledTransitions, exitedStates, enteredStates);
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": configuration after entering states:" << configuration;
@@ -388,7 +388,7 @@ void QStateMachinePrivate::microstep(const QList<QAbstractTransition*> &enabledT
#endif
}
-QList<QAbstractState*> QStateMachinePrivate::exitStates(const QList<QAbstractTransition*> &enabledTransitions)
+QList<QAbstractState*> QStateMachinePrivate::exitStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
{
// qDebug() << "exitStates(" << enabledTransitions << ")";
QSet<QAbstractState*> statesToExit;
@@ -440,25 +440,25 @@ QList<QAbstractState*> QStateMachinePrivate::exitStates(const QList<QAbstractTra
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": exiting" << s;
#endif
- QAbstractStatePrivate::get(s)->callOnExit();
+ QAbstractStatePrivate::get(s)->callOnExit(event);
configuration.remove(s);
QAbstractStatePrivate::get(s)->emitExited();
}
return statesToExit_sorted;
}
-void QStateMachinePrivate::executeTransitionContent(const QList<QAbstractTransition*> &enabledTransitions)
+void QStateMachinePrivate::executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
{
for (int i = 0; i < enabledTransitions.size(); ++i) {
QAbstractTransition *t = enabledTransitions.at(i);
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": triggering" << t;
#endif
- QAbstractTransitionPrivate::get(t)->callOnTransition();
+ QAbstractTransitionPrivate::get(t)->callOnTransition(event);
}
}
-QList<QAbstractState*> QStateMachinePrivate::enterStates(const QList<QAbstractTransition*> &enabledTransitions)
+QList<QAbstractState*> QStateMachinePrivate::enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
{
#ifdef QSTATEMACHINE_DEBUG
Q_Q(QStateMachine);
@@ -506,7 +506,7 @@ QList<QAbstractState*> QStateMachinePrivate::enterStates(const QList<QAbstractTr
#endif
configuration.insert(s);
registerTransitions(s);
- QAbstractStatePrivate::get(s)->callOnEntry();
+ QAbstractStatePrivate::get(s)->callOnEntry(event);
QAbstractStatePrivate::get(s)->emitEntered();
if (statesForDefaultEntry.contains(s)) {
// ### executeContent(s.initial.transition.children())
@@ -1067,8 +1067,8 @@ public:
StartState(QState *parent)
: QState(parent) {}
protected:
- void onEntry() {}
- void onExit() {}
+ void onEntry(QEvent *) {}
+ void onExit(QEvent *) {}
};
class InitialTransition : public QAbstractTransition
@@ -1078,7 +1078,7 @@ public:
: QAbstractTransition(QList<QAbstractState*>() << target) {}
protected:
virtual bool eventTest(QEvent *) const { return true; }
- virtual void onTransition() {}
+ virtual void onTransition(QEvent *) {}
};
} // namespace
@@ -1113,8 +1113,9 @@ void QStateMachinePrivate::_q_start()
start->addTransition(initialTransition);
QList<QAbstractTransition*> transitions;
transitions.append(initialTransition);
- executeTransitionContent(transitions);
- enterStates(transitions);
+ QEvent nullEvent(QEvent::None);
+ executeTransitionContent(&nullEvent, transitions);
+ enterStates(&nullEvent, transitions);
applyProperties(transitions, QList<QAbstractState*>() << start,
QList<QAbstractState*>() << initial);
delete start;
@@ -1180,7 +1181,7 @@ void QStateMachinePrivate::_q_process()
}
if (!enabledTransitions.isEmpty()) {
q->beginMicrostep(e);
- microstep(enabledTransitions.toList());
+ microstep(e, enabledTransitions.toList());
q->endMicrostep(e);
}
#ifdef QSTATEMACHINE_DEBUG
@@ -1455,7 +1456,7 @@ public:
setObjectName(QString::fromLatin1("DefaultErrorState"));
}
- void onEntry()
+ void onEntry(QEvent *)
{
QAbstractStatePrivate *d = QAbstractStatePrivate::get(this);
QStateMachine *machine = d->machine();
@@ -1464,7 +1465,7 @@ public:
qPrintable(machine->errorString()));
}
- void onExit() {}
+ void onExit(QEvent *) {}
};
class RootState : public QState
@@ -1475,8 +1476,8 @@ public:
{
}
- void onEntry() {}
- void onExit() {}
+ void onEntry(QEvent *) {}
+ void onExit(QEvent *) {}
};
} // namespace
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index b3707ea..bb4a78c 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -120,12 +120,12 @@ public:
void _q_animationFinished();
#endif
- void microstep(const QList<QAbstractTransition*> &transitionList);
+ void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const;
QSet<QAbstractTransition*> selectTransitions(QEvent *event) const;
- QList<QAbstractState*> exitStates(const QList<QAbstractTransition*> &transitionList);
- void executeTransitionContent(const QList<QAbstractTransition*> &transitionList);
- QList<QAbstractState*> enterStates(const QList<QAbstractTransition*> &enabledTransitions);
+ QList<QAbstractState*> exitStates(QEvent *event, const QList<QAbstractTransition*> &transitionList);
+ void executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &transitionList);
+ QList<QAbstractState*> enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions);
void addStatesToEnter(QAbstractState *s, QState *root,
QSet<QAbstractState*> &statesToEnter,
QSet<QAbstractState*> &statesForDefaultEntry);