diff --git a/src/mnemonicattached.h b/src/mnemonicattached.h --- a/src/mnemonicattached.h +++ b/src/mnemonicattached.h @@ -154,14 +154,14 @@ QString m_actualRichTextLabel; QString m_richTextLabel; QString m_mnemonicLabel; + QKeySequence m_sequence; bool m_enabled = true; QPointer m_window; //global mapping of mnemonics //TODO: map by QWindow static QHash s_sequenceToObject; - static QHash s_objectToSequence; }; QML_DECLARE_TYPEINFO(MnemonicAttached, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/mnemonicattached.cpp b/src/mnemonicattached.cpp --- a/src/mnemonicattached.cpp +++ b/src/mnemonicattached.cpp @@ -24,7 +24,6 @@ #include QHash MnemonicAttached::s_sequenceToObject = QHash(); -QHash MnemonicAttached::s_objectToSequence = QHash(); MnemonicAttached::MnemonicAttached(QObject *parent) : QObject(parent) @@ -61,11 +60,7 @@ MnemonicAttached::~MnemonicAttached() { - QHash::iterator i = s_objectToSequence.find(this); - if (i != s_objectToSequence.end()) { - s_sequenceToObject.remove(i.value()); - s_objectToSequence.erase(i); - } + s_sequenceToObject.remove(m_sequence); } bool MnemonicAttached::eventFilter(QObject *watched, QEvent *e) @@ -163,11 +158,9 @@ void MnemonicAttached::updateSequence() { - //forget about old association - QHash::iterator objIt = s_objectToSequence.find(this); - if (objIt != s_objectToSequence.end()) { - s_sequenceToObject.remove(objIt.value()); - s_objectToSequence.erase(objIt); + if (!m_sequence.isEmpty()) { + s_sequenceToObject.remove(m_sequence); + m_sequence = {}; } calculateWeights(); @@ -201,11 +194,11 @@ //the old shortcut is less valuable than the current: remove it if (otherMa) { s_sequenceToObject.remove(otherMa->sequence()); - s_objectToSequence.remove(otherMa); + otherMa->m_sequence = {}; } s_sequenceToObject[ks] = this; - s_objectToSequence[this] = ks; + m_sequence = ks; m_richTextLabel = text; m_richTextLabel.replace(QRegularExpression(QLatin1String("\\&([^\\&])")), QStringLiteral("\\1")); m_actualRichTextLabel = m_richTextLabel; @@ -222,7 +215,7 @@ } } while (i != m_weights.constBegin()); - if (s_objectToSequence.contains(this)) { + if (!m_sequence.isEmpty()) { emit sequenceChanged(); } else { m_actualRichTextLabel = text; @@ -317,7 +310,7 @@ QKeySequence MnemonicAttached::sequence() { - return s_objectToSequence.value(this); + return m_sequence; } MnemonicAttached *MnemonicAttached::qmlAttachedProperties(QObject *object)