From ebd33883e79b458639e8fe118ccc285641223203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Wed, 10 Dec 2014 15:18:49 +0100 Subject: 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 --- src/corelib/statemachine/qstate.cpp | 11 +++++++++++ src/corelib/statemachine/qstate.h | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/corelib/statemachine') diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index b68dc88fb1..15f6e29fcb 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -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 diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index a9fd04bf00..8a308cf38e 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -35,8 +35,8 @@ #define QSTATE_H #include - #include +#include 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 + QSignalTransition *addTransition(const typename QtPrivate::FunctionPointer::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 transitions() const; -- cgit v1.2.3