summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-04-24 09:58:57 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-04-24 09:58:57 (GMT)
commitdfe6974c1e7103ad46fa1162d7c9fd6a426894b7 (patch)
tree94b0475734945c9de24a472f70c3bedcd485aee6
parent686f82e51124747cbe650d04dfb053830b6660fa (diff)
parent221ec8dae1b247d5f8fb03d947d13cb6541a5805 (diff)
downloadQt-dfe6974c1e7103ad46fa1162d7c9fd6a426894b7.zip
Qt-dfe6974c1e7103ad46fa1162d7c9fd6a426894b7.tar.gz
Qt-dfe6974c1e7103ad46fa1162d7c9fd6a426894b7.tar.bz2
Merge branch 'kinetic-statemachine' into kinetic-animations
Conflicts: examples/animation/piemenu/qgraphicspiemenu_p.h
-rw-r--r--doc/src/statemachine.qdoc7
-rw-r--r--examples/animation/appchooser/main.cpp2
-rw-r--r--examples/animation/example/mainwindow.cpp6
-rw-r--r--examples/animation/moveblocks/main.cpp2
-rw-r--r--examples/animation/stickman/lifecycle.cpp16
-rw-r--r--examples/animation/stickman/lifecycle.h1
-rw-r--r--examples/animation/stickman/main.cpp2
-rw-r--r--examples/statemachine/composition/main.cpp4
-rw-r--r--examples/statemachine/trafficlight/main.cpp6
-rw-r--r--src/corelib/statemachine/qabstractstate.cpp89
-rw-r--r--src/corelib/statemachine/qabstractstate.h13
-rw-r--r--src/corelib/statemachine/qabstractstate_p.h4
-rw-r--r--src/corelib/statemachine/qactionstate.cpp293
-rw-r--r--src/corelib/statemachine/qactionstate.h102
-rw-r--r--src/corelib/statemachine/qactionstate_p.h83
-rw-r--r--src/corelib/statemachine/qactiontransition.cpp230
-rw-r--r--src/corelib/statemachine/qactiontransition.h96
-rw-r--r--src/corelib/statemachine/qactiontransition_p.h80
-rw-r--r--src/corelib/statemachine/qeventtransition.cpp21
-rw-r--r--src/corelib/statemachine/qeventtransition.h7
-rw-r--r--src/corelib/statemachine/qeventtransition_p.h4
-rw-r--r--src/corelib/statemachine/qfinalstate.cpp10
-rw-r--r--src/corelib/statemachine/qfinalstate.h6
-rw-r--r--src/corelib/statemachine/qsignaltransition.cpp15
-rw-r--r--src/corelib/statemachine/qsignaltransition.h7
-rw-r--r--src/corelib/statemachine/qsignaltransition_p.h4
-rw-r--r--src/corelib/statemachine/qstate.cpp22
-rw-r--r--src/corelib/statemachine/qstate.h8
-rw-r--r--src/corelib/statemachine/qstate_p.h4
-rw-r--r--src/corelib/statemachine/qstateaction.cpp356
-rw-r--r--src/corelib/statemachine/qstateaction.h119
-rw-r--r--src/corelib/statemachine/qstateaction_p.h107
-rw-r--r--src/corelib/statemachine/qstatefinishedtransition.cpp17
-rw-r--r--src/corelib/statemachine/qstatefinishedtransition.h7
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp171
-rw-r--r--src/corelib/statemachine/qstatemachine.h30
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h11
-rw-r--r--src/corelib/statemachine/statemachine.pri9
-rw-r--r--tests/auto/qanimationstate/qanimationstate.pro5
-rw-r--r--tests/auto/qanimationstate/tst_qanimationstate.cpp625
-rw-r--r--tests/auto/qstate/tst_qstate.cpp25
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp1036
42 files changed, 1178 insertions, 2484 deletions
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc
index 3051d19..97c09b9 100644
--- a/doc/src/statemachine.qdoc
+++ b/doc/src/statemachine.qdoc
@@ -91,13 +91,12 @@
When any of the states is entered, the label's text will be changed
accordingly.
- The QActionState::invokeMethodOnEntry() function can be used to have a state
- invoke a method (a slot) of a QObject when the state is entered. In the
+ The QActionState::entered() signal is emitted when the state is entered. In the
following snippet, the button's showMaximized() slot will be called when
state \c s3 is entered:
\code
- s2->invokeMethodOnEntry(button, "showMaximized");
+ QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized()));
\endcode
\section1 Sharing Transitions By Grouping States
@@ -209,7 +208,7 @@
mbox.addButton(QMessageBox::Ok);
mbox.setText("Interrupted!");
mbox.setIcon(QMessageBox::Information);
- s3->invokeMethodOnEntry(&mbox, "exec");
+ QObject::connect(s3, SIGNAL(entered()), &mbox, SLOT(exec()));
s3->addTransition(s1h);
machine.addState(s3);
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
index 7573347..02302d9 100644
--- a/examples/animation/appchooser/main.cpp
+++ b/examples/animation/appchooser/main.cpp
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *group = new QState(machine.rootState());
group->setObjectName("group");
diff --git a/examples/animation/example/mainwindow.cpp b/examples/animation/example/mainwindow.cpp
index 3770513..4aff384 100644
--- a/examples/animation/example/mainwindow.cpp
+++ b/examples/animation/example/mainwindow.cpp
@@ -203,9 +203,9 @@ MainWindow::MainWindow() : QMainWindow(0)
setCentralWidget(view);
- state3->invokeMethodOnEntry(this, "onEnterState3");
- state2->invokeMethodOnEntry(this, "onEnterState2");
- state1->invokeMethodOnEntry(this, "onEnterState1");
+ QObject::connect(state3, SIGNAL(entered()), this, SLOT(onEnterState3()));
+ QObject::connect(state2, SIGNAL(entered()), this, SLOT(onEnterState2()));
+ QObject::connect(state1, SIGNAL(entered()), this, SLOT(onEnterState1()));
connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
connect(button3, SIGNAL(clicked()), this, SLOT(onRemoveClicked()));
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
index 076da59..eb23bd5 100644
--- a/examples/animation/moveblocks/main.cpp
+++ b/examples/animation/moveblocks/main.cpp
@@ -202,7 +202,7 @@ int main(int argc, char **argv)
QTimer timer;
timer.setInterval(1250);
timer.setSingleShot(true);
- group->invokeMethodOnEntry(&timer, "start");
+ QObject::connect(group, SIGNAL(entered()), &timer, SLOT(start()));
QState *state1;
QState *state2;
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 4f2ac6d..df69d47 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -111,14 +111,12 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Set up intial state graph
m_machine = new QStateMachine();
- m_machine->setGlobalRestorePolicy(QState::RestoreProperties);
m_alive = new QState(m_machine->rootState());
m_alive->setObjectName("alive");
// Make it blink when lightning strikes before entering dead animation
QState *lightningBlink = new QState(m_machine->rootState());
- lightningBlink->setRestorePolicy(QState::DoNotRestoreProperties);
lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white);
lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black);
lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
@@ -127,11 +125,10 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
QTimer *timer = new QTimer(lightningBlink);
timer->setSingleShot(true);
timer->setInterval(100);
- lightningBlink->invokeMethodOnEntry(timer, "start");
- lightningBlink->invokeMethodOnExit(timer, "stop");
+ QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
m_dead = new QState(m_machine->rootState());
- m_dead->setRestorePolicy(QState::DoNotRestoreProperties);
m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
m_dead->assignProperty(m_stickMan, "penColor", Qt::white);
m_dead->assignProperty(m_stickMan, "fillColor", Qt::black);
@@ -151,15 +148,6 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
m_machine->setInitialState(m_alive);
}
-void LifeCycle::setResetKey(Qt::Key resetKey)
-{
- // When resetKey is pressed, enter the idle state and do a restoration animation
- // (requires no animation pointer, since no property is being set in the idle state)
- KeyPressTransition *trans = new KeyPressTransition(m_keyReceiver, resetKey, m_idle);
- trans->addAnimation(m_animationGroup);
- m_alive->addTransition(trans);
-}
-
void LifeCycle::setDeathAnimation(const QString &fileName)
{
QState *deathAnimation = makeState(m_dead, fileName);
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
index 4ca6ffd..e520402 100644
--- a/examples/animation/stickman/lifecycle.h
+++ b/examples/animation/stickman/lifecycle.h
@@ -58,7 +58,6 @@ public:
~LifeCycle();
void setDeathAnimation(const QString &fileName);
- void setResetKey(Qt::Key key);
void addActivity(const QString &fileName, Qt::Key key);
void start();
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index 6ff437d..62d8252 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -64,7 +64,6 @@ int main(int argc, char **argv)
"<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>"
"<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>"
"<li>Press <font color=\"purple\">C</font> to make him chill out.</li>"
- "<li>Press <font color=\"purple\">Return</font> to make him return to his original position.</li>"
"<li>When you are done, press <font color=\"purple\">Escape</font>.</li>"
"</i></p>"
"<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
@@ -87,7 +86,6 @@ int main(int argc, char **argv)
view->setSceneRect(scene->sceneRect());
LifeCycle *cycle = new LifeCycle(stickMan, view);
- cycle->setResetKey(Qt::Key_Return);
cycle->setDeathAnimation("animations/dead");
cycle->addActivity("animations/jumping", Qt::Key_J);
diff --git a/examples/statemachine/composition/main.cpp b/examples/statemachine/composition/main.cpp
index 24b823c..927fc62 100644
--- a/examples/statemachine/composition/main.cpp
+++ b/examples/statemachine/composition/main.cpp
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
s1_timer->setObjectName("s1_timer");
QTimer t1;
t1.setInterval(2000);
- s1_timer->invokeMethodOnEntry(&t1, "start");
+ QObject::connect(s1_timer, SIGNAL(entered()), &t1, SLOT(start()));
QFinalState *s1_done = new QFinalState(s1);
s1_done->setObjectName("s1_done");
s1_timer->addTransition(&t1, SIGNAL(timeout()), s1_done);
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
s2_timer->setObjectName("s2_timer");
QTimer t2;
t2.setInterval(2000);
- s2_timer->invokeMethodOnEntry(&t2, "start");
+ QObject::connect(s2_timer, SIGNAL(entered()), &t2, SLOT(start()));
QFinalState *s2_done = new QFinalState(s2);
s2_done->setObjectName("s2_done");
s2_timer->addTransition(&t2, SIGNAL(timeout()), s2_done);
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
index 528ed00..115ecad 100644
--- a/examples/statemachine/trafficlight/main.cpp
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -97,9 +97,9 @@ public:
timer->setInterval(duration);
timer->setSingleShot(true);
QState *timing = new QState(this);
- timing->invokeMethodOnEntry(light, "turnOn");
- timing->invokeMethodOnEntry(timer, "start");
- timing->invokeMethodOnExit(light, "turnOff");
+ QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
+ QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
QFinalState *done = new QFinalState(this);
timing->addTransition(timer, SIGNAL(timeout()), done);
setInitialState(timing);
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 89dcff9..396063a 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -62,6 +62,9 @@ QT_BEGIN_NAMESPACE
The assignProperty() function is used for defining property assignments that
should be performed when a state is entered.
+ The entered() signal is emitted when the state has been entered. The
+ exited() signal is emitted when the state has been exited.
+
The parentState() function returns the state's parent state.
\section1 Subclassing
@@ -73,45 +76,7 @@ QT_BEGIN_NAMESPACE
function to perform custom processing when the state is exited.
*/
-/*!
- \enum QAbstractState::RestorePolicy
-
- This enum specifies the restore policy type for a state. The restore policy
- takes effect when the machine enters a state which sets one or more
- properties. If the restore policy of the state is set to RestoreProperties,
- the state machine will save the original value of the property before the
- new value is set.
-
- Later, when the machine either enters a state which has its restore policy
- set to DoNotRestoreProperties or when it enters a state which does not set
- a value for the given property, the property will automatically be restored
- to its initial value.
-
- Only one initial value will be saved for any given property. If a value for a property has
- already been saved by the state machine, it will not be overwritten until the property has been
- successfully restored. Once the property has been restored, the state machine will clear the
- initial value until it enters a new state which sets the property and which has RestoreProperties
- as its restore policy.
-
- \value GlobalRestorePolicy The restore policy for the state should be retrieved using
- QStateMachine::globalRestorePolicy()
- \value DoNotRestoreProperties The state machine should not save the initial values of properties
- set in the state and restore them later.
- \value RestoreProperties The state machine should save the initial values of properties
- set in the state and restore them later.
-
-
- \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
-*/
-
-/*!
- \property QAbstractState::restorePolicy
-
- \brief the restore policy of this state
-*/
-
-QAbstractStatePrivate::QAbstractStatePrivate()
- : restorePolicy(QAbstractState::GlobalRestorePolicy)
+QAbstractStatePrivate::QAbstractStatePrivate()
{
}
@@ -149,6 +114,18 @@ void QAbstractStatePrivate::callOnExit()
q->onExit();
}
+void QAbstractStatePrivate::emitEntered()
+{
+ Q_Q(QAbstractState);
+ emit q->entered();
+}
+
+void QAbstractStatePrivate::emitExited()
+{
+ Q_Q(QAbstractState);
+ emit q->exited();
+}
+
/*!
Constructs a new state with the given \a parent state.
*/
@@ -222,26 +199,6 @@ void QAbstractState::assignProperty(QObject *object, const char *name,
}
/*!
- Sets the restore policy of this state to \a restorePolicy.
-
- The default restore policy is QAbstractState::GlobalRestorePolicy.
-*/
-void QAbstractState::setRestorePolicy(RestorePolicy restorePolicy)
-{
- Q_D(QAbstractState);
- d->restorePolicy = restorePolicy;
-}
-
-/*!
- Returns the restore policy for this state.
-*/
-QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
-{
- Q_D(const QAbstractState);
- return d->restorePolicy;
-}
-
-/*!
\fn QAbstractState::onExit()
This function is called when the state is exited. Reimplement this function
@@ -256,6 +213,20 @@ QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
*/
/*!
+ \fn QAbstractState::entered()
+
+ This signal is emitted when the state has been entered (after onEntry() has
+ been called).
+*/
+
+/*!
+ \fn QAbstractState::exited()
+
+ This signal is emitted when the state has been exited (after onExit() has
+ been called).
+*/
+
+/*!
\reimp
*/
bool QAbstractState::event(QEvent *e)
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index b788a88..69e6bf1 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -56,15 +56,7 @@ class QAbstractStatePrivate;
class Q_CORE_EXPORT QAbstractState : public QObject
{
Q_OBJECT
- Q_ENUMS(RestorePolicy)
- Q_PROPERTY(RestorePolicy restorePolicy READ restorePolicy WRITE setRestorePolicy)
public:
- enum RestorePolicy {
- GlobalRestorePolicy,
- DoNotRestoreProperties,
- RestoreProperties
- };
-
~QAbstractState();
QState *parentState() const;
@@ -72,8 +64,9 @@ public:
void assignProperty(QObject *object, const char *name,
const QVariant &value);
- void setRestorePolicy(RestorePolicy restorePolicy);
- RestorePolicy restorePolicy() const;
+Q_SIGNALS:
+ void entered();
+ void exited();
protected:
QAbstractState(QState *parent = 0);
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index 7c565f0..8c8f436 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -98,7 +98,9 @@ public:
void callOnEntry();
void callOnExit();
- QAbstractState::RestorePolicy restorePolicy;
+ void emitEntered();
+ void emitExited();
+
QList<QPropertyAssignment> propertyAssignments;
#ifdef QT_STATEMACHINE_SOLUTION
diff --git a/src/corelib/statemachine/qactionstate.cpp b/src/corelib/statemachine/qactionstate.cpp
deleted file mode 100644
index 1da0350..0000000
--- a/src/corelib/statemachine/qactionstate.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qactionstate.h"
-#include "qactionstate_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QActionState
-
- \brief The QActionState class provides an action-based state.
-
- \since 4.6
- \ingroup statemachine
-
- QActionState executes \l{QStateAction}{state actions} when the state is
- entered and exited. QActionState is part of \l{The State Machine Framework}.
-
- You can add actions to a state with the addEntryAction() and addExitAction()
- functions. The state executes the actions when the state is entered and
- exited, respectively.
-
- The invokeMethodOnEntry() and invokeMethodOnExit() functions are used for
- defining method invocations that should be performed when a state is entered
- and exited, respectively.
-
- \code
- QState *s2 = new QState();
- s2->invokeMethodOnEntry(&label, "showMaximized");
- machine.addState(s2);
- \endcode
-
- \sa QStateAction
-*/
-
-QActionStatePrivate::QActionStatePrivate()
-{
-}
-
-QActionStatePrivate::~QActionStatePrivate()
-{
-}
-
-QActionStatePrivate *QActionStatePrivate::get(QActionState *q)
-{
- return q->d_func();
-}
-
-const QActionStatePrivate *QActionStatePrivate::get(const QActionState *q)
-{
- return q->d_func();
-}
-
-QList<QStateAction*> QActionStatePrivate::entryActions() const
-{
- QList<QStateAction*> result;
- QList<QObject*>::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *act = qobject_cast<QStateAction*>(*it);
- if (act && (QStateActionPrivate::get(act)->when == QStateActionPrivate::ExecuteOnEntry))
- result.append(act);
- }
- return result;
-}
-
-QList<QStateAction*> QActionStatePrivate::exitActions() const
-{
- QList<QStateAction*> result;
- QList<QObject*>::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *act = qobject_cast<QStateAction*>(*it);
- if (act && (QStateActionPrivate::get(act)->when == QStateActionPrivate::ExecuteOnExit))
- result.append(act);
- }
- return result;
-}
-
-/*!
- Constructs a new action state with the given \a parent state.
-*/
-QActionState::QActionState(QState *parent)
- : QAbstractState(*new QActionStatePrivate, parent)
-{
-}
-
-/*!
- \internal
-*/
-QActionState::QActionState(QActionStatePrivate &dd,
- QState *parent)
- : QAbstractState(dd, parent)
-{
-}
-
-/*!
- Destroys this action state.
-*/
-QActionState::~QActionState()
-{
-}
-
-/*!
- Instructs this state to invoke the given \a method of the given \a object
- with the given \a arguments when the state is entered. This function will
- create a QStateInvokeMethodAction object and add it to the entry actions of
- the state.
-
- \sa invokeMethodOnExit(), addEntryAction()
-*/
-void QActionState::invokeMethodOnEntry(QObject *object, const char *method,
- const QList<QVariant> &arguments)
-{
- addEntryAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Instructs this state to invoke the given \a method of the given \a object
- with the given \a arguments when the state is exited. This function will
- create a QStateInvokeMethodAction object and add it to the exit actions of
- the state.
-
- \sa invokeMethodOnEntry(), addExitAction()
-*/
-void QActionState::invokeMethodOnExit(QObject *object, const char *method,
- const QList<QVariant> &arguments)
-{
- addExitAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Adds the given \a action to this state. The action will be executed when
- this state is entered. The state takes ownership of the action.
-
- \sa addExitAction(), removeEntryAction()
-*/
-void QActionState::addEntryAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::addEntryAction: cannot add null action");
- return;
- }
- action->setParent(this);
- QStateActionPrivate::get(action)->when = QStateActionPrivate::ExecuteOnEntry;
-}
-
-/*!
- Adds the given \a action to this state. The action will be executed when
- this state is exited. The state takes ownership of the action.
-
- \sa addEntryAction(), removeExitAction()
-*/
-void QActionState::addExitAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::addExitAction: cannot add null action");
- return;
- }
- action->setParent(this);
- QStateActionPrivate::get(action)->when = QStateActionPrivate::ExecuteOnExit;
-}
-
-/*!
- Removes the given entry \a action from this state. The state releases
- ownership of the action.
-
- \sa addEntryAction()
-*/
-void QActionState::removeEntryAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::removeEntryAction: cannot remove null action");
- return;
- }
- if (action->parent() == this)
- action->setParent(0);
-}
-
-/*!
- Removes the given exit \a action from this state. The state releases
- ownership of the action.
-
- \sa addExitAction()
-*/
-void QActionState::removeExitAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::removeExitAction: cannot remove null action");
- return;
- }
- if (action->parent() == this)
- action->setParent(0);
-}
-
-/*!
- Returns this state's entry actions.
-
- \sa addEntryAction(), exitActions()
-*/
-QList<QStateAction*> QActionState::entryActions() const
-{
- Q_D(const QActionState);
- return d->entryActions();
-}
-
-/*!
- Returns this state's exit actions.
-
- \sa addExitAction(), entryActions()
-*/
-QList<QStateAction*> QActionState::exitActions() const
-{
- Q_D(const QActionState);
- return d->exitActions();
-}
-
-/*!
- \reimp
-*/
-void QActionState::onEntry()
-{
- Q_D(QActionState);
- QList<QStateAction*> actions = d->entryActions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-void QActionState::onExit()
-{
- Q_D(QActionState);
- QList<QStateAction*> actions = d->exitActions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-bool QActionState::event(QEvent *e)
-{
- return QAbstractState::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qactionstate.h b/src/corelib/statemachine/qactionstate.h
deleted file mode 100644
index 517b4b2..0000000
--- a/src/corelib/statemachine/qactionstate.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONSTATE_H
-#define QACTIONSTATE_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qabstractstate.h>
-#else
-#include "qabstractstate.h"
-#endif
-
-#include <QtCore/qlist.h>
-#include <QtCore/qvariant.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateAction;
-
-class QActionStatePrivate;
-class Q_CORE_EXPORT QActionState : public QAbstractState
-{
- Q_OBJECT
-public:
- QActionState(QState *parent = 0);
- ~QActionState();
-
- void invokeMethodOnEntry(QObject *object, const char *method,
- const QList<QVariant> &args = QList<QVariant>());
- void invokeMethodOnExit(QObject *object, const char *method,
- const QList<QVariant> &args = QList<QVariant>());
-
- void addEntryAction(QStateAction *action);
- void addExitAction(QStateAction *action);
-
- void removeEntryAction(QStateAction *action);
- void removeExitAction(QStateAction *action);
-
- QList<QStateAction*> entryActions() const;
- QList<QStateAction*> exitActions() const;
-
-protected:
- void onEntry();
- void onExit();
-
- bool event(QEvent *e);
-
-protected:
- QActionState(QActionStatePrivate &dd, QState *parent);
-
-private:
- Q_DISABLE_COPY(QActionState)
- Q_DECLARE_PRIVATE(QActionState)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qactionstate_p.h b/src/corelib/statemachine/qactionstate_p.h
deleted file mode 100644
index a06dde2..0000000
--- a/src/corelib/statemachine/qactionstate_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONSTATE_P_H
-#define QACTIONSTATE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qabstractstate_p.h"
-#include "qactionstate.h"
-
-#include <QtCore/qlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-
-class QActionState;
-class Q_CORE_EXPORT QActionStatePrivate : public QAbstractStatePrivate
-{
- Q_DECLARE_PUBLIC(QActionState)
-
-public:
- QActionStatePrivate();
- ~QActionStatePrivate();
-
- static QActionStatePrivate *get(QActionState *q);
- static const QActionStatePrivate *get(const QActionState *q);
-
- QList<QStateAction*> entryActions() const;
- QList<QStateAction*> exitActions() const;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qactiontransition.cpp b/src/corelib/statemachine/qactiontransition.cpp
deleted file mode 100644
index 7c53e15..0000000
--- a/src/corelib/statemachine/qactiontransition.cpp
+++ /dev/null
@@ -1,230 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qactiontransition.h"
-#include "qactiontransition_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QActionTransition
-
- \brief The QActionTransition class provides an action-based transition.
-
- \since 4.6
- \ingroup statemachine
-
- QActionTransition provides an action-based transition; you add actions with
- the addAction() function. The transition executes the actions when the
- transition is triggered. QActionTransition is part of \l{The State Machine
- Framework}.
-
- The invokeMethodOnTransition() function is used for defining method
- invocations that should be performed when a transition is taken.
-
- \code
- QStateMachine machine;
- QState *s1 = new QState();
- machine.addState(s1);
- QActionTransition *t1 = new QActionTransition();
- QLabel label;
- t1->invokeMethodOnTransition(&label, "clear");
- QState *s2 = new QState();
- machine.addState(s2);
- t1->setTargetState(s2);
- s1->addTransition(t1);
- \endcode
-
- Actions are executed in the order in which they were added.
-
- \sa QState::addTransition(), QStateAction
-*/
-
-QActionTransitionPrivate::QActionTransitionPrivate()
-{
-}
-
-QActionTransitionPrivate::~QActionTransitionPrivate()
-{
-}
-
-QActionTransitionPrivate *QActionTransitionPrivate::get(QActionTransition *q)
-{
- return q->d_func();
-}
-
-const QActionTransitionPrivate *QActionTransitionPrivate::get(const QActionTransition *q)
-{
- return q->d_func();
-}
-
-QList<QStateAction*> QActionTransitionPrivate::actions() const
-{
- QList<QStateAction*> result;
- QList<QObject*>::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *s = qobject_cast<QStateAction*>(*it);
- if (s)
- result.append(s);
- }
- return result;
-}
-
-/*!
- Constructs a new QActionTransition object with the given \a sourceState.
-*/
-QActionTransition::QActionTransition(QState *sourceState)
- : QAbstractTransition(*new QActionTransitionPrivate, sourceState)
-{
-}
-
-/*!
- Constructs a new QActionTransition object with the given \a targets and \a
- sourceState.
-*/
-QActionTransition::QActionTransition(const QList<QAbstractState*> &targets, QState *sourceState)
- : QAbstractTransition(*new QActionTransitionPrivate, targets, sourceState)
-{
-}
-
-/*!
- \internal
-*/
-QActionTransition::QActionTransition(QActionTransitionPrivate &dd, QState *parent)
- : QAbstractTransition(dd, parent)
-{
-}
-
-/*!
- \internal
-*/
-QActionTransition::QActionTransition(QActionTransitionPrivate &dd, const QList<QAbstractState*> &targets, QState *parent)
- : QAbstractTransition(dd, targets, parent)
-{
-}
-
-/*!
- Destroys this transition.
-*/
-QActionTransition::~QActionTransition()
-{
-}
-
-/*!
- Instructs this QActionTransition to invoke the given \a method of the given \a
- object with the given \a arguments when the transition is taken. This
- function will create a QStateInvokeMethodAction object and add it to the
- actions of the transition.
-*/
-void QActionTransition::invokeMethodOnTransition(QObject *object, const char *method,
- const QList<QVariant> &arguments)
-{
- addAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Adds the given \a action to this transition.
- The action will be executed when the transition is triggered.
- The transition takes ownership of the action.
-
- \sa removeAction()
-*/
-void QActionTransition::addAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionTransition::addAction: cannot add null action");
- return;
- }
- action->setParent(this);
-}
-
-/*!
- Removes the given \a action from this transition.
- The transition releases ownership of the action.
-
- \sa addAction()
-*/
-void QActionTransition::removeAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionTransition::removeAction: cannot remove null action");
- return;
- }
- action->setParent(0);
-}
-
-/*!
- Returns this transitions's actions, or an empty list if the transition has
- no actions.
-
- \sa addAction()
-*/
-QList<QStateAction*> QActionTransition::actions() const
-{
- Q_D(const QActionTransition);
- return d->actions();
-}
-
-/*!
- \reimp
-*/
-void QActionTransition::onTransition()
-{
- Q_D(QActionTransition);
- QList<QStateAction*> actions = d->actions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-bool QActionTransition::event(QEvent *e)
-{
- return QAbstractTransition::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qactiontransition.h b/src/corelib/statemachine/qactiontransition.h
deleted file mode 100644
index 1a779fa..0000000
--- a/src/corelib/statemachine/qactiontransition.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONTRANSITION_H
-#define QACTIONTRANSITION_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qabstracttransition.h>
-#else
-#include "qabstracttransition.h"
-#endif
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qlist.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateAction;
-
-class QActionTransitionPrivate;
-class Q_CORE_EXPORT QActionTransition : public QAbstractTransition
-{
- Q_OBJECT
-public:
- QActionTransition(QState *sourceState = 0);
- QActionTransition(const QList<QAbstractState*> &targets, QState *sourceState = 0);
- ~QActionTransition();
-
- void invokeMethodOnTransition(QObject *object, const char *method,
- const QList<QVariant> &args = QList<QVariant>());
-
- void addAction(QStateAction *action);
- void removeAction(QStateAction *action);
- QList<QStateAction*> actions() const;
-
-protected:
- virtual void onTransition();
-
- bool event(QEvent *e);
-
-protected:
- QActionTransition(QActionTransitionPrivate &dd, QState *parent);
- QActionTransition(QActionTransitionPrivate &dd, const QList<QAbstractState*> &targets, QState *parent);
-
-private:
- Q_DISABLE_COPY(QActionTransition)
- Q_DECLARE_PRIVATE(QActionTransition)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qactiontransition_p.h b/src/corelib/statemachine/qactiontransition_p.h
deleted file mode 100644
index 34f80d1..0000000
--- a/src/corelib/statemachine/qactiontransition_p.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONTRANSITION_P_H
-#define QACTIONTRANSITION_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qabstracttransition_p.h"
-
-#include <QtCore/qlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-
-class QActionTransition;
-class Q_CORE_EXPORT QActionTransitionPrivate : public QAbstractTransitionPrivate
-{
- Q_DECLARE_PUBLIC(QActionTransition)
-public:
- QActionTransitionPrivate();
- ~QActionTransitionPrivate();
-
- static QActionTransitionPrivate *get(QActionTransition *q);
- static const QActionTransitionPrivate *get(const QActionTransition *q);
-
- QList<QStateAction*> actions() const;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp
index 87ed77a..09b89f3 100644
--- a/src/corelib/statemachine/qeventtransition.cpp
+++ b/src/corelib/statemachine/qeventtransition.cpp
@@ -129,7 +129,7 @@ void QEventTransitionPrivate::invalidate()
Constructs a new QEventTransition object with the given \a sourceState.
*/
QEventTransition::QEventTransition(QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
{
}
@@ -139,7 +139,7 @@ QEventTransition::QEventTransition(QState *sourceState)
*/
QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
{
Q_D(QEventTransition);
d->registered = false;
@@ -155,7 +155,7 @@ QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
const QList<QAbstractState*> &targets,
QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, targets, sourceState)
{
Q_D(QEventTransition);
d->registered = false;
@@ -167,7 +167,7 @@ QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
\internal
*/
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)
- : QActionTransition(dd, parent)
+ : QAbstractTransition(dd, parent)
{
}
@@ -176,7 +176,7 @@ QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)
*/
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEvent::Type type, QState *parent)
- : QActionTransition(dd, parent)
+ : QAbstractTransition(dd, parent)
{
Q_D(QEventTransition);
d->registered = false;
@@ -190,7 +190,7 @@ QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEvent::Type type, const QList<QAbstractState*> &targets,
QState *parent)
- : QActionTransition(dd, targets, parent)
+ : QAbstractTransition(dd, targets, parent)
{
Q_D(QEventTransition);
d->registered = false;
@@ -268,6 +268,13 @@ bool QEventTransition::eventTest(QEvent *event) const
}
/*!
+ \reimp
+*/
+void QEventTransition::onTransition()
+{
+}
+
+/*!
Tests an instance of an event associated with this event transition and
returns true if the transition should be taken, otherwise returns false.
The type of the given \a event will be eventType().
@@ -286,7 +293,7 @@ bool QEventTransition::testEventCondition(QEvent *event) const
*/
bool QEventTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h
index 21a696c..e19b5af 100644
--- a/src/corelib/statemachine/qeventtransition.h
+++ b/src/corelib/statemachine/qeventtransition.h
@@ -43,9 +43,9 @@
#define QEVENTTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qactiontransition.h>
+#include <QtCore/qabstracttransition.h>
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
#include <QtCore/qcoreevent.h>
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QEventTransitionPrivate;
-class Q_CORE_EXPORT QEventTransition : public QActionTransition
+class Q_CORE_EXPORT QEventTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QObject* object READ eventSource WRITE setEventSource)
@@ -80,6 +80,7 @@ protected:
virtual bool testEventCondition(QEvent *event) const; // ### name
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qeventtransition_p.h b/src/corelib/statemachine/qeventtransition_p.h
index 2bb5aaa..fca8c0d 100644
--- a/src/corelib/statemachine/qeventtransition_p.h
+++ b/src/corelib/statemachine/qeventtransition_p.h
@@ -53,12 +53,12 @@
// We mean it.
//
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
class QEventTransition;
-class Q_CORE_EXPORT QEventTransitionPrivate : public QActionTransitionPrivate
+class Q_CORE_EXPORT QEventTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QEventTransition)
public:
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
index abf9d2e..16e080e 100644
--- a/src/corelib/statemachine/qfinalstate.cpp
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
#include "qfinalstate.h"
-#include "qactionstate_p.h"
+#include "qabstractstate_p.h"
QT_BEGIN_NAMESPACE
@@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
\sa QStateFinishedTransition
*/
-class QFinalStatePrivate : public QActionStatePrivate
+class QFinalStatePrivate : public QAbstractStatePrivate
{
Q_DECLARE_PUBLIC(QFinalState)
@@ -96,7 +96,7 @@ QFinalStatePrivate::QFinalStatePrivate()
Constructs a new QFinalState object with the given \a parent state.
*/
QFinalState::QFinalState(QState *parent)
- : QActionState(*new QFinalStatePrivate, parent)
+ : QAbstractState(*new QFinalStatePrivate, parent)
{
}
@@ -112,7 +112,6 @@ QFinalState::~QFinalState()
*/
void QFinalState::onEntry()
{
- QActionState::onEntry();
}
/*!
@@ -120,7 +119,6 @@ void QFinalState::onEntry()
*/
void QFinalState::onExit()
{
- QActionState::onExit();
}
/*!
@@ -128,7 +126,7 @@ void QFinalState::onExit()
*/
bool QFinalState::event(QEvent *e)
{
- return QActionState::event(e);
+ return QAbstractState::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qfinalstate.h b/src/corelib/statemachine/qfinalstate.h
index 36813f5..726a399 100644
--- a/src/corelib/statemachine/qfinalstate.h
+++ b/src/corelib/statemachine/qfinalstate.h
@@ -43,9 +43,9 @@
#define QFINALSTATE_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qactionstate.h>
+#include <QtCore/qabstractstate.h>
#else
-#include "qactionstate.h"
+#include "qabstractstate.h"
#endif
QT_BEGIN_HEADER
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QFinalStatePrivate;
-class Q_CORE_EXPORT QFinalState : public QActionState
+class Q_CORE_EXPORT QFinalState : public QAbstractState
{
Q_OBJECT
public:
diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp
index 32f2d02..064ac6e 100644
--- a/src/corelib/statemachine/qsignaltransition.cpp
+++ b/src/corelib/statemachine/qsignaltransition.cpp
@@ -137,7 +137,7 @@ void QSignalTransitionPrivate::invalidate()
Constructs a new signal transition with the given \a sourceState.
*/
QSignalTransition::QSignalTransition(QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
{
}
@@ -147,7 +147,7 @@ QSignalTransition::QSignalTransition(QState *sourceState)
*/
QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
{
Q_D(QSignalTransition);
d->sender = sender;
@@ -162,7 +162,7 @@ QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
const QList<QAbstractState*> &targets,
QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, targets, sourceState)
{
Q_D(QSignalTransition);
d->sender = sender;
@@ -245,9 +245,16 @@ bool QSignalTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
+void QSignalTransition::onTransition()
+{
+}
+
+/*!
+ \reimp
+*/
bool QSignalTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h
index c1a41ae..4df97cf 100644
--- a/src/corelib/statemachine/qsignaltransition.h
+++ b/src/corelib/statemachine/qsignaltransition.h
@@ -43,9 +43,9 @@
#define QSIGNALTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qactiontransition.h>
+#include <QtCore/qabstracttransition.h>
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
QT_BEGIN_HEADER
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QSignalTransitionPrivate;
-class Q_CORE_EXPORT QSignalTransition : public QActionTransition
+class Q_CORE_EXPORT QSignalTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QObject* object READ senderObject WRITE setSenderObject)
@@ -77,6 +77,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qsignaltransition_p.h b/src/corelib/statemachine/qsignaltransition_p.h
index bd815d9..a23e58c 100644
--- a/src/corelib/statemachine/qsignaltransition_p.h
+++ b/src/corelib/statemachine/qsignaltransition_p.h
@@ -53,12 +53,12 @@
// We mean it.
//
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
class QSignalTransition;
-class QSignalTransitionPrivate : public QActionTransitionPrivate
+class QSignalTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QSignalTransition)
public:
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index e3da1c5..56a855e 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -138,7 +138,7 @@ const QStatePrivate *QStatePrivate::get(const QState *q)
Constructs a new state with the given \a parent state.
*/
QState::QState(QState *parent)
- : QActionState(*new QStatePrivate, parent)
+ : QAbstractState(*new QStatePrivate, parent)
{
}
@@ -146,7 +146,7 @@ QState::QState(QState *parent)
Constructs a new state of the given \a type with the given \a parent state.
*/
QState::QState(Type type, QState *parent)
- : QActionState(*new QStatePrivate, parent)
+ : QAbstractState(*new QStatePrivate, parent)
{
Q_D(QState);
d->isParallelGroup = (type == ParallelGroup);
@@ -156,7 +156,7 @@ QState::QState(Type type, QState *parent)
\internal
*/
QState::QState(QStatePrivate &dd, QState *parent)
- : QActionState(dd, parent)
+ : QAbstractState(dd, parent)
{
}
@@ -245,30 +245,32 @@ void QState::setErrorState(QAbstractState *state)
/*!
Adds the given \a transition. The transition has this state as the source.
- This state takes ownership of the transition.
+ This state takes ownership of the transition. If the transition is successfully
+ added, the function will return the \a transition pointer. Otherwise it will return null.
*/
-void QState::addTransition(QAbstractTransition *transition)
+QAbstractTransition *QState::addTransition(QAbstractTransition *transition)
{
Q_D(QState);
if (!transition) {
qWarning("QState::addTransition: cannot add null transition");
- return;
+ return 0;
}
const QList<QAbstractState*> &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
for (int i = 0; i < targets.size(); ++i) {
QAbstractState *t = targets.at(i);
if (!t) {
qWarning("QState::addTransition: cannot add transition to null state");
- return;
+ return 0;
}
if ((QAbstractStatePrivate::get(t)->machine() != d->machine())
&& QAbstractStatePrivate::get(t)->machine() && d->machine()) {
qWarning("QState::addTransition: cannot add transition "
"to a state in a different state machine");
- return;
+ return 0;
}
}
transition->setParent(this);
+ return transition;
}
/*!
@@ -383,7 +385,6 @@ QHistoryState *QState::addHistoryState(HistoryType type)
*/
void QState::onEntry()
{
- QActionState::onEntry();
}
/*!
@@ -391,7 +392,6 @@ void QState::onEntry()
*/
void QState::onExit()
{
- QActionState::onExit();
}
/*!
@@ -428,7 +428,7 @@ void QState::setInitialState(QAbstractState *state)
*/
bool QState::event(QEvent *e)
{
- return QActionState::event(e);
+ return QAbstractState::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 4c86e02..7c64c80 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -43,9 +43,9 @@
#define QSTATE_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qactionstate.h>
+#include <QtCore/qabstractstate.h>
#else
-#include "qactionstate.h"
+#include "qabstractstate.h"
#endif
QT_BEGIN_HEADER
@@ -60,7 +60,7 @@ class QSignalTransition;
class QStateFinishedTransition;
class QStatePrivate;
-class Q_CORE_EXPORT QState : public QActionState
+class Q_CORE_EXPORT QState : public QAbstractState
{
Q_OBJECT
public:
@@ -81,7 +81,7 @@ public:
QAbstractState *errorState() const;
void setErrorState(QAbstractState *state);
- void addTransition(QAbstractTransition *transition);
+ QAbstractTransition *addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target);
QAbstractTransition *addTransition(QAbstractState *target);
QStateFinishedTransition *addFinishedTransition(QAbstractState *target);
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
index 17b312a..8d040d0 100644
--- a/src/corelib/statemachine/qstate_p.h
+++ b/src/corelib/statemachine/qstate_p.h
@@ -53,14 +53,14 @@
// We mean it.
//
-#include "qactionstate_p.h"
+#include "qabstractstate_p.h"
#include <QtCore/qlist.h>
QT_BEGIN_NAMESPACE
class QState;
-class Q_CORE_EXPORT QStatePrivate : public QActionStatePrivate
+class Q_CORE_EXPORT QStatePrivate : public QAbstractStatePrivate
{
Q_DECLARE_PUBLIC(QState)
public:
diff --git a/src/corelib/statemachine/qstateaction.cpp b/src/corelib/statemachine/qstateaction.cpp
deleted file mode 100644
index 569d5d5..0000000
--- a/src/corelib/statemachine/qstateaction.cpp
+++ /dev/null
@@ -1,356 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qmetaobject.h>
-
-QT_BEGIN_NAMESPACE
-
-QStateActionPrivate::QStateActionPrivate()
-{
- when = ExecuteOnEntry;
-}
-
-QStateActionPrivate::~QStateActionPrivate()
-{
-}
-
-QStateActionPrivate *QStateActionPrivate::get(QStateAction *q)
-{
- return q->d_func();
-}
-
-void QStateActionPrivate::callExecute()
-{
- Q_Q(QStateAction);
- q->execute();
-}
-
-/*!
- \class QStateAction
-
- \brief The QStateAction class is the base class of QState actions.
-
- \since 4.6
- \ingroup statemachine
-
- A state action is added to a state by calling QActionState::addEntryAction()
- or QActionState::addExitAction(). QStateAction is part of \l{The State
- Machine Framework}.
-
- \section1 Subclassing
-
- Subclasses must implement the execute() function.
-*/
-
-/*!
- Constructs a new QStateAction object with the given \a parent.
-*/
-QStateAction::QStateAction(QObject *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- *new QStateActionPrivate,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(new QStateActionPrivate)
-#endif
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
-}
-
-/*!
- \internal
-*/
-QStateAction::QStateAction(QStateActionPrivate &dd, QObject *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- dd,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(&dd)
-#endif
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
-}
-
-/*!
- Destroys this QStateAction object.
-*/
-QStateAction::~QStateAction()
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- delete d_ptr;
-#endif
-}
-
-/*!
- \fn QStateAction::execute()
-
- Executes this action.
-*/
-
-/*!
- \reimp
-*/
-bool QStateAction::event(QEvent *e)
-{
- return QObject::event(e);
-}
-
-QStateInvokeMethodActionPrivate *QStateInvokeMethodActionPrivate::get(QStateInvokeMethodAction *q)
-{
- return q->d_func();
-}
-
-/*!
- \class QStateInvokeMethodAction
-
- \brief The QStateInvokeMethodAction class provides an invoke method action for QObjects.
-
- \since 4.6
- \ingroup statemachine
-
- The QStateInvokeMethodAction class provides an action that calls a method of
- a QObject when a QState is entered or exited. QStateInvokeMethodAction is
- part of \l{The State Machine Framework}.
-
- Typically you don't construct QStateInvokeMethodAction objects directly, but
- rather call the QState::invokeMethodOnEntry() function or the
- QState::invokeMethodOnExit() function.
-*/
-
-/*!
- \property QStateInvokeMethodAction::arguments
-
- \brief the arguments to the method this action invokes
-*/
-
-/*!
- \property QStateInvokeMethodAction::methodName
-
- \brief the name of the method this action invokes
-*/
-
-/*!
- \property QStateInvokeMethodAction::target
-
- \brief the object on which this action invokes a method
-*/
-
-/*!
- Constructs a new QStateInvokeMethodAction object for the method named \a
- methodName of the given \a target object, with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(
- QObject *target, const QByteArray &methodName, QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
- d->methodName = methodName;
- d->methodIndex = -1;
-}
-
-/*!
- Constructs a new QStateInvokeMethodAction object for the method named \a
- methodName of the given \a target object, with the given arguments, \a args,
- and with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(
- QObject *target, const QByteArray &methodName,
- const QList<QVariant> &args, QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
- d->methodName = methodName;
- d->methodIndex = -1;
- d->args = args;
-}
-
-/*!
- Constructs a new QStateInvokeMethodAction object with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = 0;
- d->methodIndex = -1;
-}
-
-/*!
- Destroys this QStateInvokeMethodAction object.
-*/
-QStateInvokeMethodAction::~QStateInvokeMethodAction()
-{
-}
-
-/*!
- \reimp
-*/
-void QStateInvokeMethodAction::execute()
-{
- Q_D(QStateInvokeMethodAction);
- if (!d->target)
- return;
-
- if (d->methodIndex == -1) {
- QVarLengthArray<char, 512> sig;
- int len = d->methodName.length();
- if (len <= 0)
- return;
- sig.append(d->methodName, len);
- sig.append('(');
-
- int paramCount;
- for (paramCount = 0; paramCount < d->args.size() && paramCount < 10; ++paramCount) {
- const char *tn = d->args.at(paramCount).typeName();
- len = qstrlen(tn);
- if (len <= 0)
- break;
- sig.append(tn, len);
- sig.append(',');
- }
- if (paramCount == 0)
- sig.append(')'); // no parameters
- else
- sig[sig.size() - 1] = ')';
- sig.append('\0');
-
- const QMetaObject *meta = d->target->metaObject();
- int idx = meta->indexOfMethod(sig.constData());
- if (idx < 0) {
- QByteArray norm = QMetaObject::normalizedSignature(sig.constData());
- idx = meta->indexOfMethod(norm.constData());
- if ((idx < 0) || (idx >= meta->methodCount())) {
- qWarning("InvokeMethodAction: unable to find method '%s' of %s(%p)",
- sig.constData(), meta->className(), d->target);
- return;
- }
- }
- d->methodIndex = idx;
- }
-
- void *param[11];
- param[0] = 0; // return value
- for (int i = 0; i < 10; ++i)
- param[i+1] = (i < d->args.size()) ? const_cast<void*>(d->args.at(i).constData()) : (void*)0;
- (void)d->target->qt_metacall(QMetaObject::InvokeMetaMethod, d->methodIndex, param);
-}
-
-/*!
- Returns the object on which this action invokes a method.
-*/
-QObject *QStateInvokeMethodAction::targetObject() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->target;
-}
-
-/*!
- Sets the object on which this action invokes a method.
-*/
-void QStateInvokeMethodAction::setTargetObject(QObject *target)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
-}
-
-/*!
- Returns the name of the method this action will invoke.
-*/
-QByteArray QStateInvokeMethodAction::methodName() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->methodName;
-}
-
-/*!
- Sets the name of the method this action will invoke.
-*/
-void QStateInvokeMethodAction::setMethodName(const QByteArray &methodName)
-{
- Q_D(QStateInvokeMethodAction);
- if (methodName != d->methodName) {
- d->methodName = methodName;
- d->methodIndex = -1;
- }
-}
-
-/*!
- Returns the arguments to the method this action will invoke.
-*/
-QVariantList QStateInvokeMethodAction::arguments() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->args;
-}
-
-/*!
- Sets the arguments to the method this action will invoke.
-*/
-void QStateInvokeMethodAction::setArguments(const QVariantList &arguments)
-{
- Q_D(QStateInvokeMethodAction);
- if (d->args != arguments) {
- d->args = arguments;
- d->methodIndex = -1;
- }
-}
-
-/*!
- \reimp
-*/
-bool QStateInvokeMethodAction::event(QEvent *e)
-{
- return QStateAction::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstateaction.h b/src/corelib/statemachine/qstateaction.h
deleted file mode 100644
index 6843080..0000000
--- a/src/corelib/statemachine/qstateaction.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEACTION_H
-#define QSTATEACTION_H
-
-#include <QtCore/qobject.h>
-
-#include <QtCore/qvariant.h>
-#include <QtCore/qlist.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateActionPrivate;
-class Q_CORE_EXPORT QStateAction : public QObject
-{
- Q_OBJECT
-public:
- ~QStateAction();
-
-protected:
- QStateAction(QObject *parent = 0);
-
- virtual void execute() = 0;
-
- bool event(QEvent *e);
-
-protected:
-#ifdef QT_STATEMACHINE_SOLUTION
- QStateActionPrivate *d_ptr;
-#endif
- QStateAction(QStateActionPrivate &dd, QObject *parent);
-
-private:
- Q_DISABLE_COPY(QStateAction)
- Q_DECLARE_PRIVATE(QStateAction)
-};
-
-class QStateInvokeMethodActionPrivate;
-class Q_CORE_EXPORT QStateInvokeMethodAction : public QStateAction
-{
- Q_OBJECT
- Q_PROPERTY(QObject* target READ targetObject WRITE setTargetObject)
- Q_PROPERTY(QByteArray methodName READ methodName WRITE setMethodName)
- Q_PROPERTY(QVariantList arguments READ arguments WRITE setArguments)
-public:
- QStateInvokeMethodAction(QObject *target, const QByteArray &methodName,
- QObject *parent = 0);
- QStateInvokeMethodAction(QObject *target, const QByteArray &methodName,
- const QList<QVariant> &args, QObject *parent = 0);
- QStateInvokeMethodAction(QObject *parent = 0);
- ~QStateInvokeMethodAction();
-
- QObject *targetObject() const;
- void setTargetObject(QObject *target);
-
- QByteArray methodName() const;
- void setMethodName(const QByteArray &methodName);
-
- QVariantList arguments() const;
- void setArguments(const QVariantList &arguments);
-
-protected:
- void execute();
-
- bool event(QEvent *e);
-
-private:
- Q_DISABLE_COPY(QStateInvokeMethodAction)
- Q_DECLARE_PRIVATE(QStateInvokeMethodAction)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qstateaction_p.h b/src/corelib/statemachine/qstateaction_p.h
deleted file mode 100644
index 4016b74..0000000
--- a/src/corelib/statemachine/qstateaction_p.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEACTION_P_H
-#define QSTATEACTION_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include <private/qobject_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-class QStateActionPrivate
-#ifndef QT_STATEMACHINE_SOLUTION
- : public QObjectPrivate
-#endif
-{
- Q_DECLARE_PUBLIC(QStateAction)
-public:
- QStateActionPrivate();
- ~QStateActionPrivate();
-
- static QStateActionPrivate *get(QStateAction *q);
-
- void callExecute();
-
- enum When {
- ExecuteOnEntry,
- ExecuteOnExit
- };
-
- When when;
-
-#ifdef QT_STATEMACHINE_SOLUTION
- QStateAction *q_ptr;
-#endif
-};
-
-class QStateInvokeMethodAction;
-class QStateInvokeMethodActionPrivate : public QStateActionPrivate
-{
- Q_DECLARE_PUBLIC(QStateInvokeMethodAction)
-public:
- QStateInvokeMethodActionPrivate() {}
- ~QStateInvokeMethodActionPrivate() {}
-
- static QStateInvokeMethodActionPrivate *get(QStateInvokeMethodAction *q);
-
- QObject *target;
- QByteArray methodName;
- int methodIndex;
- QList<QVariant> args;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qstatefinishedtransition.cpp b/src/corelib/statemachine/qstatefinishedtransition.cpp
index 33c3d22..151a274 100644
--- a/src/corelib/statemachine/qstatefinishedtransition.cpp
+++ b/src/corelib/statemachine/qstatefinishedtransition.cpp
@@ -41,7 +41,7 @@
#include "qstatefinishedtransition.h"
#include "qstatefinishedevent.h"
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
@@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
\brief the state whose QStateFinishedEvent this transition is associated with
*/
-class QStateFinishedTransitionPrivate : public QActionTransitionPrivate
+class QStateFinishedTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QStateFinishedTransition)
public:
@@ -106,7 +106,7 @@ QStateFinishedTransitionPrivate *QStateFinishedTransitionPrivate::get(QStateFini
sourceState.
*/
QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
- : QActionTransition(*new QStateFinishedTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QStateFinishedTransitionPrivate, sourceState)
{
}
@@ -116,7 +116,7 @@ QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
*/
QStateFinishedTransition::QStateFinishedTransition(
QState *state, const QList<QAbstractState*> &targets, QState *sourceState)
- : QActionTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
{
Q_D(QStateFinishedTransition);
d->state = state;
@@ -167,9 +167,16 @@ bool QStateFinishedTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
+void QStateFinishedTransition::onTransition()
+{
+}
+
+/*!
+ \reimp
+*/
bool QStateFinishedTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstatefinishedtransition.h b/src/corelib/statemachine/qstatefinishedtransition.h
index f9320f5..ed86288 100644
--- a/src/corelib/statemachine/qstatefinishedtransition.h
+++ b/src/corelib/statemachine/qstatefinishedtransition.h
@@ -43,9 +43,9 @@
#define QSTATEFINISHEDTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qactiontransition.h>
+#include <QtCore/qabstracttransition.h>
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
QT_BEGIN_HEADER
@@ -57,7 +57,7 @@ QT_MODULE(Core)
class QState;
class QStateFinishedTransitionPrivate;
-class Q_CORE_EXPORT QStateFinishedTransition : public QActionTransition
+class Q_CORE_EXPORT QStateFinishedTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QState* state READ state WRITE setState)
@@ -72,6 +72,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 0a1d248..2d3eea1 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -49,8 +49,6 @@
#include "qsignaleventgenerator_p.h"
#include "qabstractstate.h"
#include "qabstractstate_p.h"
-#include "qactionstate.h"
-#include "qactionstate_p.h"
#include "qfinalstate.h"
#include "qhistorystate.h"
#include "qhistorystate_p.h"
@@ -58,8 +56,6 @@
#include "qstatefinishedtransition.h"
#include "qstate.h"
#include "qstate_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
#ifndef QT_STATEMACHINE_SOLUTION
#include "private/qobject_p.h"
#include "private/qthread_p.h"
@@ -192,7 +188,7 @@ QStateMachinePrivate::QStateMachinePrivate()
processingScheduled = false;
stop = false;
error = QStateMachine::NoError;
- globalRestorePolicy = QAbstractState::DoNotRestoreProperties;
+ globalRestorePolicy = QStateMachine::DoNotRestoreProperties;
rootState = 0;
initialErrorStateForRoot = 0;
#ifndef QT_STATEMACHINE_SOLUTION
@@ -417,6 +413,7 @@ QList<QAbstractState*> QStateMachinePrivate::exitStates(const QList<QAbstractTra
#endif
QAbstractStatePrivate::get(s)->callOnExit();
configuration.remove(s);
+ QAbstractStatePrivate::get(s)->emitExited();
}
return statesToExit_sorted;
}
@@ -504,6 +501,7 @@ QList<QAbstractState*> QStateMachinePrivate::enterStates(const QList<QAbstractTr
configuration.insert(s);
registerTransitions(s);
QAbstractStatePrivate::get(s)->callOnEntry();
+ QAbstractStatePrivate::get(s)->emitEntered();
if (statesForDefaultEntry.contains(s)) {
// ### executeContent(s.initial.transition.children())
}
@@ -612,8 +610,17 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr
// Find the animations to use for the state change.
QList<QAbstractAnimation*> selectedAnimations;
- for (int i = 0; i < transitionList.size(); ++i)
- selectedAnimations << transitionList.at(i)->animations();
+ for (int i = 0; i < transitionList.size(); ++i) {
+ QAbstractTransition *transition = transitionList.at(i);
+
+ selectedAnimations << transition->animations();
+ selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
+
+ QList<QAbstractState *> targetStates = transition->targetStates();
+ for (int j=0; j<targetStates.size(); ++j)
+ selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));
+ }
+ selectedAnimations << defaultAnimations;
#else
Q_UNUSED(transitionList);
#endif
@@ -624,14 +631,10 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr
for (int i = 0; i < enteredStates.size(); ++i) {
QAbstractState *s = enteredStates.at(i);
- QAbstractState::RestorePolicy restorePolicy = s->restorePolicy();
- if (restorePolicy == QAbstractState::GlobalRestorePolicy)
- restorePolicy = globalRestorePolicy;
-
QList<QPropertyAssignment> assignments = QAbstractStatePrivate::get(s)->propertyAssignments;
for (int j = 0; j < assignments.size(); ++j) {
const QPropertyAssignment &assn = assignments.at(j);
- if (restorePolicy == QAbstractState::RestoreProperties) {
+ if (globalRestorePolicy == QStateMachine::RestoreProperties) {
registerRestorable(assn.object, assn.propertyName);
}
pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
@@ -1451,6 +1454,32 @@ void QStateMachine::setErrorState(QAbstractState *state)
*/
/*!
+ \enum QStateMachine::RestorePolicy
+
+ This enum specifies the restore policy type. The restore policy
+ takes effect when the machine enters a state which sets one or more
+ properties. If the restore policy is set to RestoreProperties,
+ the state machine will save the original value of the property before the
+ new value is set.
+
+ Later, when the machine either enters a state which does not set
+ a value for the given property, the property will automatically be restored
+ to its initial value.
+
+ Only one initial value will be saved for any given property. If a value for a property has
+ already been saved by the state machine, it will not be overwritten until the property has been
+ successfully restored.
+
+ \value DoNotRestoreProperties The state machine should not save the initial values of properties
+ and restore them later.
+ \value RestoreProperties The state machine should save the initial values of properties
+ and restore them later.
+
+ \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
+*/
+
+
+/*!
Returns the error code of the last error that occurred in the state machine.
*/
QStateMachine::Error QStateMachine::error() const
@@ -1479,33 +1508,25 @@ void QStateMachine::clearError()
}
/*!
- Returns the global restore policy of the state machine.
+ Returns the restore policy of the state machine.
- \sa QActionState::restorePolicy()
+ \sa setGlobalRestorePolicy()
*/
-QActionState::RestorePolicy QStateMachine::globalRestorePolicy() const
+QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const
{
Q_D(const QStateMachine);
return d->globalRestorePolicy;
}
/*!
- Sets the global restore policy of the state machine to \a restorePolicy. The default global
+ Sets the restore policy of the state machine to \a restorePolicy. The default
restore policy is QAbstractState::DoNotRestoreProperties.
- The global restore policy cannot be set to QAbstractState::GlobalRestorePolicy.
-
- \sa QAbstractState::setRestorePolicy()
+ \sa globalRestorePolicy()
*/
-void QStateMachine::setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy)
+void QStateMachine::setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy)
{
Q_D(QStateMachine);
- if (restorePolicy == QState::GlobalRestorePolicy) {
- qWarning("QStateMachine::setGlobalRestorePolicy: Cannot set global restore policy to "
- "GlobalRestorePolicy");
- return;
- }
-
d->globalRestorePolicy = restorePolicy;
}
@@ -1828,6 +1849,104 @@ void QStateMachine::endMicrostep(QEvent *event)
Q_UNUSED(event);
}
+#ifndef QT_NO_ANIMATION
+
+/*!
+ Adds a default \a animation to be considered for any transition.
+*/
+void QStateMachine::addDefaultAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimations.append(animation);
+}
+
+/*!
+ Returns the list of default animations that will be considered for any transition.
+*/
+QList<QAbstractAnimation*> QStateMachine::defaultAnimations() const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimations;
+}
+
+/*!
+ Removes \a animation from the list of default animations.
+*/
+void QStateMachine::removeDefaultAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimations.removeAll(animation);
+}
+
+
+/*!
+ Adds a default \a animation to be considered for any transition with the source state
+ \a sourceState.
+*/
+void QStateMachine::addDefaultAnimationForSourceState(QAbstractState *sourceState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForSource.insert(sourceState, animation);
+}
+
+
+/*!
+ Returns the list of default animations that will be considered for any transition with
+ the source state \a sourceState.
+*/
+QList<QAbstractAnimation*> QStateMachine::defaultAnimationsForSourceState(QAbstractState *sourceState) const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimationsForSource.values(sourceState);
+}
+
+/*!
+ Removes \a animation from the list of default animations for the source state
+ \a sourceState.
+*/
+void QStateMachine::removeDefaultAnimationForSourceState(QAbstractState *sourceState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForSource.remove(sourceState, animation);
+}
+
+/*!
+ Adds a default \a animation to be considered for any transition with the target state
+ \a targetState.
+*/
+void QStateMachine::addDefaultAnimationForTargetState(QAbstractState *targetState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForTarget.insert(targetState, animation);
+}
+
+/*!
+ Returns the list of default animations that will be considered for any transition with
+ the target state \a targetState.
+*/
+QList<QAbstractAnimation *> QStateMachine::defaultAnimationsForTargetState(QAbstractState *targetState) const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimationsForTarget.values(targetState);
+}
+
+/*!
+ Removes \a animation from the list of default animations for the target state
+ \a targetState.
+*/
+void QStateMachine::removeDefaultAnimationForTargetState(QAbstractState *targetState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForTarget.remove(targetState, animation);
+}
+
+#endif // QT_NO_ANIMATION
+
+
static const uint qt_meta_data_QSignalEventGenerator[] = {
// content:
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index c7de171..9a7a6fc 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -43,9 +43,9 @@
#define QSTATEMACHINE_H
#ifndef QT_STATEMACHINE_SOLUTION
-# include <QtCore/qactionstate.h>
+# include <QtCore/qabstractstate.h>
#else
-# include "qactionstate.h"
+# include "qabstractstate.h"
#endif
#include <QtCore/qlist.h>
@@ -63,6 +63,8 @@ class QAbstractState;
class QState;
class QStateMachinePrivate;
+class QAbstractAnimation;
+class QAbstractState;
class Q_CORE_EXPORT QStateMachine : public QObject
{
Q_OBJECT
@@ -70,7 +72,13 @@ class Q_CORE_EXPORT QStateMachine : public QObject
Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState)
Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState)
Q_PROPERTY(QString errorString READ errorString)
+ Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy)
+ Q_ENUMS(RestorePolicy)
public:
+ enum RestorePolicy {
+ DoNotRestoreProperties,
+ RestoreProperties
+ };
enum Error {
NoError,
@@ -96,8 +104,22 @@ public:
QString errorString() const;
void clearError();
- QAbstractState::RestorePolicy globalRestorePolicy() const;
- void setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy);
+#ifndef QT_NO_ANIMATION
+ void addDefaultAnimation(QAbstractAnimation *animation);
+ QList<QAbstractAnimation *> defaultAnimations() const;
+ void removeDefaultAnimation(QAbstractAnimation *animation);
+
+ void addDefaultAnimationForSourceState(QAbstractState *sourceState, QAbstractAnimation *animation);
+ QList<QAbstractAnimation *> defaultAnimationsForSourceState(QAbstractState *sourceState) const;
+ void removeDefaultAnimationForSourceState(QAbstractState *sourceState, QAbstractAnimation *animation);
+
+ void addDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
+ QList<QAbstractAnimation *> defaultAnimationsForTargetState(QAbstractState *targetState) const;
+ void removeDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
+#endif // QT_NO_ANIMATION
+
+ QStateMachine::RestorePolicy globalRestorePolicy() const;
+ void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy);
void postEvent(QEvent *event, int delay = 0);
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 04dc71e..9f93217 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -169,9 +169,9 @@ public:
QSet<QAbstractState*> configuration;
QList<QEvent*> internalEventQueue;
QList<QEvent*> externalEventQueue;
-
+
QStateMachine::Error error;
- QActionState::RestorePolicy globalRestorePolicy;
+ QStateMachine::RestorePolicy globalRestorePolicy;
QString errorString;
QSet<QAbstractState *> pendingErrorStates;
@@ -186,7 +186,12 @@ public:
QList<QPair<QAbstractAnimation*, QPropertyAssignment> > propertiesForAnimations;
QList<QAbstractAnimation*> playingAnimations;
QList<QAbstractAnimation*> resetEndValues;
-#endif
+
+ QList<QAbstractAnimation *> defaultAnimations;
+ QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForSource;
+ QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForTarget;
+
+#endif // QT_NO_ANIMATION
#ifndef QT_STATEMACHINE_SOLUTION
QSignalEventGenerator *signalEventGenerator;
diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri
index 4179e45..620c7a0 100644
--- a/src/corelib/statemachine/statemachine.pri
+++ b/src/corelib/statemachine/statemachine.pri
@@ -1,12 +1,8 @@
HEADERS += $$PWD/qstatemachine.h \
$$PWD/qstatemachine_p.h \
- $$PWD/qstateaction.h \
- $$PWD/qstateaction_p.h \
$$PWD/qsignaleventgenerator_p.h \
$$PWD/qabstractstate.h \
$$PWD/qabstractstate_p.h \
- $$PWD/qactionstate.h \
- $$PWD/qactionstate_p.h \
$$PWD/qstate.h \
$$PWD/qstate_p.h \
$$PWD/qfinalstate.h \
@@ -14,8 +10,6 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qhistorystate_p.h \
$$PWD/qabstracttransition.h \
$$PWD/qabstracttransition_p.h \
- $$PWD/qactiontransition.h \
- $$PWD/qactiontransition_p.h \
$$PWD/qstatefinishedevent.h \
$$PWD/qstatefinishedtransition.h \
$$PWD/qsignalevent.h \
@@ -23,14 +17,11 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qsignaltransition_p.h
SOURCES += $$PWD/qstatemachine.cpp \
- $$PWD/qstateaction.cpp \
$$PWD/qabstractstate.cpp \
- $$PWD/qactionstate.cpp \
$$PWD/qstate.cpp \
$$PWD/qfinalstate.cpp \
$$PWD/qhistorystate.cpp \
$$PWD/qabstracttransition.cpp \
- $$PWD/qactiontransition.cpp \
$$PWD/qstatefinishedtransition.cpp \
$$PWD/qsignaltransition.cpp
diff --git a/tests/auto/qanimationstate/qanimationstate.pro b/tests/auto/qanimationstate/qanimationstate.pro
deleted file mode 100644
index 8862c27..0000000
--- a/tests/auto/qanimationstate/qanimationstate.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-load(qttest_p4)
-QT = core
-SOURCES += tst_qanimationstate.cpp
-
-
diff --git a/tests/auto/qanimationstate/tst_qanimationstate.cpp b/tests/auto/qanimationstate/tst_qanimationstate.cpp
deleted file mode 100644
index 085db24..0000000
--- a/tests/auto/qanimationstate/tst_qanimationstate.cpp
+++ /dev/null
@@ -1,625 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/qstate.h>
-#include <QtCore/qstatemachine.h>
-#include <QtCore/qanimationstate.h>
-
-//TESTED_CLASS=QAnimationState
-//TESTED_FILES=
-
-#define QTRY_COMPARE(__expr, __expected) \
- do { \
- const int __step = 50; \
- const int __timeout = 5000; \
- if ((__expr) != (__expected)) { \
- QTest::qWait(0); \
- } \
- for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
- QTest::qWait(__step); \
- } \
- QCOMPARE(__expr, __expected); \
- } while(0)
-
-
-class tst_QAnimationState : public QObject
-{
- Q_OBJECT
-public:
- tst_QAnimationState();
- virtual ~tst_QAnimationState();
-
-private slots:
- void init();
- void cleanup();
- void construction();
- void noAnimation();
- void simpleAnimation();
- void twoAnimations();
- void reuseAnimation();
- void nestedTargetState();
- void parallelTargetState();
- void playTwice();
- void twoAnimatedTransitions();
- void globalRestoreProperty();
- void specificRestoreProperty();
- void someAnimationsNotSpecified();
- void someActionsNotAnimated();
- void specificTargetValueOfAnimation();
- void persistentTargetValueOfAnimation();
-};
-
-tst_QAnimationState::tst_QAnimationState()
-{
-}
-
-tst_QAnimationState::~tst_QAnimationState()
-{
-}
-
-void tst_QAnimationState::init()
-{
-}
-
-void tst_QAnimationState::cleanup()
-{
-}
-
-void tst_QAnimationState::construction()
-{
- QAnimationState as;
-}
-
-class EventTransition : public QTransition
-{
-public:
- EventTransition(QEvent::Type type, QAbstractState *target)
- : QTransition(), m_type(type) {
- setTargetState(target);
- }
-protected:
- virtual bool eventTest(QEvent *e) const {
- return (e->type() == m_type);
- }
-private:
- QEvent::Type m_type;
-};
-
-void tst_QAnimationState::noAnimation()
-{
- QStateMachine machine;
-
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
- s2->setProperty("entered", false);
- s2->setPropertyOnEntry(s2, "entered", true);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- s2->addTransition(new EventTransition(QEvent::User, s1));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- QVERIFY(machine.configuration().contains(s1));
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->property("entered").toBool(), true);
- QVERIFY(machine.configuration().contains(s2));
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
-
- QVERIFY(machine.configuration().contains(s1));
-
- s2->setProperty("entered", false);
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->property("entered").toBool(), true);
- QVERIFY(machine.configuration().contains(s2));
-}
-
-class ValueCheckerState: public QState
-{
-public:
- ValueCheckerState(QState *parent)
- : QState(parent)
- {
- }
-
- void addPropertyToCheck(const QObject *object, const char *propertyName)
- {
- m_objects.append(object);
- m_propertyNames.append(propertyName);
- valueOnEntry.append(QVariant());
- }
-
- QVariantList valueOnEntry;
-
-protected:
- virtual void onEntry()
- {
- for (int i=0; i<m_objects.size(); ++i)
- valueOnEntry[i] = m_objects.at(i)->property(m_propertyNames.at(i));
-
- QState::onEntry();
- }
-
- QList<const QObject *> m_objects;
- QList<QByteArray> m_propertyNames;
-
-};
-
-void tst_QAnimationState::simpleAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("fooBar", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "fooBar");
- s2->setPropertyOnEntry(object, "fooBar", 2.0);
-
- QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), animation);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::twoAnimations()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
- s2->setPropertyOnEntry(object, "bar", 10.0);
-
- QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
- QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
- animationBar->setDuration(900);
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(animationFoo);
- as->addAnimation(animationBar);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 10.0);
-}
-
-void tst_QAnimationState::parallelTargetState()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(QState::ParallelGroup, machine.rootState());
-
- ValueCheckerState *c1 = new ValueCheckerState(s2);
- c1->setPropertyOnEntry(object, "foo", 2.0);
- c1->addPropertyToCheck(object, "foo");
- c1->addPropertyToCheck(object, "bar");
-
- QState *c2 = new QState(s2);
- c2->setPropertyOnEntry(object, "bar", 10.0);
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(c1->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(c1->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(c1->valueOnEntry.at(1).toDouble(), 10.0);
-}
-
-
-void tst_QAnimationState::twoAnimatedTransitions()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
- s3->addPropertyToCheck(object, "foo");
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s2));
- s2->addAnimatedTransition(new EventTransition(QEvent::User, s3),
- new QPropertyAnimation(object, "foo", s2));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::playTwice()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- QState *s3 = new QState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s2));
- s2->addTransition(new EventTransition(QEvent::User, s3));
- s3->addTransition(s1);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QVERIFY(machine.configuration().contains(s1));
- QCOMPARE(object->property("foo").toDouble(), 2.0);
-
- s2->valueOnEntry[0] = QVariant();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(object->property("foo").toDouble(), 5.0);
-}
-
-void tst_QAnimationState::nestedTargetState()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QState *s2Child = new QState(s2);
- s2Child->setPropertyOnEntry(object, "bar", 10.0);
- s2->setInitialState(s2Child);
-
- QState *s2Child2 = new QState(s2);
- s2Child2->setPropertyOnEntry(object, "bar", 11.0);
- s2Child->addTransition(s2Child2); // should *not* be considered by QAnimationState as part of target
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 10.0);
- QCOMPARE(object->property("bar").toDouble(), 11.0);
-}
-
-void tst_QAnimationState::reuseAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
- s3->addPropertyToCheck(object, "foo");
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo", s2);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
- s2->addAnimatedTransition(new EventTransition(QEvent::User, s3), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::globalRestoreProperty()
-{
- QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->addPropertyToCheck(object, "foo");
- s3->addPropertyToCheck(object, "bar");
- s3->setPropertyOnEntry(object, "bar", 5.0);
-
- ValueCheckerState *s4 = new ValueCheckerState(machine.rootState());
- s4->addPropertyToCheck(object, "foo");
- s4->addPropertyToCheck(object, "bar");
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s2->addAnimatedTransition(new EventTransition(QEvent::User, s3));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s3->addAnimatedTransition(new EventTransition(QEvent::User, s4));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s3->valueOnEntry.at(1).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s4->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s4->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s4->valueOnEntry.at(1).toDouble(), 3.0);
-
-}
-
-void tst_QAnimationState::specificRestoreProperty()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->setRestorePolicy(QState::RestoreProperties);
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setRestorePolicy(QState::RestoreProperties);
- s3->addPropertyToCheck(object, "foo");
- s3->addPropertyToCheck(object, "bar");
- s3->setPropertyOnEntry(object, "bar", 5.0);
-
- ValueCheckerState *s4 = new ValueCheckerState(machine.rootState());
- s4->setRestorePolicy(QState::RestoreProperties);
- s4->addPropertyToCheck(object, "foo");
- s4->addPropertyToCheck(object, "bar");
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
-
- as = s2->addAnimatedTransition(new EventTransition(QEvent::User, s3));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s3->addAnimatedTransition(new EventTransition(QEvent::User, s4));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s3->valueOnEntry.at(1).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s4->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s4->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s4->valueOnEntry.at(1).toDouble(), 3.0);
-}
-
-void tst_QAnimationState::someAnimationsNotSpecified()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-}
-
-void tst_QAnimationState::someActionsNotAnimated()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
- s2->setPropertyOnEntry(object, "bar", 5.0);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s1));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
- QCOMPARE(object->property("foo").toDouble(), 2.0);
- QCOMPARE(object->property("bar").toDouble(), 5.0);
-}
-
-void tst_QAnimationState::specificTargetValueOfAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
- anim->setEndValue(10.0);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 10.0);
- QCOMPARE(object->property("foo").toDouble(), 2.0);
-}
-
-void tst_QAnimationState::persistentTargetValueOfAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(anim->endValue().isValid(), false);
-}
-
-
-QTEST_MAIN(tst_QAnimationState)
-#include "tst_qanimationstate.moc"
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index f28c3fa..f082caf 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -9,9 +9,7 @@
#include "qstate.h"
#include "qstatemachine.h"
-#include "qtransition.h"
#include "qsignaltransition.h"
-#include "qstateaction.h"
// Will try to wait for the condition while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
@@ -45,7 +43,6 @@ private slots:
void assignProperty();
void assignPropertyTwice();
void historyInitialState();
- void addEntryAction();
private:
bool functionCalled;
@@ -214,22 +211,6 @@ public slots:
};
-void tst_QState::addEntryAction()
-{
- QStateMachine sm;
-
- TestClass testObject;
-
- QState *s0 = new QState(sm.rootState());
- s0->addEntryAction(new QStateInvokeMethodAction(&testObject, "slot"));
- sm.setInitialState(s0);
-
- sm.start();
- QCoreApplication::processEvents();
-
- QCOMPARE(testObject.called, true);
-}
-
void tst_QState::assignProperty()
{
QStateMachine machine;
@@ -265,11 +246,11 @@ void tst_QState::assignPropertyTwice()
QCOMPARE(object->property("fooBar").toInt(), 30);
}
-class EventTestTransition: public QTransition
+class EventTestTransition: public QAbstractTransition
{
public:
EventTestTransition(QEvent::Type type, QState *targetState)
- : QTransition(QList<QAbstractState*>() << targetState), m_type(type)
+ : QAbstractTransition(QList<QAbstractState*>() << targetState), m_type(type)
{
}
@@ -279,6 +260,8 @@ protected:
return e->type() == m_type;
}
+ void onTransition() {}
+
private:
QEvent::Type m_type;
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 085d16b..2fa9b1a 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -45,7 +45,6 @@
#include "qstatemachine.h"
#include "qstate.h"
-#include "qactiontransition.h"
#include "qhistorystate.h"
#include "qkeyeventtransition.h"
#include "qmouseeventtransition.h"
@@ -70,6 +69,17 @@
static int globalTick;
+// Run exec for a maximum of TIMEOUT msecs
+#define QCOREAPPLICATION_EXEC(TIMEOUT) \
+{ \
+ QTimer timer; \
+ timer.setSingleShot(true); \
+ timer.setInterval(TIMEOUT); \
+ timer.start(); \
+ connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); \
+ QCoreApplication::exec(); \
+}
+
class tst_QStateMachine : public QObject
{
Q_OBJECT
@@ -91,8 +101,6 @@ private slots:
void signalTransitions();
void eventTransitions();
void historyStates();
- void stateActions();
- void transitionActions();
void transitionToRootState();
void transitionEntersParent();
@@ -113,15 +121,39 @@ private slots:
void customErrorStateNotInGraph();
void transitionToStateNotInGraph();
void restoreProperties();
+
void defaultGlobalRestorePolicy();
void globalRestorePolicySetToRestore();
void globalRestorePolicySetToDoNotRestore();
- void restorePolicyNotInherited();
- void mixedRestoreProperties();
- void setRestorePolicyToDoNotRestore();
- void setGlobalRestorePolicyToGlobalRestore();
- void restorePolicyOnChildState();
+
+ //void restorePolicyNotInherited();
+ //void mixedRestoreProperties();
+ //void setRestorePolicyToDoNotRestore();
+ //void setGlobalRestorePolicyToGlobalRestore();
+ //void restorePolicyOnChildState();
+
void transitionWithParent();
+
+ void simpleAnimation();
+ void twoAnimations();
+ void twoAnimatedTransitions();
+ void playAnimationTwice();
+ void nestedTargetStateForAnimation();
+ void animatedGlobalRestoreProperty();
+ void specificTargetValueOfAnimation();
+ void addDefaultAnimation();
+ void addDefaultAnimationWithUnusedAnimation();
+ void addDefaultAnimationForSource();
+ void addDefaultAnimationForTarget();
+ void removeDefaultAnimation();
+ void removeDefaultAnimationForSource();
+ void removeDefaultAnimationForTarget();
+ void overrideDefaultAnimationWithSource();
+ void overrideDefaultAnimationWithTarget();
+ void overrideDefaultAnimationWithSpecific();
+ void overrideDefaultSourceAnimationWithSpecific();
+ void overrideDefaultTargetAnimationWithSpecific();
+ void overrideDefaultTargetAnimationWithSource();
};
tst_QStateMachine::tst_QStateMachine()
@@ -194,15 +226,16 @@ void tst_QStateMachine::cleanup()
qInstallMsgHandler(s_oldHandler);
}
-class EventTransition : public QActionTransition
+class EventTransition : public QAbstractTransition
{
public:
EventTransition(QEvent::Type type, QAbstractState *target, QState *parent = 0)
- : QActionTransition(QList<QAbstractState*>() << target, parent), m_type(type) {}
+ : QAbstractTransition(QList<QAbstractState*>() << target, parent), m_type(type) {}
protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == m_type);
}
+ virtual void onTransition() {}
private:
QEvent::Type m_type;
};
@@ -893,22 +926,20 @@ void tst_QStateMachine::restoreProperties()
object->setProperty("b", 2);
QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *S1 = new QState();
S1->setObjectName("S1");
S1->assignProperty(object, "a", 3);
- S1->setRestorePolicy(QState::RestoreProperties);
machine.addState(S1);
QState *S2 = new QState();
S2->setObjectName("S2");
S2->assignProperty(object, "b", 5);
- S2->setRestorePolicy(QState::RestoreProperties);
machine.addState(S2);
QState *S3 = new QState();
S3->setObjectName("S3");
- S3->setRestorePolicy(QState::RestoreProperties);
machine.addState(S3);
QFinalState *S4 = new QFinalState();
@@ -1599,154 +1630,6 @@ void tst_QStateMachine::historyStates()
QTRY_COMPARE(finishedSpy.count(), 1);
}
-class TestStateAction : public QStateAction
-{
-public:
- TestStateAction() : m_didExecute(false)
- {}
- bool didExecute() const {
- return m_didExecute;
- }
-protected:
- void execute() {
- m_didExecute = true;
- }
-private:
- bool m_didExecute;
-};
-
-void tst_QStateMachine::stateActions()
-{
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
-
- QVERIFY(s1->entryActions().isEmpty());
- QVERIFY(s1->exitActions().isEmpty());
-
- QTest::ignoreMessage(QtWarningMsg, "QActionState::addEntryAction: cannot add null action");
- s1->addEntryAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::addExitAction: cannot add null action");
- s1->addExitAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::removeEntryAction: cannot remove null action");
- s1->removeEntryAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::removeExitAction: cannot remove null action");
- s1->removeExitAction(0);
-
- QFinalState *s2 = new QFinalState(machine.rootState());
- s1->addTransition(s2);
-
- machine.setInitialState(s1);
- QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
-
- QObject *obj = new QObject();
- QStateInvokeMethodAction *ima = new QStateInvokeMethodAction(obj, "deleteLater");
- QPointer<QObject> ptr(obj);
- QVERIFY(ptr != 0);
- s1->addEntryAction(ima);
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-
- s1->removeEntryAction(ima);
-
- s1->invokeMethodOnEntry(ima, "deleteLater");
- QCOMPARE(s1->entryActions().size(), 1);
-
- ptr = ima;
- QVERIFY(ptr != 0);
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-
- while (!s1->entryActions().isEmpty()) {
- QStateAction *act = s1->entryActions().first();
- s1->removeEntryAction(act);
- delete act;
- }
-
- TestStateAction *act1 = new TestStateAction();
- s1->addEntryAction(act1);
- TestStateAction *act2 = new TestStateAction();
- s1->addExitAction(act2);
- QVERIFY(!act1->didExecute());
- QVERIFY(!act2->didExecute());
-
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
-
- QVERIFY(act1->didExecute());
- QVERIFY(act2->didExecute());
-
- QCOMPARE(s1->entryActions().size(), 1);
- QCOMPARE(s2->entryActions().size(), 0);
- s2->addEntryAction(act1); // should remove it from s1
- QCOMPARE(s1->entryActions().size(), 0);
- QCOMPARE(s2->entryActions().size(), 1);
- QCOMPARE(act1->parent(), (QObject*)s2);
-
- QCOMPARE(s2->exitActions().size(), 0);
- s2->addExitAction(act1); // should remove entry action
- QCOMPARE(s2->exitActions().size(), 1);
- QCOMPARE(s2->entryActions().size(), 0);
- QCOMPARE(act1->parent(), (QObject*)s2);
-}
-
-void tst_QStateMachine::transitionActions()
-{
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
-
- QFinalState *s2 = new QFinalState(machine.rootState());
- EventTransition *trans = new EventTransition(QEvent::User, s2);
- s1->addTransition(trans);
- QVERIFY(trans->actions().isEmpty());
- QTest::ignoreMessage(QtWarningMsg, "QActionTransition::addAction: cannot add null action");
- trans->addAction(0);
- QVERIFY(trans->actions().isEmpty());
-
- TestStateAction *act = new TestStateAction();
- trans->addAction(act);
- QCOMPARE(trans->actions().size(), 1);
- QCOMPARE(trans->actions().at(0), (QStateAction*)act);
- QCOMPARE(act->parent(), (QObject*)trans);
- QVERIFY(!act->didExecute());
-
- trans->removeAction(act);
- QVERIFY(trans->actions().isEmpty());
- QCOMPARE(act->parent(), (QObject*)0);
-
- trans->addAction(act);
-
- QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QVERIFY(act->didExecute());
-
- trans->invokeMethodOnTransition(act, "deleteLater");
-
- QPointer<QStateAction> ptr(act);
- QVERIFY(ptr != 0);
- finishedSpy.clear();
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-}
-
void tst_QStateMachine::defaultGlobalRestorePolicy()
{
QStateMachine machine;
@@ -1786,6 +1669,7 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::restorePolicyNotInherited()
{
QStateMachine machine;
@@ -1832,12 +1716,12 @@ void tst_QStateMachine::restorePolicyNotInherited()
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
-}
+}*/
void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::DoNotRestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -1874,6 +1758,7 @@ void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::setRestorePolicyToDoNotRestore()
{
QObject *object = new QObject();
@@ -1930,19 +1815,20 @@ void tst_QStateMachine::setGlobalRestorePolicyToGlobalRestore()
{
s_countWarnings = false;
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::DoNotRestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
s_msgType = QtDebugMsg;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::RestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::RestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
}
+
void tst_QStateMachine::restorePolicyOnChildState()
{
QStateMachine machine;
@@ -1991,11 +1877,12 @@ void tst_QStateMachine::restorePolicyOnChildState()
QCOMPARE(propertyHolder->property("a").toInt(), 1);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+*/
void tst_QStateMachine::globalRestorePolicySetToRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -2032,6 +1919,7 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+/*
void tst_QStateMachine::mixedRestoreProperties()
{
QStateMachine machine;
@@ -2098,6 +1986,7 @@ void tst_QStateMachine::mixedRestoreProperties()
// Enter s3, restore
QCOMPARE(propertyHolder->property("a").toInt(), 5);
}
+*/
void tst_QStateMachine::transitionWithParent()
{
@@ -2111,5 +2000,814 @@ void tst_QStateMachine::transitionWithParent()
QCOMPARE(trans->targetStates().at(0), (QAbstractState*)s2);
}
+void tst_QStateMachine::simpleAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "fooBar", 2.0);
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
+ et->addAnimation(animation);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(animation, SIGNAL(finished()), s3);
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("fooBar").toDouble(), 2.0);
+}
+
+class SlotCalledCounter: public QObject
+{
+ Q_OBJECT
+public:
+ SlotCalledCounter() : counter(0) {}
+
+ int counter;
+
+public slots:
+ void slot() { counter++; }
+};
+
+void tst_QStateMachine::twoAnimations()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+ s2->assignProperty(object, "bar", 10.0);
+
+ QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
+ QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
+ animationBar->setDuration(900);
+
+ SlotCalledCounter counter;
+ connect(animationFoo, SIGNAL(finished()), &counter, SLOT(slot()));
+ connect(animationBar, SIGNAL(finished()), &counter, SLOT(slot()));
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ et->addAnimation(animationFoo);
+ et->addAnimation(animationBar);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::twoAnimatedTransitions()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::playAnimationTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::nestedTargetStateForAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s2Child = new QState(s2);
+ s2Child->assignProperty(object, "bar", 10.0);
+ s2->setInitialState(s2Child);
+
+ QState *s2Child2 = new QState(s2);
+ s2Child2->assignProperty(object, "bar", 11.0);
+ QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2));
+
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ animation = new QPropertyAnimation(object, "foo", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::animatedGlobalRestoreProperty()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s2->addTransition(pa, SIGNAL(finished()), s3);
+ pa = new QPropertyAnimation(object, "foo", s3);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s3->addTransition(pa, SIGNAL(finished()), s4);
+ pa = new QPropertyAnimation(object, "foo", s4);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s4));
+ QCOMPARE(object->property("foo").toDouble(), 1.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::specificTargetValueOfAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
+ anim->setEndValue(10.0);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(anim, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(anim->endValue().toDouble(), 10.0);
+}
+
+void tst_QStateMachine::addDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 2.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ pa = new QPropertyAnimation(object, "bar", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(counter.counter, 1);
+}
+
+void tst_QStateMachine::addDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForSourceState(s1, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForTargetState(s2, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::removeDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ machine.addDefaultAnimation(anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimation(anim2);
+
+ QCOMPARE(machine.defaultAnimations().size(), 2);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim2);
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForTargetState(s2, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForSourceState(s1, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"