From f87641584424deed25e2abdadea08c3be94b9ce1 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 22 Apr 2009 17:20:19 +0200 Subject: kill the stateactions api It just didn't give us that much. Typically you just reimplement onEntry/onExit/onTransition when you want to do something. We go back to the signals-and-slots approach: states have entered() and exited() signals that you can connect to. It's still possible to have an action-based API, but then you build it on top of the core API, which is OK. Replacing 4 public classes (and one layer in the hierarchy) with 2 signals feels good. --- doc/src/statemachine.qdoc | 7 +- examples/animation/example/mainwindow.cpp | 6 +- examples/animation/moveblocks/main.cpp | 2 +- examples/animation/stickman/lifecycle.cpp | 4 +- examples/statemachine/composition/main.cpp | 4 +- examples/statemachine/trafficlight/main.cpp | 6 +- src/corelib/statemachine/qabstractstate.cpp | 29 ++ src/corelib/statemachine/qabstractstate.h | 4 + src/corelib/statemachine/qabstractstate_p.h | 3 + src/corelib/statemachine/qactionstate.cpp | 293 ----------------- src/corelib/statemachine/qactionstate.h | 102 ------ src/corelib/statemachine/qactionstate_p.h | 83 ----- src/corelib/statemachine/qactiontransition.cpp | 230 ------------- src/corelib/statemachine/qactiontransition.h | 96 ------ src/corelib/statemachine/qactiontransition_p.h | 80 ----- src/corelib/statemachine/qeventtransition.cpp | 21 +- src/corelib/statemachine/qeventtransition.h | 7 +- src/corelib/statemachine/qeventtransition_p.h | 4 +- src/corelib/statemachine/qfinalstate.cpp | 10 +- src/corelib/statemachine/qfinalstate.h | 6 +- src/corelib/statemachine/qsignaltransition.cpp | 15 +- src/corelib/statemachine/qsignaltransition.h | 7 +- src/corelib/statemachine/qsignaltransition_p.h | 4 +- src/corelib/statemachine/qstate.cpp | 10 +- src/corelib/statemachine/qstate.h | 6 +- src/corelib/statemachine/qstate_p.h | 4 +- src/corelib/statemachine/qstateaction.cpp | 356 --------------------- src/corelib/statemachine/qstateaction.h | 119 ------- src/corelib/statemachine/qstateaction_p.h | 107 ------- .../statemachine/qstatefinishedtransition.cpp | 17 +- .../statemachine/qstatefinishedtransition.h | 7 +- src/corelib/statemachine/qstatemachine.cpp | 10 +- src/corelib/statemachine/qstatemachine.h | 4 +- src/corelib/statemachine/qstatemachine_p.h | 2 +- src/corelib/statemachine/statemachine.pri | 9 - tests/auto/qstatemachine/tst_qstatemachine.cpp | 194 ++--------- 36 files changed, 148 insertions(+), 1720 deletions(-) delete mode 100644 src/corelib/statemachine/qactionstate.cpp delete mode 100644 src/corelib/statemachine/qactionstate.h delete mode 100644 src/corelib/statemachine/qactionstate_p.h delete mode 100644 src/corelib/statemachine/qactiontransition.cpp delete mode 100644 src/corelib/statemachine/qactiontransition.h delete mode 100644 src/corelib/statemachine/qactiontransition_p.h delete mode 100644 src/corelib/statemachine/qstateaction.cpp delete mode 100644 src/corelib/statemachine/qstateaction.h delete mode 100644 src/corelib/statemachine/qstateaction_p.h 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/example/mainwindow.cpp b/examples/animation/example/mainwindow.cpp index 2b0e035..bec755c 100644 --- a/examples/animation/example/mainwindow.cpp +++ b/examples/animation/example/mainwindow.cpp @@ -173,9 +173,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 1f253f3..639fff3 100644 --- a/examples/animation/moveblocks/main.cpp +++ b/examples/animation/moveblocks/main.cpp @@ -172,7 +172,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 9233760..e67b32d 100644 --- a/examples/animation/stickman/lifecycle.cpp +++ b/examples/animation/stickman/lifecycle.cpp @@ -86,8 +86,8 @@ 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); 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..030c63c 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 @@ -149,6 +152,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. */ @@ -256,6 +271,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..55e9a62 100644 --- a/src/corelib/statemachine/qabstractstate.h +++ b/src/corelib/statemachine/qabstractstate.h @@ -75,6 +75,10 @@ public: 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..e47fbd2 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -98,6 +98,9 @@ public: void callOnEntry(); void callOnExit(); + void emitEntered(); + void emitExited(); + QAbstractState::RestorePolicy restorePolicy; QList propertyAssignments; 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 QActionStatePrivate::entryActions() const -{ - QList result; - QList::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(*it); - if (act && (QStateActionPrivate::get(act)->when == QStateActionPrivate::ExecuteOnEntry)) - result.append(act); - } - return result; -} - -QList QActionStatePrivate::exitActions() const -{ - QList result; - QList::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(*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 &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 &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 QActionState::entryActions() const -{ - Q_D(const QActionState); - return d->entryActions(); -} - -/*! - Returns this state's exit actions. - - \sa addExitAction(), entryActions() -*/ -QList QActionState::exitActions() const -{ - Q_D(const QActionState); - return d->exitActions(); -} - -/*! - \reimp -*/ -void QActionState::onEntry() -{ - Q_D(QActionState); - QList 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 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 -#else -#include "qabstractstate.h" -#endif - -#include -#include - -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 &args = QList()); - void invokeMethodOnExit(QObject *object, const char *method, - const QList &args = QList()); - - void addEntryAction(QStateAction *action); - void addExitAction(QStateAction *action); - - void removeEntryAction(QStateAction *action); - void removeExitAction(QStateAction *action); - - QList entryActions() const; - QList 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 - -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 entryActions() const; - QList 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 QActionTransitionPrivate::actions() const -{ - QList result; - QList::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(*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 &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 &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 &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 QActionTransition::actions() const -{ - Q_D(const QActionTransition); - return d->actions(); -} - -/*! - \reimp -*/ -void QActionTransition::onTransition() -{ - Q_D(QActionTransition); - QList 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 -#else -#include "qabstracttransition.h" -#endif - -#include -#include - -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 &targets, QState *sourceState = 0); - ~QActionTransition(); - - void invokeMethodOnTransition(QObject *object, const char *method, - const QList &args = QList()); - - void addAction(QStateAction *action); - void removeAction(QStateAction *action); - QList actions() const; - -protected: - virtual void onTransition(); - - bool event(QEvent *e); - -protected: - QActionTransition(QActionTransitionPrivate &dd, QState *parent); - QActionTransition(QActionTransitionPrivate &dd, const QList &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 - -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 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 &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 &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 +#include #else -#include "qactiontransition.h" +#include "qabstracttransition.h" #endif #include @@ -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 +#include #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 &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 +#include #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 28c84d5..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) { } @@ -385,7 +385,6 @@ QHistoryState *QState::addHistoryState(HistoryType type) */ void QState::onEntry() { - QActionState::onEntry(); } /*! @@ -393,7 +392,6 @@ void QState::onEntry() */ void QState::onExit() { - QActionState::onExit(); } /*! @@ -430,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 1ec0896..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 +#include #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: 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 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 -#include - -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 &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 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(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 - -#include -#include - -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 &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 -#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 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 &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 +#include #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 1f8d8a8..b6ab205 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" @@ -417,6 +413,7 @@ QList QStateMachinePrivate::exitStates(const QListcallOnExit(); configuration.remove(s); + QAbstractStatePrivate::get(s)->emitExited(); } return statesToExit_sorted; } @@ -504,6 +501,7 @@ QList QStateMachinePrivate::enterStates(const QListcallOnEntry(); + QAbstractStatePrivate::get(s)->emitEntered(); if (statesForDefaultEntry.contains(s)) { // ### executeContent(s.initial.transition.children()) } @@ -1490,9 +1488,9 @@ void QStateMachine::clearError() /*! Returns the global restore policy of the state machine. - \sa QActionState::restorePolicy() + \sa QAbstractState::restorePolicy() */ -QActionState::RestorePolicy QStateMachine::globalRestorePolicy() const +QAbstractState::RestorePolicy QStateMachine::globalRestorePolicy() const { Q_D(const QStateMachine); return d->globalRestorePolicy; diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h index f39efc7..901d160 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 +# include #else -# include "qactionstate.h" +# include "qabstractstate.h" #endif #include diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index a9fd2de..910b751 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -171,7 +171,7 @@ public: QList externalEventQueue; QStateMachine::Error error; - QActionState::RestorePolicy globalRestorePolicy; + QAbstractState::RestorePolicy globalRestorePolicy; QString errorString; QSet pendingErrorStates; 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/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index b82055b..bf3ff71 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" @@ -102,8 +101,6 @@ private slots: void signalTransitions(); void eventTransitions(); void historyStates(); - void stateActions(); - void transitionActions(); void transitionToRootState(); void transitionEntersParent(); @@ -226,15 +223,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() << target, parent), m_type(type) {} + : QAbstractTransition(QList() << 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; }; @@ -1631,154 +1629,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 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 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; @@ -2161,7 +2011,7 @@ void tst_QStateMachine::simpleAnimation() QState *s3 = new QState(machine.rootState()); s2->addTransition(animation, SIGNAL(finished()), s3); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); machine.setInitialState(s1); machine.start(); @@ -2213,7 +2063,7 @@ void tst_QStateMachine::twoAnimations() s1->addTransition(et); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s2->addTransition(&machine, SIGNAL(animationsFinished()), s3); machine.setInitialState(s1); @@ -2245,7 +2095,7 @@ void tst_QStateMachine::twoAnimatedTransitions() s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s2->addTransition(fooAnimation, SIGNAL(finished()), s3); QState *s4 = new QState(machine.rootState()); @@ -2254,7 +2104,7 @@ void tst_QStateMachine::twoAnimatedTransitions() s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2); QState *s5 = new QState(machine.rootState()); - s5->invokeMethodOnEntry(QApplication::instance(), "quit"); + QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); s4->addTransition(fooAnimation2, SIGNAL(finished()), s5); machine.setInitialState(s1); @@ -2289,7 +2139,7 @@ void tst_QStateMachine::playAnimationTwice() s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s2->addTransition(fooAnimation, SIGNAL(finished()), s3); QState *s4 = new QState(machine.rootState()); @@ -2297,7 +2147,7 @@ void tst_QStateMachine::playAnimationTwice() s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation); QState *s5 = new QState(machine.rootState()); - s5->invokeMethodOnEntry(QApplication::instance(), "quit"); + QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); s4->addTransition(fooAnimation, SIGNAL(finished()), s5); machine.setInitialState(s1); @@ -2355,7 +2205,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation() at->addAnimation(animation); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s2->addTransition(&machine, SIGNAL(animationsFinished()), s3); machine.setInitialState(s1); @@ -2388,7 +2238,7 @@ void tst_QStateMachine::animatedGlobalRestoreProperty() QState *s3 = new QState(machine.rootState()); QState *s4 = new QState(machine.rootState()); - s4->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + 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); @@ -2435,7 +2285,7 @@ void tst_QStateMachine::specificTargetValueOfAnimation() s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s2->addTransition(anim, SIGNAL(finished()), s3); machine.setInitialState(s1); @@ -2463,7 +2313,7 @@ void tst_QStateMachine::addDefaultAnimation() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2498,7 +2348,7 @@ void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2536,7 +2386,7 @@ void tst_QStateMachine::addDefaultAnimationForSource() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2568,7 +2418,7 @@ void tst_QStateMachine::addDefaultAnimationForTarget() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2726,7 +2576,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithSource() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2766,7 +2616,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithTarget() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2807,7 +2657,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2847,7 +2697,7 @@ void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2887,7 +2737,7 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); @@ -2927,7 +2777,7 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSource() s2->assignProperty(object, "foo", 2.0); QState *s3 = new QState(machine.rootState()); - s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit"); + QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); -- cgit v0.12