summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qcoreevent.h2
-rw-r--r--src/corelib/statemachine/qeventtransition.cpp34
-rw-r--r--src/corelib/statemachine/qeventtransition.h2
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp58
-rw-r--r--src/corelib/statemachine/qwrappedevent.h (renamed from src/corelib/statemachine/qboundevent_p.h)38
-rw-r--r--src/corelib/statemachine/statemachine.pri2
-rw-r--r--src/gui/statemachine/qkeyeventtransition.cpp18
-rw-r--r--src/gui/statemachine/qkeyeventtransition.h1
-rw-r--r--src/gui/statemachine/qmouseeventtransition.cpp18
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp2
10 files changed, 99 insertions, 76 deletions
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/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
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 <QtCore/qwrappedevent.h>
#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<QWrappedEvent*>(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 <QtCore/qwrappedevent.h>
#include <QtGui/qpainterpath.h>
#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<QWrappedEvent*>(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);