From c07b3bd9c3c2d7195dfa52547961647a963c8d41 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Wed, 29 Apr 2009 18:20:49 +0200 Subject: Merged local changes. --- doc/src/animation.qdoc | 14 +++++++------- doc/src/groups.qdoc | 2 +- src/corelib/animation/qanimationgroup.cpp | 2 +- src/gui/statemachine/qbasickeyeventtransition.cpp | 2 ++ src/gui/statemachine/qbasicmouseeventtransition.cpp | 2 ++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/src/animation.qdoc b/doc/src/animation.qdoc index 081660c..5eb2eda 100644 --- a/doc/src/animation.qdoc +++ b/doc/src/animation.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \page animation.html + \page animation-overview.html \title The Animation Framework \ingroup architecture \ingroup animation @@ -132,7 +132,7 @@ \endcode This code will move \c button from the top left corner of the - screen to the position (250, 250). + screen to the position (250, 250) in 10 seconds (10000 milliseconds). The example above will do a linear interpolation between the start and end value. It is also possible to set values @@ -162,7 +162,7 @@ that is not declared as a Qt property. The only requirement is that this value has a setter. You can then subclass the class containing the value and declare a property that uses this setter. - Note that all Qt properties requires a getter, so you will need to + Note that each Qt property requires a getter, so you will need to provide a getter yourself if this is not defined. \code @@ -184,9 +184,9 @@ \section1 Animations and the Graphics View Framework When you want to animate \l{QGraphicsItem}s, you also use - QPropertyAnimation. But, unfortunetly, QGraphicsItem does not - inherit QObject. A good solution is to subclass the graphics item - you wish to animate. This class will then also inherit QObject. + QPropertyAnimation. However, QGraphicsItem does not inherit QObject. + A good solution is to subclass the graphics item you wish to animate. + This class will then also inherit QObject. This way, QPropertyAnimation can be used for \l{QGraphicsItem}s. The example below shows how this is done. Another possibility is to inherit QGraphicsWidget, which already is a QObject. @@ -326,7 +326,7 @@ When using a \l{The State Machine Framework}{state machine}, we have a special state, QAnimationState, that will play one or more animations. - + The QState::addAnimatedTransition() convenience function lets you associate an animation to a state transition. The function will create the QAnimationState for you, and insert it into the state diff --git a/doc/src/groups.qdoc b/doc/src/groups.qdoc index 0411c3a..fda54dc 100644 --- a/doc/src/groups.qdoc +++ b/doc/src/groups.qdoc @@ -69,7 +69,7 @@ */ /*! - \group animations + \group animation \ingroup groups \title Animation Framework diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp index 03573bb..0d87527 100644 --- a/src/corelib/animation/qanimationgroup.cpp +++ b/src/corelib/animation/qanimationgroup.cpp @@ -41,7 +41,7 @@ /*! \class QAnimationGroup - \brief The QAnimationGroup is an abstract base class for group of animations. + \brief The QAnimationGroup class is an abstract base class for groups of animations. \since 4.5 \ingroup animation \preliminary diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp index 4e3fa11..189332d 100644 --- a/src/gui/statemachine/qbasickeyeventtransition.cpp +++ b/src/gui/statemachine/qbasickeyeventtransition.cpp @@ -25,6 +25,8 @@ QT_BEGIN_NAMESPACE /*! \internal \class QBasicKeyEventTransition + \since 4.6 + \ingroup statemachine \brief The QBasicKeyEventTransition class provides a transition for Qt key events. */ diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp index 83254dc..a330c78 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition.cpp +++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp @@ -25,6 +25,8 @@ QT_BEGIN_NAMESPACE /*! \internal \class QBasicMouseEventTransition + \since 4.6 + \ingroup statemachine \brief The QBasicMouseEventTransition class provides a transition for Qt mouse events. */ -- cgit v0.12 From a82714c6c82f682e02969d9afa551f37f8132653 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 13 May 2009 13:56:44 +0200 Subject: correctly handle multiple event transitions for same (object,event) The event filter was not removed at the right time. We now store the number of active event transitions for a particular (object,event) and only remove the filtering when the count drops to zero. --- src/corelib/statemachine/qstatemachine.cpp | 19 ++++++---- src/corelib/statemachine/qstatemachine_p.h | 2 +- tests/auto/qstatemachine/tst_qstatemachine.cpp | 48 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 2f620c7..046fbb4 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1407,7 +1407,7 @@ void QStateMachinePrivate::registerEventTransition(QEventTransition *transition) QObjectPrivate *od = QObjectPrivate::get(object); if (!od->eventFilters.contains(q)) object->installEventFilter(q); - qobjectEvents[object].insert(transition->eventType()); + ++qobjectEvents[object][transition->eventType()]; QEventTransitionPrivate::get(transition)->registered = true; #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": added event transition from" << transition->sourceState() @@ -1422,11 +1422,18 @@ void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transitio if (!QEventTransitionPrivate::get(transition)->registered) return; QObject *object = QEventTransitionPrivate::get(transition)->object; - QSet &events = qobjectEvents[object]; - events.remove(transition->eventType()); - if (events.isEmpty()) { - qobjectEvents.remove(object); - object->removeEventFilter(q); + QHash &events = qobjectEvents[object]; + Q_ASSERT(events.value(transition->eventType()) > 0); + if (--events[transition->eventType()] == 0) { + events.remove(transition->eventType()); + int sum = 0; + QHash::const_iterator it; + for (it = events.constBegin(); it != events.constEnd(); ++it) + sum += it.value(); + if (sum == 0) { + qobjectEvents.remove(object); + object->removeEventFilter(q); + } } QEventTransitionPrivate::get(transition)->registered = false; } diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 9b4b861..dfa5575 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -200,7 +200,7 @@ public: QHash > connections; #ifndef QT_NO_STATEMACHINE_EVENTFILTER - QHash > qobjectEvents; + QHash > qobjectEvents; #endif QHash delayedEvents; diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 3f94ad9..f8a778a 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1881,6 +1881,54 @@ void tst_QStateMachine::eventTransitions() QTRY_COMPARE(finishedSpy.count(), 1); } + // Multiple transitions for same (object,event) + { + QStateMachine machine; + QState *s0 = new QState(machine.rootState()); + QState *s1 = new QState(machine.rootState()); + QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress); + t0->setTargetState(s1); + s0->addTransition(t0); + QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonPress); + t1->setTargetState(s0); + s1->addTransition(t1); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.setInitialState(s0); + machine.start(); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s0)); + + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + s0->removeTransition(t0); + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s0)); + + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s0)); + + s1->removeTransition(t1); + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s0)); + + s0->addTransition(t0); + s1->addTransition(t1); + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + } } void tst_QStateMachine::historyStates() -- cgit v0.12 From 2a4f5a1b4e6e9632ab18c81c3e06ebf2061cd765 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Thu, 14 May 2009 14:17:18 +0200 Subject: Doc: Marked up a link correctly. Reviewed-by: David Boddie --- doc/src/groups.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/groups.qdoc b/doc/src/groups.qdoc index fda54dc..3c4da53 100644 --- a/doc/src/groups.qdoc +++ b/doc/src/groups.qdoc @@ -76,7 +76,7 @@ \brief Classes for animations, states and transitions. These classes provide a framework for creating both simple and complex - animations. The Animation Framework also provides states and animated + animations. \l{The Animation Framework} also provides states and animated transitions, making it easy to create animated stateful forms. */ -- cgit v0.12