Add PointerToMemberFunction for ctor of QSignalTransition

[ChangeLog][QtCore][State Machine] Added constructor overload that
takes a pointer-to-member for the QSignalTransition.

Change-Id: I80ac6e16d0edf7d2ab09882b6f6db4cbd73364e1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
André Klitzing 2015-08-31 15:04:51 +02:00
parent d6ffbedc49
commit 63827c4d27
3 changed files with 54 additions and 0 deletions

View File

@ -145,6 +145,19 @@ QSignalTransition::QSignalTransition(const QObject *sender, const char *signal,
d->maybeRegister();
}
/*!
\fn QSignalTransition::QSignalTransition(const QObject *sender,
PointerToMemberFunction signal, QState *sourceState);
\since 5.7
\overload
Constructs a new signal transition associated with the given \a signal of
the given \a sender object and with the given \a sourceSate.
This constructor is enabled if compiler supports delegating constructor.
\sa Q_COMPILER_DELEGATING_CONSTRUCTORS
*/
/*!
Destroys this signal transition.
*/

View File

@ -35,6 +35,7 @@
#define QSIGNALTRANSITION_H
#include <QtCore/qabstracttransition.h>
#include <QtCore/qmetaobject.h>
QT_BEGIN_NAMESPACE
@ -52,6 +53,18 @@ public:
QSignalTransition(QState *sourceState = Q_NULLPTR);
QSignalTransition(const QObject *sender, const char *signal,
QState *sourceState = Q_NULLPTR);
#ifdef Q_QDOC
QSignalTransition(const QObject *object, PointerToMemberFunction signal,
QState *sourceState = Q_NULLPTR);
#elif defined(Q_COMPILER_DELEGATING_CONSTRUCTORS)
template <typename Func>
QSignalTransition(const typename QtPrivate::FunctionPointer<Func>::Object *obj,
Func sig, QState *srcState = Q_NULLPTR)
: QSignalTransition(obj, QMetaMethod::fromSignal(sig).methodSignature().constData(), srcState)
{
}
#endif
~QSignalTransition();
QObject *senderObject() const;

View File

@ -238,6 +238,9 @@ private slots:
void multiTargetTransitionInsideParallelStateGroup();
void signalTransitionNormalizeSignature();
#ifdef Q_COMPILER_DELEGATING_CONSTRUCTORS
void createPointerToMemberSignalTransition();
#endif
void createSignalTransitionWhenRunning();
void createEventTransitionWhenRunning();
void signalTransitionSenderInDifferentThread();
@ -5876,6 +5879,31 @@ void tst_QStateMachine::signalTransitionNormalizeSignature()
TEST_ACTIVE_CHANGED(s1, 1);
}
#ifdef Q_COMPILER_DELEGATING_CONSTRUCTORS
void tst_QStateMachine::createPointerToMemberSignalTransition()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.start();
TEST_ACTIVE_CHANGED(s1, 1);
QTRY_VERIFY(machine.configuration().contains(s1));
QState *s2 = new QState(&machine);
DEFINE_ACTIVE_SPY(s2);
SignalEmitter emitter;
QSignalTransition *t1 = new QSignalTransition(&emitter, &SignalEmitter::signalWithNoArg, s1);
QCOMPARE(t1->sourceState(), s1);
t1->setTargetState(s2);
s1->addTransition(t1);
emitter.emitSignalWithNoArg();
TEST_ACTIVE_CHANGED(s1, 2);
TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
}
#endif
void tst_QStateMachine::createSignalTransitionWhenRunning()
{
QStateMachine machine;