summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-05-12 16:38:32 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-05-12 16:38:32 (GMT)
commit09d1e6ee7d93c9fb658b2be5fe49698bf3faa0d6 (patch)
tree2e68a3b01279934464acf98dd774b90659573dc6 /src/corelib/statemachine
parent3db6f6234eb36ec4b3d6e14dc48917762653cbd7 (diff)
downloadQt-09d1e6ee7d93c9fb658b2be5fe49698bf3faa0d6.zip
Qt-09d1e6ee7d93c9fb658b2be5fe49698bf3faa0d6.tar.gz
Qt-09d1e6ee7d93c9fb658b2be5fe49698bf3faa0d6.tar.bz2
correctly handle multiple signal transitions for same (object,signal)
The signal was not disconnected at the right time. We now store the number of active signal transitions for a particular (object,signal) and only disconnect when the count drops to zero.
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r--src/corelib/statemachine/qstate.cpp2
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp33
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h3
3 files changed, 23 insertions, 15 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 3a3bfc3..f1528b8 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -327,6 +327,8 @@ QAbstractTransition *QState::addTransition(QAbstractTransition *transition)
}
}
transition->setParent(this);
+ if (machine() != 0 && machine()->configuration().contains(this))
+ QStateMachinePrivate::get(machine())->registerTransitions(this);
return transition;
}
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 24af8e4..40a465a 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1311,8 +1311,10 @@ void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transitio
sender->metaObject()->className(), signal.constData());
return;
}
- QList<int> &connectedSignalIndexes = connections[sender];
- if (!connectedSignalIndexes.contains(signalIndex)) {
+ QVector<int> &connectedSignalIndexes = connections[sender];
+ if (connectedSignalIndexes.size() <= signalIndex)
+ connectedSignalIndexes.resize(signalIndex+1);
+ if (connectedSignalIndexes.at(signalIndex) == 0) {
#ifndef QT_STATEMACHINE_SOLUTION
if (!signalEventGenerator)
signalEventGenerator = new QSignalEventGenerator(q);
@@ -1329,8 +1331,8 @@ void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transitio
#endif
return;
}
- connectedSignalIndexes.append(signalIndex);
}
+ ++connectedSignalIndexes[signalIndex];
QSignalTransitionPrivate::get(transition)->signalIndex = signalIndex;
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q << ": added signal transition from" << transition->sourceState()
@@ -1345,17 +1347,20 @@ void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transit
if (signalIndex == -1)
return; // not registered
#ifndef QT_STATEMACHINE_SOLUTION
+ QSignalTransitionPrivate::get(transition)->signalIndex = -1;
const QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
- QList<int> &connectedSignalIndexes = connections[sender];
- Q_ASSERT(connectedSignalIndexes.contains(signalIndex));
- Q_ASSERT(signalEventGenerator != 0);
- bool ok = QMetaObject::disconnect(sender, signalIndex, signalEventGenerator,
- signalEventGenerator->metaObject()->methodOffset());
- if (ok) {
- connectedSignalIndexes.removeOne(signalIndex);
- if (connectedSignalIndexes.isEmpty())
+ QVector<int> &connectedSignalIndexes = connections[sender];
+ Q_ASSERT(connectedSignalIndexes.size() > signalIndex);
+ Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0);
+ if (--connectedSignalIndexes[signalIndex] == 0) {
+ Q_ASSERT(signalEventGenerator != 0);
+ QMetaObject::disconnect(sender, signalIndex, signalEventGenerator,
+ signalEventGenerator->metaObject()->methodOffset());
+ int sum = 0;
+ for (int i = 0; i < connectedSignalIndexes.size(); ++i)
+ sum += connectedSignalIndexes.at(i);
+ if (sum == 0)
connections.remove(sender);
- QSignalTransitionPrivate::get(transition)->signalIndex = -1;
}
#endif
}
@@ -1420,8 +1425,8 @@ void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transitio
void QStateMachinePrivate::handleTransitionSignal(const QObject *sender, int signalIndex,
void **argv)
{
- const QList<int> &connectedSignalIndexes = connections[sender];
- Q_ASSERT(connectedSignalIndexes.contains(signalIndex));
+ const QVector<int> &connectedSignalIndexes = connections[sender];
+ Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0);
const QMetaObject *meta = sender->metaObject();
QMetaMethod method = meta->method(signalIndex);
QList<QByteArray> parameterTypes = method.parameterTypes();
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 47b139c..4bf9ce2 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -61,6 +61,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
#include <QtCore/qset.h>
+#include <QtCore/qvector.h>
#include "qstate.h"
#include "qstate_p.h"
@@ -202,7 +203,7 @@ public:
#ifndef QT_STATEMACHINE_SOLUTION
QSignalEventGenerator *signalEventGenerator;
#endif
- QHash<const QObject*, QList<int> > connections;
+ QHash<const QObject*, QVector<int> > connections;
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
QHash<QObject*, QSet<QEvent::Type> > qobjectEvents;
#endif