diff --git a/examples/gallerydata/contents/ui/gallery/FormLayoutGallery.qml b/examples/gallerydata/contents/ui/gallery/FormLayoutGallery.qml --- a/examples/gallerydata/contents/ui/gallery/FormLayoutGallery.qml +++ b/examples/gallerydata/contents/ui/gallery/FormLayoutGallery.qml @@ -76,7 +76,7 @@ } Button { text: item ? "Remove Field" : "Add Field" - property var item + property Item item onClicked: { if (item) { item.destroy(); diff --git a/src/formlayoutattached.h b/src/formlayoutattached.h --- a/src/formlayoutattached.h +++ b/src/formlayoutattached.h @@ -34,7 +34,7 @@ public: - explicit FormLayoutAttached(QObject *parent = 0); + explicit FormLayoutAttached(QObject *parent = nullptr); ~FormLayoutAttached(); void setLabel(const QString &text); @@ -53,8 +53,6 @@ Q_SIGNALS: void labelChanged(); void isSectionChanged(); - void mnemonicChanged(); - void decoratedLabelChanged(); private: QString m_label; diff --git a/src/formlayoutattached.cpp b/src/formlayoutattached.cpp --- a/src/formlayoutattached.cpp +++ b/src/formlayoutattached.cpp @@ -25,7 +25,6 @@ : QObject(parent) { m_buddyFor = qobject_cast(parent); - qApp->installEventFilter(this); } FormLayoutAttached::~FormLayoutAttached() diff --git a/src/mnemonicattached.h b/src/mnemonicattached.h --- a/src/mnemonicattached.h +++ b/src/mnemonicattached.h @@ -35,15 +35,16 @@ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(MnemonicAttached::ControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged) Q_PROPERTY(QKeySequence sequence READ sequence NOTIFY sequenceChanged) - Q_ENUMS(ControlType) + public: enum ControlType { ActionElement, /** pushbuttons, checkboxes etc */ DialogButton, /** buttons for dialogs */ MenuItem, /** Menu items */ FormLabel, /** Buddy label in a FormLayout*/ SecondaryControl /** Other controls that are considered not much important and low priority for shortcuts */ }; + Q_ENUM(ControlType) explicit MnemonicAttached(QObject *parent = 0); ~MnemonicAttached(); diff --git a/src/mnemonicattached.cpp b/src/mnemonicattached.cpp --- a/src/mnemonicattached.cpp +++ b/src/mnemonicattached.cpp @@ -61,17 +61,18 @@ MnemonicAttached::~MnemonicAttached() { - if (s_objectToSequence.contains(this)) { - s_sequenceToObject.remove(s_objectToSequence.value(this)); - s_objectToSequence.remove(this); + QHash::iterator i = s_objectToSequence.find(this); + if (i != s_objectToSequence.end()) { + s_sequenceToObject.remove(i.value()); + s_objectToSequence.erase(i); } } bool MnemonicAttached::eventFilter(QObject *watched, QEvent *e) { Q_UNUSED(watched) - if (m_richTextLabel.length() == 0) { + if (m_richTextLabel.isEmpty()) { return false; } @@ -163,9 +164,10 @@ void MnemonicAttached::updateSequence() { //forget about old association - if (s_objectToSequence.contains(this)) { - s_sequenceToObject.remove(s_objectToSequence.value(this)); - s_objectToSequence.remove(this); + QHash::iterator objIt = s_objectToSequence.find(this); + if (objIt != s_objectToSequence.end()) { + s_sequenceToObject.remove(objIt.value()); + s_objectToSequence.erase(objIt); } calculateWeights(); @@ -175,9 +177,12 @@ if (!m_enabled) { m_actualRichTextLabel = text; m_actualRichTextLabel.replace(QRegularExpression("\\&[^\\&]"), QString()); - m_mnemonicLabel = m_actualRichTextLabel; - emit mnemonicLabelChanged(); - emit richTextLabelChanged(); + //was the label already completely plain text? try to limit signal emission + if (m_mnemonicLabel != m_actualRichTextLabel) { + m_mnemonicLabel = m_actualRichTextLabel; + emit mnemonicLabelChanged(); + emit richTextLabelChanged(); + } return; } @@ -219,6 +224,10 @@ if (s_objectToSequence.contains(this)) { emit sequenceChanged(); + } else { + m_actualRichTextLabel = text; + m_actualRichTextLabel.replace(QRegularExpression("\\&[^\\&]"), QString()); + m_mnemonicLabel = m_actualRichTextLabel; } emit richTextLabelChanged(); @@ -238,7 +247,7 @@ QString MnemonicAttached::richTextLabel() const { - return m_actualRichTextLabel.length() > 0 ? m_actualRichTextLabel : m_label; + return !m_actualRichTextLabel.isEmpty() ? m_actualRichTextLabel : m_label; } QString MnemonicAttached::mnemonicLabel() const @@ -296,7 +305,7 @@ if (m_weights.isEmpty()) { m_weight = m_baseWeight; } else { - m_weight = m_baseWeight + m_weights.keys().last(); + m_weight = m_baseWeight + (m_weights.constEnd() - 1).key(); } emit controlTypeChanged(); }