summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-05-05 16:17:43 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-05-05 16:17:43 (GMT)
commit2e0430832d3656753f73b09765769d10aa51add3 (patch)
tree04c9fa068c57b90de15ebd01831a0e140b2b8e6c
parent6eae8aedd14acbc4ea73f336124b0243e9ebb9c0 (diff)
downloadQt-2e0430832d3656753f73b09765769d10aa51add3.zip
Qt-2e0430832d3656753f73b09765769d10aa51add3.tar.gz
Qt-2e0430832d3656753f73b09765769d10aa51add3.tar.bz2
add event as argument to onEntry(), onExit() and onTransition()
Accessing the event can be useful. E.g., onEntry() can do some common event processing regardless of which transition caused the state to be entered; onTransition() can be used in combination with eventTest(), where eventTest() would first check that the input matches some criteria, and then the actual processing of that input would be done in onTransition.
-rw-r--r--examples/animation/moveblocks/main.cpp6
-rw-r--r--examples/animation/sub-attaq/boat_p.h12
-rw-r--r--examples/animation/sub-attaq/qanimationstate.cpp4
-rw-r--r--examples/animation/sub-attaq/qanimationstate.h4
-rw-r--r--examples/animation/sub-attaq/states.cpp16
-rw-r--r--examples/animation/sub-attaq/states.h14
-rw-r--r--examples/animation/sub-attaq/submarine_p.h12
-rw-r--r--examples/statemachine/clockticking/main.cpp6
-rw-r--r--examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h4
-rw-r--r--examples/statemachine/errorstateplugins/seek_ai/seek_ai.h6
-rw-r--r--examples/statemachine/errorstateplugins/spin_ai/spin_ai.h2
-rw-r--r--examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h2
-rw-r--r--examples/statemachine/factorial/main.cpp4
-rw-r--r--examples/statemachine/helloworld/main.cpp2
-rw-r--r--examples/statemachine/pingpong/main.cpp6
-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
-rw-r--r--src/gui/statemachine/qbasickeyeventtransition.cpp2
-rw-r--r--src/gui/statemachine/qbasickeyeventtransition_p.h2
-rw-r--r--src/gui/statemachine/qbasicmouseeventtransition.cpp2
-rw-r--r--src/gui/statemachine/qbasicmouseeventtransition_p.h2
-rw-r--r--src/gui/statemachine/qkeyeventtransition.cpp4
-rw-r--r--src/gui/statemachine/qkeyeventtransition.h2
-rw-r--r--src/gui/statemachine/qmouseeventtransition.cpp4
-rw-r--r--src/gui/statemachine/qmouseeventtransition.h2
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp16
42 files changed, 140 insertions, 130 deletions
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
index eb23bd5..06ed3dd 100644
--- a/examples/animation/moveblocks/main.cpp
+++ b/examples/animation/moveblocks/main.cpp
@@ -101,7 +101,7 @@ protected:
&& (static_cast<StateSwitchEvent *>(event)->rand() == m_rand);
}
- virtual void onTransition() {}
+ virtual void onTransition(QEvent *) {}
private:
int m_rand;
@@ -116,7 +116,7 @@ public:
m_stateCount(0), m_lastIndex(0)
{ }
- virtual void onEntry()
+ virtual void onEntry(QEvent *)
{
int n;
while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
@@ -124,7 +124,7 @@ public:
m_lastIndex = n;
m_machine->postEvent(new StateSwitchEvent(n));
}
- virtual void onExit() {}
+ virtual void onExit(QEvent *) {}
void addState(QState *state, QAbstractAnimation *animation) {
StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount);
diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h
index 855b10f..17fbe5c 100644
--- a/examples/animation/sub-attaq/boat_p.h
+++ b/examples/animation/sub-attaq/boat_p.h
@@ -104,7 +104,7 @@ protected:
return false;
}
- void onTransition()
+ void onTransition(QEvent *)
{
//We decrease the speed if needed
if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right)
@@ -156,7 +156,7 @@ public:
this->boat = boat;
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
boat->setCurrentDirection(Boat::Right);
boat->updateBoatMovement();
@@ -174,7 +174,7 @@ public:
this->boat = boat;
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
boat->setCurrentDirection(Boat::Left);
boat->updateBoatMovement();
@@ -192,7 +192,7 @@ public:
this->boat = boat;
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
boat->setCurrentSpeed(0);
boat->setCurrentDirection(Boat::None);
@@ -211,7 +211,7 @@ public:
this->boat = boat;
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
Bomb *b = new Bomb();
b->setPos(boat->x()+boat->size().width(),boat->y());
@@ -233,7 +233,7 @@ public:
this->boat = boat;
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
Bomb *b = new Bomb();
b->setPos(boat->x() - b->size().width(), boat->y());
diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp
index 3659657..0f30ac2 100644
--- a/examples/animation/sub-attaq/qanimationstate.cpp
+++ b/examples/animation/sub-attaq/qanimationstate.cpp
@@ -146,7 +146,7 @@ QAbstractAnimation* QAnimationState::animation() const
/*!
\reimp
*/
-void QAnimationState::onEntry()
+void QAnimationState::onEntry(QEvent *)
{
Q_D(QAnimationState);
if (d->animation)
@@ -156,7 +156,7 @@ void QAnimationState::onEntry()
/*!
\reimp
*/
-void QAnimationState::onExit()
+void QAnimationState::onExit(QEvent *)
{
Q_D(QAnimationState);
if (d->animation)
diff --git a/examples/animation/sub-attaq/qanimationstate.h b/examples/animation/sub-attaq/qanimationstate.h
index ddf5681..88c0a6d 100644
--- a/examples/animation/sub-attaq/qanimationstate.h
+++ b/examples/animation/sub-attaq/qanimationstate.h
@@ -74,8 +74,8 @@ Q_SIGNALS:
void animationFinished();
protected:
- void onEntry();
- void onExit();
+ void onEntry(QEvent *);
+ void onExit(QEvent *);
bool event(QEvent *e);
private:
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
index 0b98016..c6af924 100644
--- a/examples/animation/sub-attaq/states.cpp
+++ b/examples/animation/sub-attaq/states.cpp
@@ -76,7 +76,7 @@ PlayState::~PlayState()
{
}
-void PlayState::onEntry()
+void PlayState::onEntry(QEvent *)
{
//We are now playing?
if (machine) {
@@ -159,7 +159,7 @@ void PlayState::onEntry()
LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game)
{
}
-void LevelState::onEntry()
+void LevelState::onEntry(QEvent *)
{
initializeLevel();
}
@@ -202,12 +202,12 @@ void LevelState::initializeLevel()
PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene)
{
}
-void PauseState::onEntry()
+void PauseState::onEntry(QEvent *)
{
AnimationManager::self()->pauseAll();
scene->boat->setEnabled(false);
}
-void PauseState::onExit()
+void PauseState::onExit(QEvent *)
{
AnimationManager::self()->resumeAll();
scene->boat->setEnabled(true);
@@ -219,7 +219,7 @@ LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QS
{
}
-void LostState::onEntry()
+void LostState::onEntry(QEvent *)
{
//The message to display
QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score);
@@ -242,7 +242,7 @@ WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QSta
{
}
-void WinState::onEntry()
+void WinState::onEntry(QEvent *)
{
//We clear the scene
scene->clearScene();
@@ -269,9 +269,9 @@ UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(par
{
this->game = game;
}
-void UpdateScoreState::onEntry()
+void UpdateScoreState::onEntry(QEvent *e)
{
- QState::onEntry();
+ QState::onEntry(e);
}
/** Win transition */
diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h
index ec69ae7..27beb71 100644
--- a/examples/animation/sub-attaq/states.h
+++ b/examples/animation/sub-attaq/states.h
@@ -68,7 +68,7 @@ public:
~PlayState();
protected:
- void onEntry();
+ void onEntry(QEvent *);
private :
GraphicsScene *scene;
@@ -91,7 +91,7 @@ class LevelState : public QState
public:
LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry();
+ void onEntry(QEvent *);
private :
void initializeLevel();
GraphicsScene *scene;
@@ -104,8 +104,8 @@ public:
PauseState(GraphicsScene *scene, QState *parent = 0);
protected:
- void onEntry();
- void onExit();
+ void onEntry(QEvent *);
+ void onExit(QEvent *);
private :
GraphicsScene *scene;
Boat *boat;
@@ -117,7 +117,7 @@ public:
LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry();
+ void onEntry(QEvent *);
private :
GraphicsScene *scene;
PlayState *game;
@@ -129,7 +129,7 @@ public:
WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
protected:
- void onEntry();
+ void onEntry(QEvent *);
private :
GraphicsScene *scene;
PlayState *game;
@@ -140,7 +140,7 @@ class UpdateScoreState : public QState
public:
UpdateScoreState(PlayState *game, QState *parent);
protected:
- void onEntry();
+ void onEntry(QEvent *);
private:
QPropertyAnimation *scoreAnimation;
PlayState *game;
diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h
index 918e7f5..c76d991 100644
--- a/examples/animation/sub-attaq/submarine_p.h
+++ b/examples/animation/sub-attaq/submarine_p.h
@@ -77,7 +77,7 @@ protected slots:
}
protected:
- void onEntry()
+ void onEntry(QEvent *e)
{
if (submarine->currentDirection() == SubMarine::Left) {
movementAnimation->setEndValue(QPointF(0,submarine->y()));
@@ -88,7 +88,7 @@ protected:
movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12);
}
movementAnimation->setStartValue(submarine->pos());
- QAnimationState::onEntry();
+ QAnimationState::onEntry(e);
}
private:
@@ -109,19 +109,19 @@ public:
}
protected:
- void onEntry()
+ void onEntry(QEvent *e)
{
returnAnimation->stop();
returnAnimation->setStartValue(submarine->yRotation());
returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.);
returnAnimation->setDuration(500);
- QAnimationState::onEntry();
+ QAnimationState::onEntry(e);
}
- void onExit()
+ void onExit(QEvent *e)
{
submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right);
- QAnimationState::onExit();
+ QAnimationState::onExit(e);
}
private:
diff --git a/examples/statemachine/clockticking/main.cpp b/examples/statemachine/clockticking/main.cpp
index 9b54f29..ea8e692 100644
--- a/examples/statemachine/clockticking/main.cpp
+++ b/examples/statemachine/clockticking/main.cpp
@@ -61,7 +61,7 @@ public:
: QState(parent) {}
protected:
- virtual void onEntry()
+ virtual void onEntry(QEvent *)
{
fprintf(stdout, "ClockState entered; posting the initial tick\n");
machine()->postEvent(new ClockEvent());
@@ -77,7 +77,7 @@ protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == QEvent::User+2);
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
fprintf(stdout, "ClockTransition triggered; posting another tick with a delay of 1 second\n");
machine()->postEvent(new ClockEvent(), 1000);
@@ -93,7 +93,7 @@ protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == QEvent::User+2);
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
fprintf(stdout, "ClockListener heard a tick!\n");
}
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
index d3670bd..3db464b 100644
--- a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
@@ -21,7 +21,7 @@ signals:
void turnSelected();
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
int rand = qrand() % 4;
switch (rand) {
@@ -45,7 +45,7 @@ signals:
void distanceComputed(qreal distance);
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
emit distanceComputed(qreal(qrand() % 180));
}
diff --git a/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h b/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h
index 83f50a7..7d8aa68 100644
--- a/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h
+++ b/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h
@@ -48,13 +48,13 @@ signals:
void nearestObstacleStraightAhead();
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle()));
turnAlittle();
}
- void onExit()
+ void onExit(QEvent *)
{
disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle()));
disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(nearestObstacleStraightAhead()));
@@ -89,7 +89,7 @@ protected:
return QSignalTransition::eventTest(event);
}
- void onTransition()
+ void onTransition(QEvent *)
{
qreal currentDirection = m_tank->property("direction").toDouble();
qreal angleOfWall = m_lastLine.angle();
diff --git a/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h b/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h
index 309ba14..4b4629c 100644
--- a/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h
+++ b/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h
@@ -22,7 +22,7 @@ public slots:
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
spin();
diff --git a/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h
index fa06d10..9a96a8b 100644
--- a/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h
+++ b/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h
@@ -22,7 +22,7 @@ public slots:
}
protected:
- void onEntry()
+ void onEntry(QEvent *)
{
connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
spin();
diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp
index 9e39ced..2b63690 100644
--- a/examples/statemachine/factorial/main.cpp
+++ b/examples/statemachine/factorial/main.cpp
@@ -104,7 +104,7 @@ public:
return m_fact->property("x").toInt() > 1;
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
int x = m_fact->property("x").toInt();
int fac = m_fact->property("fac").toInt();
@@ -128,7 +128,7 @@ public:
return m_fact->property("x").toInt() <= 1;
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
fprintf(stdout, "%d\n", m_fact->property("fac").toInt());
}
diff --git a/examples/statemachine/helloworld/main.cpp b/examples/statemachine/helloworld/main.cpp
index 13486d4..fbe34b5 100644
--- a/examples/statemachine/helloworld/main.cpp
+++ b/examples/statemachine/helloworld/main.cpp
@@ -52,7 +52,7 @@ public:
S0(QState *parent = 0)
: QState(parent) {}
- virtual void onEntry()
+ virtual void onEntry(QEvent *)
{
fprintf(stdout, "Hello world!\n");
}
diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp
index 68f7115..eb8fd5d 100644
--- a/examples/statemachine/pingpong/main.cpp
+++ b/examples/statemachine/pingpong/main.cpp
@@ -68,7 +68,7 @@ public:
: QState(parent) {}
protected:
- virtual void onEntry()
+ virtual void onEntry(QEvent *)
{
machine()->postEvent(new PingEvent());
fprintf(stdout, "ping?\n");
@@ -84,7 +84,7 @@ protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == QEvent::User+3);
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
machine()->postEvent(new PingEvent(), 500);
fprintf(stdout, "ping?\n");
@@ -100,7 +100,7 @@ protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == QEvent::User+2);
}
- virtual void onTransition()
+ virtual void onTransition(QEvent *)
{
machine()->postEvent(new PongEvent(), 500);
fprintf(stdout, "pong!\n");
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);
diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp
index 4e3fa11..7821feb 100644
--- a/src/gui/statemachine/qbasickeyeventtransition.cpp
+++ b/src/gui/statemachine/qbasickeyeventtransition.cpp
@@ -170,7 +170,7 @@ bool QBasicKeyEventTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QBasicKeyEventTransition::onTransition()
+void QBasicKeyEventTransition::onTransition(QEvent *)
{
}
diff --git a/src/gui/statemachine/qbasickeyeventtransition_p.h b/src/gui/statemachine/qbasickeyeventtransition_p.h
index de49eac..0d08da0 100644
--- a/src/gui/statemachine/qbasickeyeventtransition_p.h
+++ b/src/gui/statemachine/qbasickeyeventtransition_p.h
@@ -56,7 +56,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
- void onTransition();
+ void onTransition(QEvent *);
private:
Q_DISABLE_COPY(QBasicKeyEventTransition)
diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp
index 83254dc..0cb727e 100644
--- a/src/gui/statemachine/qbasicmouseeventtransition.cpp
+++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp
@@ -174,7 +174,7 @@ bool QBasicMouseEventTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QBasicMouseEventTransition::onTransition()
+void QBasicMouseEventTransition::onTransition(QEvent *)
{
}
diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h
index 77fbd58..20c7f8f 100644
--- a/src/gui/statemachine/qbasicmouseeventtransition_p.h
+++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h
@@ -59,7 +59,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
- void onTransition();
+ void onTransition(QEvent *);
private:
Q_DISABLE_COPY(QBasicMouseEventTransition)
diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp
index 37f4dd9..e6ab11b 100644
--- a/src/gui/statemachine/qkeyeventtransition.cpp
+++ b/src/gui/statemachine/qkeyeventtransition.cpp
@@ -153,9 +153,9 @@ bool QKeyEventTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QKeyEventTransition::onTransition()
+void QKeyEventTransition::onTransition(QEvent *event)
{
- QEventTransition::onTransition();
+ QEventTransition::onTransition(event);
}
QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h
index fa95c1b..3f797f1 100644
--- a/src/gui/statemachine/qkeyeventtransition.h
+++ b/src/gui/statemachine/qkeyeventtransition.h
@@ -45,7 +45,7 @@ public:
void setModifiersMask(Qt::KeyboardModifiers modifiers);
protected:
- void onTransition();
+ void onTransition(QEvent *event);
bool eventTest(QEvent *event) const;
private:
diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp
index 353b833..3191a2f 100644
--- a/src/gui/statemachine/qmouseeventtransition.cpp
+++ b/src/gui/statemachine/qmouseeventtransition.cpp
@@ -183,9 +183,9 @@ bool QMouseEventTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
-void QMouseEventTransition::onTransition()
+void QMouseEventTransition::onTransition(QEvent *event)
{
- QEventTransition::onTransition();
+ QEventTransition::onTransition(event);
}
QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h
index d5fb565..eee971e 100644
--- a/src/gui/statemachine/qmouseeventtransition.h
+++ b/src/gui/statemachine/qmouseeventtransition.h
@@ -51,7 +51,7 @@ public:
void setPath(const QPainterPath &path);
protected:
- void onTransition();
+ void onTransition(QEvent *event);
bool eventTest(QEvent *event) const;
private:
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 5dfc758..94afe51 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -186,10 +186,10 @@ public:
: QState(parent) {}
QList<QPair<int, Event> > events;
protected:
- virtual void onEntry() {
+ virtual void onEntry(QEvent *) {
events.append(qMakePair(globalTick++, Entry));
}
- virtual void onExit() {
+ virtual void onExit(QEvent *) {
events.append(qMakePair(globalTick++, Exit));
}
};
@@ -204,7 +204,7 @@ protected:
virtual bool eventTest(QEvent *) const {
return true;
}
- virtual void onTransition() {
+ virtual void onTransition(QEvent *) {
triggers.append(globalTick++);
}
};
@@ -246,7 +246,7 @@ protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == m_type);
}
- virtual void onTransition() {}
+ virtual void onTransition(QEvent *) {}
private:
QEvent::Type m_type;
};
@@ -380,7 +380,7 @@ public:
{
}
- void onEntry()
+ void onEntry(QEvent *)
{
error = m_machine->error();
errorString = m_machine->errorString();
@@ -1367,7 +1367,7 @@ protected:
StringEvent *se = static_cast<StringEvent*>(e);
return (m_value == se->value) && (!m_cond.isValid() || (m_cond.indexIn(m_value) != -1));
}
- virtual void onTransition() {}
+ virtual void onTransition(QEvent *) {}
private:
QString m_value;
@@ -1384,11 +1384,11 @@ public:
{ m_value = value; }
protected:
- virtual void onEntry()
+ virtual void onEntry(QEvent *)
{
m_machine->postEvent(new StringEvent(m_value));
}
- virtual void onExit() {}
+ virtual void onExit(QEvent *) {}
private:
QStateMachine *m_machine;