summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-22 12:44:55 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-22 12:50:11 (GMT)
commitdb92a780ceb130b6fa91ad866e521237c4b255b8 (patch)
tree01d7e77c82f652799cdfac86aadc6d8cf3e317b4
parent24146ce4ad076fb6337b591d24e5a8c6a290fe41 (diff)
downloadQt-db92a780ceb130b6fa91ad866e521237c4b255b8.zip
Qt-db92a780ceb130b6fa91ad866e521237c4b255b8.tar.gz
Qt-db92a780ceb130b6fa91ad866e521237c4b255b8.tar.bz2
perform normalization of signatures for signal transitions
Make state->addTransition(foo, SIGNAL( bar( ) ), ...) work.
-rw-r--r--src/corelib/statemachine/qstate.cpp11
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp12
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp25
3 files changed, 40 insertions, 8 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index c42c9c9..fd7ddef 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -333,10 +333,13 @@ QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
return 0;
}
int offset = (*signal == '0'+QSIGNAL_CODE) ? 1 : 0;
- if (sender->metaObject()->indexOfSignal(signal+offset) == -1) {
- qWarning("QState::addTransition: no such signal %s::%s",
- sender->metaObject()->className(), signal+offset);
- return 0;
+ const QMetaObject *meta = sender->metaObject();
+ if (meta->indexOfSignal(signal+offset) == -1) {
+ if (meta->indexOfSignal(QMetaObject::normalizedSignature(signal+offset)) == -1) {
+ qWarning("QState::addTransition: no such signal %s::%s",
+ meta->className(), signal+offset);
+ return 0;
+ }
}
QSignalTransition *trans = new QSignalTransition(sender, signal, QList<QAbstractState*>() << target);
addTransition(trans);
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 758bdbe..682dd97 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1316,11 +1316,15 @@ void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transitio
QByteArray signal = QSignalTransitionPrivate::get(transition)->signal;
if (signal.startsWith('0'+QSIGNAL_CODE))
signal.remove(0, 1);
- int signalIndex = sender->metaObject()->indexOfSignal(signal);
+ const QMetaObject *meta = sender->metaObject();
+ int signalIndex = meta->indexOfSignal(signal);
if (signalIndex == -1) {
- qWarning("QSignalTransition: no such signal: %s::%s",
- sender->metaObject()->className(), signal.constData());
- return;
+ signalIndex = meta->indexOfSignal(QMetaObject::normalizedSignature(signal));
+ if (signalIndex == -1) {
+ qWarning("QSignalTransition: no such signal: %s::%s",
+ meta->className(), signal.constData());
+ return;
+ }
}
QVector<int> &connectedSignalIndexes = connections[sender];
if (connectedSignalIndexes.size() <= signalIndex)
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 1cc2a8e..553833c 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -1981,6 +1981,31 @@ void tst_QStateMachine::signalTransitions()
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s3));
}
+ // signature normalization
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL( signalWithNoArg( ) ), s1);
+ QVERIFY(t0 != 0);
+ QCOMPARE(t0->signal(), QByteArray(SIGNAL( signalWithNoArg( ) )));
+
+ QSignalTransition *t1 = s0->addTransition(&emitter, SIGNAL( signalWithStringArg( const QString & ) ), s1);
+ QVERIFY(t1 != 0);
+ QCOMPARE(t1->signal(), QByteArray(SIGNAL( signalWithStringArg( const QString & ) )));
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
}
void tst_QStateMachine::eventTransitions()