Make it possible to connect to QAbstract{State,Transtion} private signals.
Use the same trick as used for private signals in the models. Change-Id: I4235788490cae0e3d554565621d145652dc5b0ca Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
536ec793b6
commit
f108fceb2c
@ -119,13 +119,13 @@ void QAbstractStatePrivate::callOnExit(QEvent *e)
|
|||||||
void QAbstractStatePrivate::emitEntered()
|
void QAbstractStatePrivate::emitEntered()
|
||||||
{
|
{
|
||||||
Q_Q(QAbstractState);
|
Q_Q(QAbstractState);
|
||||||
emit q->entered();
|
emit q->entered(QAbstractState::QPrivateSignal());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAbstractStatePrivate::emitExited()
|
void QAbstractStatePrivate::emitExited()
|
||||||
{
|
{
|
||||||
Q_Q(QAbstractState);
|
Q_Q(QAbstractState);
|
||||||
emit q->exited();
|
emit q->exited(QAbstractState::QPrivateSignal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -65,11 +65,16 @@ public:
|
|||||||
QStateMachine *machine() const;
|
QStateMachine *machine() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
#if !defined(Q_MOC_RUN) && !defined(qdoc)
|
void entered(
|
||||||
private: // can only be emitted by QAbstractState
|
#if !defined(qdoc)
|
||||||
|
QPrivateSignal
|
||||||
#endif
|
#endif
|
||||||
void entered();
|
);
|
||||||
void exited();
|
void exited(
|
||||||
|
#if !defined(qdoc)
|
||||||
|
QPrivateSignal
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QAbstractState(QState *parent = 0);
|
QAbstractState(QState *parent = 0);
|
||||||
|
@ -145,7 +145,7 @@ QState *QAbstractTransitionPrivate::sourceState() const
|
|||||||
void QAbstractTransitionPrivate::emitTriggered()
|
void QAbstractTransitionPrivate::emitTriggered()
|
||||||
{
|
{
|
||||||
Q_Q(QAbstractTransition);
|
Q_Q(QAbstractTransition);
|
||||||
emit q->triggered();
|
emit q->triggered(QAbstractTransition::QPrivateSignal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -88,10 +88,11 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
#if !defined(Q_MOC_RUN) && !defined(qdoc)
|
void triggered(
|
||||||
private: // can only be emitted by QAbstractTransition
|
#if !defined(qdoc)
|
||||||
|
QPrivateSignal
|
||||||
#endif
|
#endif
|
||||||
void triggered();
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool eventTest(QEvent *event) = 0;
|
virtual bool eventTest(QEvent *event) = 0;
|
||||||
|
@ -57,6 +57,7 @@ private slots:
|
|||||||
void assignPropertyTwice();
|
void assignPropertyTwice();
|
||||||
void historyInitialState();
|
void historyInitialState();
|
||||||
void transitions();
|
void transitions();
|
||||||
|
void privateSignals();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool functionCalled;
|
bool functionCalled;
|
||||||
@ -237,5 +238,125 @@ void tst_QState::transitions()
|
|||||||
QCOMPARE(s21->transitions().first(), t3);
|
QCOMPARE(s21->transitions().first(), t3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MyState : public QState
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyState(QState *parent = 0)
|
||||||
|
: QState(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void emitPrivateSignals()
|
||||||
|
{
|
||||||
|
// These deliberately do not compile
|
||||||
|
// emit entered();
|
||||||
|
// emit exited();
|
||||||
|
//
|
||||||
|
// emit entered(QPrivateSignal());
|
||||||
|
// emit exited(QPrivateSignal());
|
||||||
|
//
|
||||||
|
// emit entered(QAbstractState::QPrivateSignal());
|
||||||
|
// emit exited(QAbstractState::QPrivateSignal());
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyTransition : public QSignalTransition
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyTransition(QObject * sender, const char * signal, QState *sourceState = 0)
|
||||||
|
: QSignalTransition(sender, signal, sourceState)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void emitPrivateSignals()
|
||||||
|
{
|
||||||
|
// These deliberately do not compile
|
||||||
|
// emit triggered();
|
||||||
|
//
|
||||||
|
// emit triggered(QPrivateSignal());
|
||||||
|
//
|
||||||
|
// emit triggered(QAbstractTransition::QPrivateSignal());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SignalConnectionTester : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SignalConnectionTester(QObject *parent = 0)
|
||||||
|
: QObject(parent), testPassed(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void testSlot()
|
||||||
|
{
|
||||||
|
testPassed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool testPassed;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestTrigger : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TestTrigger(QObject *parent = 0)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void emitTrigger()
|
||||||
|
{
|
||||||
|
emit trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void trigger();
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_QState::privateSignals()
|
||||||
|
{
|
||||||
|
QStateMachine machine;
|
||||||
|
|
||||||
|
QState *s1 = new QState(&machine);
|
||||||
|
MyState *s2 = new MyState(&machine);
|
||||||
|
|
||||||
|
TestTrigger testTrigger;
|
||||||
|
|
||||||
|
MyTransition *t1 = new MyTransition(&testTrigger, SIGNAL(trigger()), s1);
|
||||||
|
s1->addTransition(t1);
|
||||||
|
t1->setTargetState(s2);
|
||||||
|
|
||||||
|
machine.setInitialState(s1);
|
||||||
|
machine.start();
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
|
SignalConnectionTester s1Tester;
|
||||||
|
SignalConnectionTester s2Tester;
|
||||||
|
SignalConnectionTester t1Tester;
|
||||||
|
|
||||||
|
QObject::connect(s1, &QState::exited, &s1Tester, &SignalConnectionTester::testSlot);
|
||||||
|
QObject::connect(s2, &QState::entered, &s2Tester, &SignalConnectionTester::testSlot);
|
||||||
|
QObject::connect(t1, &QSignalTransition::triggered, &t1Tester, &SignalConnectionTester::testSlot);
|
||||||
|
|
||||||
|
testTrigger.emitTrigger();
|
||||||
|
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
|
QVERIFY(s1Tester.testPassed);
|
||||||
|
QVERIFY(s2Tester.testPassed);
|
||||||
|
QVERIFY(t1Tester.testPassed);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QState)
|
QTEST_MAIN(tst_QState)
|
||||||
#include "tst_qstate.moc"
|
#include "tst_qstate.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user