From 6ca9c87235b057bc635576b0c414ca789afaf592 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 29 Apr 2009 12:20:11 +0200 Subject: rename QBoundEvent to QWrappedEvent and make it public Result of API review. --- src/corelib/kernel/qcoreevent.h | 2 +- src/corelib/statemachine/qboundevent_p.h | 82 -------------------------- src/corelib/statemachine/qeventtransition.cpp | 34 ++++------- src/corelib/statemachine/qeventtransition.h | 2 - src/corelib/statemachine/qstatemachine.cpp | 58 +++++++++++++++++- src/corelib/statemachine/qwrappedevent.h | 76 ++++++++++++++++++++++++ src/corelib/statemachine/statemachine.pri | 2 +- src/gui/statemachine/qkeyeventtransition.cpp | 18 +++--- src/gui/statemachine/qkeyeventtransition.h | 1 - src/gui/statemachine/qmouseeventtransition.cpp | 18 +++--- tests/auto/qstatemachine/tst_qstatemachine.cpp | 2 +- 11 files changed, 159 insertions(+), 136 deletions(-) delete mode 100644 src/corelib/statemachine/qboundevent_p.h create mode 100644 src/corelib/statemachine/qwrappedevent.h diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index 674b5b0..18188a8 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -270,7 +270,7 @@ public: MacGLClearDrawable = 191, // Internal Cocoa, the window has changed, so we must clear Signal = 192, - Bound = 193, + Wrapped = 193, // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event diff --git a/src/corelib/statemachine/qboundevent_p.h b/src/corelib/statemachine/qboundevent_p.h deleted file mode 100644 index b641ff3..0000000 --- a/src/corelib/statemachine/qboundevent_p.h +++ /dev/null @@ -1,82 +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 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. -// - -#include - -QT_BEGIN_NAMESPACE - -class QBoundEvent : 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() {} - - inline QObject *object() const { return m_object; } - inline QEvent *event() const { return m_event; } - -private: - QObject *m_object; - QEvent *m_event; -}; - -QT_END_NAMESPACE - -#endif 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(event); - return (oe->object() == d->object) - && (oe->event()->type() == d->eventType) - && testEventCondition(oe->event()); + QWrappedEvent *we = static_cast(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/qwrappedevent.h b/src/corelib/statemachine/qwrappedevent.h new file mode 100644 index 0000000..b01c608 --- /dev/null +++ b/src/corelib/statemachine/qwrappedevent.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 QWRAPPEDEVENT_H +#define QWRAPPEDEVENT_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class QObject; + +class Q_CORE_EXPORT QWrappedEvent : public QEvent +{ +public: + QWrappedEvent(QObject *object, QEvent *event); + ~QWrappedEvent(); + + inline QObject *object() const { return m_object; } + inline QEvent *event() const { return m_event; } + +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 diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp index 7c1ae8a..37f4dd9 100644 --- a/src/gui/statemachine/qkeyeventtransition.cpp +++ b/src/gui/statemachine/qkeyeventtransition.cpp @@ -11,6 +11,7 @@ #include "qkeyeventtransition.h" #include "qbasickeyeventtransition_p.h" +#include #if defined(QT_EXPERIMENTAL_SOLUTION) # include "qeventtransition_p.h" @@ -139,19 +140,14 @@ void QKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) /*! \reimp */ -bool QKeyEventTransition::testEventCondition(QEvent *event) const -{ - Q_D(const QKeyEventTransition); - d->transition->setEventType(event->type()); - return QAbstractTransitionPrivate::get(d->transition)->callEventTest(event); -} - -/*! - \reimp -*/ bool QKeyEventTransition::eventTest(QEvent *event) const { - return QEventTransition::eventTest(event); + Q_D(const QKeyEventTransition); + if (!QEventTransition::eventTest(event)) + return false; + QWrappedEvent *we = static_cast(event); + d->transition->setEventType(we->event()->type()); + return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event()); } /*! diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h index ef814db..fa95c1b 100644 --- a/src/gui/statemachine/qkeyeventtransition.h +++ b/src/gui/statemachine/qkeyeventtransition.h @@ -47,7 +47,6 @@ public: protected: void onTransition(); bool eventTest(QEvent *event) const; - bool testEventCondition(QEvent *event) const; private: Q_DISABLE_COPY(QKeyEventTransition) diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp index d6d9b62..353b833 100644 --- a/src/gui/statemachine/qmouseeventtransition.cpp +++ b/src/gui/statemachine/qmouseeventtransition.cpp @@ -11,6 +11,7 @@ #include "qmouseeventtransition.h" #include "qbasicmouseeventtransition_p.h" +#include #include #if defined(QT_EXPERIMENTAL_SOLUTION) @@ -169,19 +170,14 @@ void QMouseEventTransition::setPath(const QPainterPath &path) /*! \reimp */ -bool QMouseEventTransition::testEventCondition(QEvent *event) const -{ - Q_D(const QMouseEventTransition); - d->transition->setEventType(event->type()); - return QAbstractTransitionPrivate::get(d->transition)->callEventTest(event); -} - -/*! - \reimp -*/ bool QMouseEventTransition::eventTest(QEvent *event) const { - return QEventTransition::eventTest(event); + Q_D(const QMouseEventTransition); + if (!QEventTransition::eventTest(event)) + return false; + QWrappedEvent *we = static_cast(event); + d->transition->setEventType(we->event()->type()); + return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event()); } /*! diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 7187b14..b380f6d 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -2857,7 +2857,7 @@ void tst_QStateMachine::parallelStateAssignmentsDone() QState *s1 = new QState(machine.rootState()); machine.setInitialState(s1); - QState *parallelState = new QState(QState::ParallelGroup, machine.rootState()); + QState *parallelState = new QState(QState::ParallelStates, machine.rootState()); parallelState->assignProperty(propertyHolder, "foo", 321); QState *s2 = new QState(parallelState); -- cgit v0.12