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:
parent
d6ffbedc49
commit
63827c4d27
@ -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.
|
||||
*/
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user