QState: Added template PointerToMemberFunction
Added the function pointer to addTransition to take advantage of the new connect syntax. [ChangeLog][QtCore][State Machine] Added an addTransition() overload that takes a pointer-to-member for the signal triggering the transition. Change-Id: Ic97f7983839217ca0c8484b269d38221cbe804e3 Task-number: QTBUG-40293 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
86d04cfe2b
commit
ebd33883e7
|
|
@ -338,6 +338,17 @@ void QState::addTransition(QAbstractTransition *transition)
|
|||
QStateMachinePrivate::get(mach)->maybeRegisterTransition(transition);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QState::addTransition(const QObject *sender, PointerToMemberFunction signal,
|
||||
QAbstractState *target);
|
||||
\since 5.5
|
||||
\overload
|
||||
|
||||
Adds a transition associated with the given \a signal of the given \a sender
|
||||
object, and returns the new QSignalTransition object. The transition has
|
||||
this state as the source, and the given \a target as the target state.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Adds a transition associated with the given \a signal of the given \a sender
|
||||
object, and returns the new QSignalTransition object. The transition has
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
#define QSTATE_H
|
||||
|
||||
#include <QtCore/qabstractstate.h>
|
||||
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qmetaobject.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -74,6 +74,18 @@ public:
|
|||
|
||||
void addTransition(QAbstractTransition *transition);
|
||||
QSignalTransition *addTransition(const QObject *sender, const char *signal, QAbstractState *target);
|
||||
#ifdef Q_QDOC
|
||||
QSignalTransition *addTransition(const QObject *sender, PointerToMemberFunction signal,
|
||||
QAbstractState *target);
|
||||
#else
|
||||
template <typename Func>
|
||||
QSignalTransition *addTransition(const typename QtPrivate::FunctionPointer<Func>::Object *obj,
|
||||
Func signal, QAbstractState *target)
|
||||
{
|
||||
const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal);
|
||||
return addTransition(obj, signalMetaMethod.methodSignature().constData(), target);
|
||||
}
|
||||
#endif // Q_QDOC
|
||||
QAbstractTransition *addTransition(QAbstractState *target);
|
||||
void removeTransition(QAbstractTransition *transition);
|
||||
QList<QAbstractTransition*> transitions() const;
|
||||
|
|
|
|||
|
|
@ -205,12 +205,16 @@ void tst_QState::transitions()
|
|||
QVERIFY(s1.transitions().isEmpty());
|
||||
|
||||
QAbstractTransition *t1 = s1.addTransition(this, SIGNAL(destroyed()), &s2);
|
||||
QAbstractTransition *t1_1 = s1.addTransition(this, &tst_QState::destroyed, &s2);
|
||||
QVERIFY(t1 != 0);
|
||||
QCOMPARE(s1.transitions().count(), 1);
|
||||
QVERIFY(t1_1 != 0);
|
||||
QCOMPARE(s1.transitions().count(), 2);
|
||||
QCOMPARE(s1.transitions().first(), t1);
|
||||
QCOMPARE(s1.transitions().last(), t1_1);
|
||||
QVERIFY(s2.transitions().isEmpty());
|
||||
|
||||
s1.removeTransition(t1);
|
||||
s1.removeTransition(t1_1);
|
||||
QVERIFY(s1.transitions().isEmpty());
|
||||
|
||||
s1.addTransition(t1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue