diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-04-29 10:20:11 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-04-29 10:20:11 (GMT) |
commit | 6ca9c87235b057bc635576b0c414ca789afaf592 (patch) | |
tree | 3ba290fc3edabbb1372dba253cbe5d3526f80f14 /src/corelib/statemachine | |
parent | 35f353f16f696a7362d3e899c9a7e2066dc09c65 (diff) | |
download | Qt-6ca9c87235b057bc635576b0c414ca789afaf592.zip Qt-6ca9c87235b057bc635576b0c414ca789afaf592.tar.gz Qt-6ca9c87235b057bc635576b0c414ca789afaf592.tar.bz2 |
rename QBoundEvent to QWrappedEvent and make it public
Result of API review.
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r-- | src/corelib/statemachine/qeventtransition.cpp | 34 | ||||
-rw-r--r-- | src/corelib/statemachine/qeventtransition.h | 2 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 58 | ||||
-rw-r--r-- | src/corelib/statemachine/qwrappedevent.h (renamed from src/corelib/statemachine/qboundevent_p.h) | 38 | ||||
-rw-r--r-- | src/corelib/statemachine/statemachine.pri | 2 |
5 files changed, 83 insertions, 51 deletions
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp index 2126373..cbd03bd 100644 --- a/src/corelib/statemachine/qeventtransition.cpp +++ b/src/corelib/statemachine/qeventtransition.cpp @@ -41,7 +41,7 @@ #include "qeventtransition.h" #include "qeventtransition_p.h" -#include "qboundevent_p.h" +#include "qwrappedevent.h" #include "qstate.h" #include "qstate_p.h" #include "qstatemachine.h" @@ -79,10 +79,11 @@ QT_BEGIN_NAMESPACE \section1 Subclassing - Many event classes have attributes in addition to the event type itself. - The testEventCondition() function can be reimplemented to check attributes - of an event instance in order to determine whether the transition should be - triggered or not. + When reimplementing the eventTest() function, you should first call the base + implementation to verify that the event is a QWrappedEvent for the proper + object and event type. You may then cast the event to a QWrappedEvent and + get the original event by calling QWrappedEvent::event(), and perform + additional checks on that object. \sa QState::addTransition() */ @@ -257,12 +258,11 @@ bool QEventTransition::eventTest(QEvent *event) const #ifdef QT_STATEMACHINE_SOLUTION if (event->type() == QEvent::Type(QEvent::User-3)) { #else - if (event->type() == QEvent::Bound) { + if (event->type() == QEvent::Wrapped) { #endif - QBoundEvent *oe = static_cast<QBoundEvent*>(event); - return (oe->object() == d->object) - && (oe->event()->type() == d->eventType) - && testEventCondition(oe->event()); + QWrappedEvent *we = static_cast<QWrappedEvent*>(event); + return (we->object() == d->object) + && (we->event()->type() == d->eventType); } return false; } @@ -275,20 +275,6 @@ 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(). - - Reimplement this function if you have custom conditions associated with - the transition. The default implementation always returns true. -*/ -bool QEventTransition::testEventCondition(QEvent *event) const -{ - Q_UNUSED(event); - return true; -} - -/*! \reimp */ bool QEventTransition::event(QEvent *e) diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h index 82fcd36..484602c 100644 --- a/src/corelib/statemachine/qeventtransition.h +++ b/src/corelib/statemachine/qeventtransition.h @@ -77,8 +77,6 @@ public: void setEventType(QEvent::Type type); protected: - virtual bool testEventCondition(QEvent *event) const; // ### name - bool eventTest(QEvent *event) const; void onTransition(); diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 0ddeac9..b0f6cd6 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -62,7 +62,7 @@ #ifndef QT_NO_STATEMACHINE_EVENTFILTER #include "qeventtransition.h" #include "qeventtransition_p.h" -#include "qboundevent_p.h" +#include "qwrappedevent.h" #endif #ifndef QT_NO_ANIMATION @@ -1827,7 +1827,7 @@ bool QStateMachine::eventFilter(QObject *watched, QEvent *event) Q_D(QStateMachine); Q_ASSERT(d->qobjectEvents.contains(watched)); if (d->qobjectEvents[watched].contains(event->type())) - postEvent(new QBoundEvent(watched, d->handler->cloneEvent(event))); + postEvent(new QWrappedEvent(watched, d->handler->cloneEvent(event))); return false; } #endif @@ -2140,6 +2140,60 @@ QSignalEvent::~QSignalEvent() Returns the arguments of the signal. */ + +/*! + \class QWrappedEvent + + \brief The QWrappedEvent class holds a clone of an event associated with a QObject. + + \since 4.6 + \ingroup statemachine + + A wrapped event is generated by a QStateMachine in response to a Qt + event. The QEventTransition class provides a transition associated with a + such an event. QWrappedEvent is part of \l{The State Machine Framework}. + + The object() function returns the object that generated the event. The + event() function returns a clone of the original event. + + \sa QEventTransition +*/ + +/*! + \internal + + Constructs a new QWrappedEvent object with the given \a object + and \a event. +*/ +QWrappedEvent::QWrappedEvent(QObject *object, QEvent *event) +#ifdef QT_STATEMACHINE_SOLUTION + : QEvent(QEvent::Type(QEvent::User-3)) +#else + : QEvent(QEvent::Wrapped) +#endif + , m_object(object), m_event(event) +{ +} + +/*! + Destroys this QWrappedEvent. +*/ +QWrappedEvent::~QWrappedEvent() +{ +} + +/*! + \fn QWrappedEvent::object() const + + Returns the object that the event is associated with. +*/ + +/*! + \fn QWrappedEvent::event() const + + Returns a clone of the original event. +*/ + QT_END_NAMESPACE #include "moc_qstatemachine.cpp" diff --git a/src/corelib/statemachine/qboundevent_p.h b/src/corelib/statemachine/qwrappedevent.h index b641ff3..b01c608 100644 --- a/src/corelib/statemachine/qboundevent_p.h +++ b/src/corelib/statemachine/qwrappedevent.h @@ -39,35 +39,24 @@ ** ****************************************************************************/ -#ifndef QBOUNDEVENT_P_H -#define QBOUNDEVENT_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 QWRAPPEDEVENT_H +#define QWRAPPEDEVENT_H #include <QtCore/qcoreevent.h> +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE -class QBoundEvent : public QEvent +QT_MODULE(Core) + +class QObject; + +class Q_CORE_EXPORT QWrappedEvent : public QEvent { public: - QBoundEvent(QObject *object, QEvent *event) -#ifdef QT_STATEMACHINE_SOLUTION - : QEvent(QEvent::Type(QEvent::User-3)), -#else - : QEvent(QEvent::Bound), -#endif - m_object(object), m_event(event) {} - ~QBoundEvent() {} + QWrappedEvent(QObject *object, QEvent *event); + ~QWrappedEvent(); inline QObject *object() const { return m_object; } inline QEvent *event() const { return m_event; } @@ -75,8 +64,13 @@ public: private: QObject *m_object; QEvent *m_event; + +private: + Q_DISABLE_COPY(QWrappedEvent) }; QT_END_NAMESPACE +QT_END_HEADER + #endif diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri index 69f887c..5b19bc1 100644 --- a/src/corelib/statemachine/statemachine.pri +++ b/src/corelib/statemachine/statemachine.pri @@ -23,7 +23,7 @@ SOURCES += $$PWD/qstatemachine.cpp \ $$PWD/qsignaltransition.cpp !contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) { -HEADERS += $$PWD/qboundevent_p.h \ +HEADERS += $$PWD/qwrappedevent.h \ $$PWD/qeventtransition.h \ $$PWD/qeventtransition_p.h SOURCES += $$PWD/qeventtransition.cpp |