summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2017-06-12 16:19:08 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2017-08-14 09:08:05 +0000
commit8af8db3810ec2d8d2d923f39e23512d30ae234d9 (patch)
tree1d7e2fb3e27eecc3a8868b17494cc3a5c259e63d /src
parentcbcd1b0c432089777377fb0190a7d86195367bb6 (diff)
Fix emission of state changed signals
The state index is not the same as its changed signal index. The changed signal is not being generated for history states. The current fix is that we create a hash cache of state index into the signal index of its appropriate signal just after we set the table data for the state machine. Task-number: QTBUG-61243 Change-Id: I778adaf6c2d626be17c50b558f93ec0035ea3325 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/scxml/qscxmlstatemachine.cpp26
-rw-r--r--src/scxml/qscxmlstatemachine_p.h4
2 files changed, 29 insertions, 1 deletions
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp
index e57630f..9767a03 100644
--- a/src/scxml/qscxmlstatemachine.cpp
+++ b/src/scxml/qscxmlstatemachine.cpp
@@ -731,7 +731,9 @@ void QScxmlStateMachinePrivate::emitStateActive(int stateIndex, bool active)
{
Q_Q(QScxmlStateMachine);
void *args[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&active)) };
- QMetaObject::activate(q, m_metaObject, stateIndex, args);
+ const int signalIndex = m_stateIndexToSignalIndex.value(stateIndex, -1);
+ if (signalIndex >= 0)
+ QMetaObject::activate(q, m_metaObject, signalIndex, args);
}
void QScxmlStateMachinePrivate::emitInvokedServicesChanged()
@@ -755,6 +757,26 @@ void QScxmlStateMachinePrivate::attach(QScxmlStateMachineInfo *info)
info, &QScxmlStateMachineInfo::transitionsTriggered);
}
+void QScxmlStateMachinePrivate::updateMetaCache()
+{
+ m_stateIndexToSignalIndex.clear();
+
+ if (!m_tableData)
+ return;
+
+ if (!m_stateTable)
+ return;
+
+ int signalIndex = 0;
+ for (int i = 0; i < m_stateTable->stateCount; ++i) {
+ const auto &s = m_stateTable->state(i);
+ if (!s.isHistoryState() && s.type != StateTable::State::Invalid) {
+ m_stateIndexToSignalIndex.insert(i, signalIndex);
+ ++signalIndex;
+ }
+ }
+}
+
QStringList QScxmlStateMachinePrivate::stateNames(const std::vector<int> &stateIndexes) const
{
QStringList names;
@@ -1767,6 +1789,8 @@ void QScxmlStateMachine::setTableData(QScxmlTableData *tableData)
== QScxmlExecutableContent::StateTable::terminator);
}
+ d->updateMetaCache();
+
emit tableDataChanged(tableData);
}
diff --git a/src/scxml/qscxmlstatemachine_p.h b/src/scxml/qscxmlstatemachine_p.h
index bfa7bc1..388dd8d 100644
--- a/src/scxml/qscxmlstatemachine_p.h
+++ b/src/scxml/qscxmlstatemachine_p.h
@@ -283,6 +283,8 @@ public:
void attach(QScxmlStateMachineInfo *info);
const OrderedSet &configuration() const { return m_configuration; }
+ void updateMetaCache();
+
private:
QStringList stateNames(const std::vector<int> &stateIndexes) const;
std::vector<int> historyStates(int stateIdx) const;
@@ -379,6 +381,8 @@ private:
bool isPaused() const { return m_runningState == Paused; }
QScxmlInternal::StateMachineInfoProxy *m_infoSignalProxy;
+
+ QHash<int, int> m_stateIndexToSignalIndex;
};
QT_END_NAMESPACE