summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-04-27 16:07:03 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-04-27 16:07:03 (GMT)
commita460bee2b3051bf6a5176b5c620f81ff962a7f53 (patch)
treecd16498e44c7ab61b527e4c192969d8101ccb5ad /src/corelib
parent53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5 (diff)
downloadQt-a460bee2b3051bf6a5176b5c620f81ff962a7f53.zip
Qt-a460bee2b3051bf6a5176b5c620f81ff962a7f53.tar.gz
Qt-a460bee2b3051bf6a5176b5c620f81ff962a7f53.tar.bz2
replace QStateFinished{Event,Transition} by QState::finished() signal
Not worth it having two public classes when the same can be achieved by having a signal.
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/statemachine/qfinalstate.cpp2
-rw-r--r--src/corelib/statemachine/qstate.cpp30
-rw-r--r--src/corelib/statemachine/qstate.h5
-rw-r--r--src/corelib/statemachine/qstate_p.h2
-rw-r--r--src/corelib/statemachine/qstatefinishedevent.h70
-rw-r--r--src/corelib/statemachine/qstatefinishedtransition.cpp182
-rw-r--r--src/corelib/statemachine/qstatefinishedtransition.h88
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp60
-rw-r--r--src/corelib/statemachine/statemachine.pri3
9 files changed, 21 insertions, 421 deletions
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
index 16e080e..6a1b608 100644
--- a/src/corelib/statemachine/qfinalstate.cpp
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -76,8 +76,6 @@ QT_BEGIN_NAMESPACE
machine.setInitialState(s1);
machine.start();
\endcode
-
- \sa QStateFinishedTransition
*/
class QFinalStatePrivate : public QAbstractStatePrivate
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 56a855e..9bda250 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -46,7 +46,6 @@
#include "qabstracttransition.h"
#include "qabstracttransition_p.h"
#include "qsignaltransition.h"
-#include "qstatefinishedtransition.h"
#include "qstatemachine.h"
#include "qstatemachine_p.h"
@@ -75,9 +74,6 @@ QT_BEGIN_NAMESPACE
The addHistoryState() function adds a history state.
- The addFinishedTransition() function creates and adds a transition that's
- triggered when a final child state is entered.
-
The setErrorState() sets the state's error state. The error state is the
state that the state machine will transition to if an error is detected when
attempting to enter the state (e.g. because no initial state has been set).
@@ -134,6 +130,12 @@ const QStatePrivate *QStatePrivate::get(const QState *q)
return q->d_func();
}
+void QStatePrivate::emitFinished()
+{
+ Q_Q(QState);
+ emit q->finished();
+}
+
/*!
Constructs a new state with the given \a parent state.
*/
@@ -294,20 +296,6 @@ QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
return trans;
}
-/*!
- Adds a transition that's triggered by the finished event of this state, and
- returns the new QStateFinishedTransition object. The transition has the
- given \a target state.
-
- \sa QStateFinishedEvent
-*/
-QStateFinishedTransition *QState::addFinishedTransition(QAbstractState *target)
-{
- QStateFinishedTransition *trans = new QStateFinishedTransition(this, QList<QAbstractState*>() << target);
- addTransition(trans);
- return trans;
-}
-
namespace {
// ### Make public?
@@ -431,4 +419,10 @@ bool QState::event(QEvent *e)
return QAbstractState::event(e);
}
+/*!
+ \fn QState::finished()
+
+ This signal is emitted when a final child state of this state is entered.
+*/
+
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 7c64c80..70211c1 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -57,7 +57,6 @@ QT_MODULE(Core)
class QAbstractTransition;
class QHistoryState;
class QSignalTransition;
-class QStateFinishedTransition;
class QStatePrivate;
class Q_CORE_EXPORT QState : public QAbstractState
@@ -84,7 +83,6 @@ public:
QAbstractTransition *addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target);
QAbstractTransition *addTransition(QAbstractState *target);
- QStateFinishedTransition *addFinishedTransition(QAbstractState *target);
void removeTransition(QAbstractTransition *transition);
QList<QAbstractTransition*> transitions() const;
@@ -93,6 +91,9 @@ public:
QAbstractState *initialState() const;
void setInitialState(QAbstractState *state);
+Q_SIGNALS:
+ void finished();
+
protected:
void onEntry();
void onExit();
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
index 8d040d0..2df6823 100644
--- a/src/corelib/statemachine/qstate_p.h
+++ b/src/corelib/statemachine/qstate_p.h
@@ -74,6 +74,8 @@ public:
QList<QHistoryState*> historyStates() const;
QList<QAbstractTransition*> transitions() const;
+ void emitFinished();
+
QAbstractState *errorState;
bool isParallelGroup;
QAbstractState *initialState;
diff --git a/src/corelib/statemachine/qstatefinishedevent.h b/src/corelib/statemachine/qstatefinishedevent.h
deleted file mode 100644
index c2f81f7..0000000
--- a/src/corelib/statemachine/qstatefinishedevent.h
+++ /dev/null
@@ -1,70 +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 QSTATEFINISHEDEVENT_H
-#define QSTATEFINISHEDEVENT_H
-
-#include <QtCore/qcoreevent.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QState;
-
-class Q_CORE_EXPORT QStateFinishedEvent : public QEvent
-{
-public:
- QStateFinishedEvent(QState *state);
- ~QStateFinishedEvent();
-
- QState *state() const;
-
-private:
- QState *m_state;
- void *d;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qstatefinishedtransition.cpp b/src/corelib/statemachine/qstatefinishedtransition.cpp
deleted file mode 100644
index 151a274..0000000
--- a/src/corelib/statemachine/qstatefinishedtransition.cpp
+++ /dev/null
@@ -1,182 +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 "qstatefinishedtransition.h"
-#include "qstatefinishedevent.h"
-#include "qabstracttransition_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QStateFinishedTransition
-
- \brief The QStateFinishedTransition class provides a transition that triggers when a state is finished.
-
- \ingroup statemachine
-
- A state is finished when one of its final child states (a QFinalState) is
- entered; this will cause a QStateFinishedEvent to be generated. The
- QStateFinishedTransition class provides a way of associating a transition
- with such an event. QStateFinishedTransition is part of \l{The State Machine
- Framework}.
-
- \code
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
- QState *s11 = new QState(s1);
- QFinalState *s12 = new QFinalState(s1);
- s11->addTransition(s12);
-
- QState *s2 = new QState(machine.rootState());
- QStateFinishedTransition *finishedTransition = new QStateFinishedTransition(s1);
- finishedTransition->setTargetState(s2);
- s1->addTransition(finishedTransition);
- \endcode
-
- \sa QState::addFinishedTransition(), QStateFinishedEvent
-*/
-
-/*!
- \property QStateFinishedTransition::state
-
- \brief the state whose QStateFinishedEvent this transition is associated with
-*/
-
-class QStateFinishedTransitionPrivate : public QAbstractTransitionPrivate
-{
- Q_DECLARE_PUBLIC(QStateFinishedTransition)
-public:
- QStateFinishedTransitionPrivate();
-
- static QStateFinishedTransitionPrivate *get(QStateFinishedTransition *q);
-
- QState *state;
-};
-
-QStateFinishedTransitionPrivate::QStateFinishedTransitionPrivate()
-{
- state = 0;
-}
-
-QStateFinishedTransitionPrivate *QStateFinishedTransitionPrivate::get(QStateFinishedTransition *q)
-{
- return q->d_func();
-}
-
-/*!
- Constructs a new QStateFinishedTransition object that has the given \a
- sourceState.
-*/
-QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
- : QAbstractTransition(*new QStateFinishedTransitionPrivate, sourceState)
-{
-}
-
-/*!
- Constructs a new QStateFinishedTransition object associated with the given
- \a state, and that has the given \a targets and \a sourceState.
-*/
-QStateFinishedTransition::QStateFinishedTransition(
- QState *state, const QList<QAbstractState*> &targets, QState *sourceState)
- : QAbstractTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
-{
- Q_D(QStateFinishedTransition);
- d->state = state;
-}
-
-/*!
- Destroys this QStateFinishedTransition.
-*/
-QStateFinishedTransition::~QStateFinishedTransition()
-{
-}
-
-/*!
- Returns the state associated with this QStateFinishedTransition.
-*/
-QState *QStateFinishedTransition::state() const
-{
- Q_D(const QStateFinishedTransition);
- return d->state;
-}
-
-/*!
- Sets the \a state associated with this QStateFinishedTransition.
-*/
-void QStateFinishedTransition::setState(QState *state)
-{
- Q_D(QStateFinishedTransition);
- d->state = state;
-}
-
-/*!
- \reimp
-*/
-bool QStateFinishedTransition::eventTest(QEvent *event) const
-{
- Q_D(const QStateFinishedTransition);
-#ifndef QT_STATEMACHINE_SOLUTION
- if (event->type() == QEvent::StateFinished) {
-#else
- if (event->type() == QEvent::Type(QEvent::User-2)) {
-#endif
- QStateFinishedEvent *sfe = static_cast<QStateFinishedEvent*>(event);
- return (sfe->state() == d->state);
- }
- return false;
-}
-
-/*!
- \reimp
-*/
-void QStateFinishedTransition::onTransition()
-{
-}
-
-/*!
- \reimp
-*/
-bool QStateFinishedTransition::event(QEvent *e)
-{
- return QAbstractTransition::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstatefinishedtransition.h b/src/corelib/statemachine/qstatefinishedtransition.h
deleted file mode 100644
index ed86288..0000000
--- a/src/corelib/statemachine/qstatefinishedtransition.h
+++ /dev/null
@@ -1,88 +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 QSTATEFINISHEDTRANSITION_H
-#define QSTATEFINISHEDTRANSITION_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include <QtCore/qabstracttransition.h>
-#else
-#include "qabstracttransition.h"
-#endif
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QState;
-
-class QStateFinishedTransitionPrivate;
-class Q_CORE_EXPORT QStateFinishedTransition : public QAbstractTransition
-{
- Q_OBJECT
- Q_PROPERTY(QState* state READ state WRITE setState)
-public:
- QStateFinishedTransition(QState *sourceState = 0);
- QStateFinishedTransition(QState *state, const QList<QAbstractState*> &targets,
- QState *sourceState = 0);
- ~QStateFinishedTransition();
-
- QState *state() const; // ### name
- void setState(QState *state);
-
-protected:
- bool eventTest(QEvent *event) const;
- void onTransition();
-
- bool event(QEvent *e);
-
-private:
- Q_DISABLE_COPY(QStateFinishedTransition)
- Q_DECLARE_PRIVATE(QStateFinishedTransition)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 8cee1fc..632390f 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -52,8 +52,6 @@
#include "qfinalstate.h"
#include "qhistorystate.h"
#include "qhistorystate_p.h"
-#include "qstatefinishedevent.h"
-#include "qstatefinishedtransition.h"
#include "qstate.h"
#include "qstate_p.h"
#ifndef QT_STATEMACHINE_SOLUTION
@@ -524,9 +522,9 @@ QList<QAbstractState*> QStateMachinePrivate::enterStates(const QList<QAbstractTr
if (parent) {
QState *grandparent = parent->parentState();
#ifdef QSTATEMACHINE_DEBUG
- qDebug() << q << ": posting finished event for" << parent;
+ qDebug() << q << ": emitting finished signal for" << parent;
#endif
- internalEventQueue.append(new QStateFinishedEvent(parent));
+ QStatePrivate::get(parent)->emitFinished();
if (grandparent && isParallel(grandparent)) {
bool allChildStatesFinal = true;
QList<QAbstractState*> childStates = QStatePrivate::get(grandparent)->childStates();
@@ -539,9 +537,9 @@ QList<QAbstractState*> QStateMachinePrivate::enterStates(const QList<QAbstractTr
}
if (allChildStatesFinal) {
#ifdef QSTATEMACHINE_DEBUG
- qDebug() << q << ": posting finished event for" << grandparent;
+ qDebug() << q << ": emitting finished signal for" << grandparent;
#endif
- internalEventQueue.append(new QStateFinishedEvent(grandparent));
+ QStatePrivate::get(grandparent)->emitFinished();
}
}
}
@@ -2102,56 +2100,6 @@ QSignalEvent::~QSignalEvent()
Returns the arguments of the signal.
*/
-/*!
- \class QStateFinishedEvent
-
- \brief The QStateFinishedEvent class contains parameters that describe a state that has finished.
-
- \since 4.6
- \ingroup statemachine
-
- A state is finished when one of its final child states (a QFinalState) is
- entered; this will cause a QStateFinishedEvent to be generated by the state
- machine. QStateFinishedEvent is part of \l{The State Machine Framework}.
-
- Typically you do not create QStateFinishedEvent objects yourself, but rather
- use QStateFinishedTransition to create a transition that's triggered by a
- state's finished event.
-
- \sa QStateFinishedTransition
-*/
-
-/*!
- \internal
-
- Constructs a new QStateFinishedEvent object associated with the given \a state.
-*/
-QStateFinishedEvent::QStateFinishedEvent(QState *state)
- :
-#ifndef QT_STATEMACHINE_SOLUTION
- QEvent(StateFinished)
-#else
- QEvent(QEvent::Type(QEvent::User-2))
-#endif
- , m_state(state), d(0)
-{
-}
-
-/*!
- Destroys this QStateFinishedEvent.
-*/
-QStateFinishedEvent::~QStateFinishedEvent()
-{
-}
-
-/*!
- Returns the state associated with this QStateFinishedEvent.
-*/
-QState *QStateFinishedEvent::state() const
-{
- return m_state;
-}
-
QT_END_NAMESPACE
#include "moc_qstatemachine.cpp"
diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri
index 620c7a0..69f887c 100644
--- a/src/corelib/statemachine/statemachine.pri
+++ b/src/corelib/statemachine/statemachine.pri
@@ -10,8 +10,6 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qhistorystate_p.h \
$$PWD/qabstracttransition.h \
$$PWD/qabstracttransition_p.h \
- $$PWD/qstatefinishedevent.h \
- $$PWD/qstatefinishedtransition.h \
$$PWD/qsignalevent.h \
$$PWD/qsignaltransition.h \
$$PWD/qsignaltransition_p.h
@@ -22,7 +20,6 @@ SOURCES += $$PWD/qstatemachine.cpp \
$$PWD/qfinalstate.cpp \
$$PWD/qhistorystate.cpp \
$$PWD/qabstracttransition.cpp \
- $$PWD/qstatefinishedtransition.cpp \
$$PWD/qsignaltransition.cpp
!contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) {