diff --git a/src/blackmisc/input/actionhotkey.cpp b/src/blackmisc/input/actionhotkey.cpp index 285fa8467..97ed900ef 100644 --- a/src/blackmisc/input/actionhotkey.cpp +++ b/src/blackmisc/input/actionhotkey.cpp @@ -8,6 +8,7 @@ */ #include "blackmisc/input/actionhotkey.h" +#include namespace BlackMisc { @@ -23,12 +24,12 @@ namespace BlackMisc QString CActionHotkey::convertToQString(bool /* i18n */) const { - QString s; - s += m_identifier.getMachineName(); - s += " "; - s += m_combination.toQString(); - s += " "; - s += m_action; + const QString s = + m_identifier.getMachineName() % + QStringLiteral(" ") % + m_combination.toQString() % + QStringLiteral(" ") % + m_action; return s; } @@ -37,6 +38,11 @@ namespace BlackMisc m_combination = combination; } + bool CActionHotkey::isForSameMachine(const CActionHotkey &key) const + { + return this->getApplicableMachine().hasSameMachineId(key.getApplicableMachine()); + } + void CActionHotkey::setObject(const CActionHotkey &obj) { m_action = obj.m_action; @@ -46,30 +52,23 @@ namespace BlackMisc CVariant CActionHotkey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexIdentifier: - return CVariant::from(m_identifier); - case IndexIdentifierAsString: - return CVariant::from(m_identifier.getMachineName()); - case IndexAction: - return CVariant::from(m_action); - case IndexActionAsString: - return CVariant::from(m_action); - case IndexCombination: - return CVariant::from(m_combination); - case IndexCombinationAsString: - return CVariant::from(QString(m_combination.toQString())); - default: - return CValueObject::propertyByIndex(index); + case IndexIdentifier: return CVariant::from(m_identifier); + case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName()); + case IndexAction: return CVariant::from(m_action); + case IndexActionAsString: return CVariant::from(m_action); + case IndexCombination: return CVariant::from(m_combination); + case IndexCombinationAsString: return CVariant::from(QString(m_combination.toQString())); + default: return CValueObject::propertyByIndex(index); } } void CActionHotkey::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexAction: @@ -80,6 +79,7 @@ namespace BlackMisc case IndexCombination: case IndexCombinationAsString: m_combination = variant.to(); + break; case IndexObject: this->setObject(variant.value()); break; diff --git a/src/blackmisc/input/actionhotkey.h b/src/blackmisc/input/actionhotkey.h index 52375f40a..71d139b32 100644 --- a/src/blackmisc/input/actionhotkey.h +++ b/src/blackmisc/input/actionhotkey.h @@ -34,7 +34,7 @@ namespace BlackMisc //! Properties by index enum ColumnIndex { - IndexIdentifier = BlackMisc::CPropertyIndex::GlobalIndexCSettingKeyboardHotkey, + IndexIdentifier = CPropertyIndex::GlobalIndexCSettingKeyboardHotkey, IndexIdentifierAsString, IndexCombination, IndexCombinationAsString, @@ -59,7 +59,7 @@ namespace BlackMisc void setCombination(const CHotkeyCombination &combination); //! Action - QString getAction() const { return m_action; } + const QString &getAction() const { return m_action; } //! Set function void setAction(const QString &action) { m_action = action; } @@ -68,7 +68,10 @@ namespace BlackMisc void setApplicableMachine(const CIdentifier &identifier) { m_identifier = identifier; } //! Get applicable machine - CIdentifier getApplicableMachine() const { return m_identifier; } + const CIdentifier &getApplicableMachine() const { return m_identifier; } + + //! Key for the same machine? + bool isForSameMachine(const CActionHotkey &key) const; //! Set object void setObject(const CActionHotkey &obj); @@ -77,10 +80,10 @@ namespace BlackMisc bool isValid() const { return !m_identifier.getMachineName().isEmpty() && !m_combination.isEmpty() && !m_action.isEmpty(); } //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + CVariant propertyByIndex(const CPropertyIndex &index) const; //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; @@ -97,8 +100,8 @@ namespace BlackMisc BLACK_METAMEMBER(action) ); }; - } -} + } // ns +} // ns Q_DECLARE_METATYPE(BlackMisc::Input::CActionHotkey) diff --git a/src/blackmisc/input/actionhotkeylist.cpp b/src/blackmisc/input/actionhotkeylist.cpp index 167429dd9..559d44335 100644 --- a/src/blackmisc/input/actionhotkeylist.cpp +++ b/src/blackmisc/input/actionhotkeylist.cpp @@ -36,7 +36,7 @@ namespace BlackMisc CActionHotkeyList CActionHotkeyList::findSupersetsOf(const CActionHotkey &other) const { CActionHotkeyList supersets; - for (const auto &actionHotkey : *this) + for (const CActionHotkey &actionHotkey : *this) { if (other.getCombination().isSubsetOf(actionHotkey.getCombination())) { @@ -46,6 +46,17 @@ namespace BlackMisc return supersets; } + CActionHotkeyList CActionHotkeyList::findBySameMachine(const CActionHotkey &key) const + { + CActionHotkeyList sameMachineKeys; + for (const CActionHotkey &actionHotkey : *this) + { + if (!actionHotkey.isForSameMachine(key)) { continue; } + sameMachineKeys.push_back(actionHotkey); + } + return sameMachineKeys; + } + bool CActionHotkeyList::containsAction(const QString &action) const { return this->contains(&CActionHotkey::getAction, action); diff --git a/src/blackmisc/input/actionhotkeylist.h b/src/blackmisc/input/actionhotkeylist.h index 421b4b380..9b6d49b1d 100644 --- a/src/blackmisc/input/actionhotkeylist.h +++ b/src/blackmisc/input/actionhotkeylist.h @@ -45,16 +45,17 @@ namespace BlackMisc CActionHotkeyList(const CSequence &baseClass); //! Returns true if this list has a action hotkey with a combination which is a subset of other - //! Example: - //! List contains CTRL and other has combination CTRL-F + //! Example: List contains CTRL and other has combination CTRL-F CActionHotkeyList findSubsetsOf(const CActionHotkey &other) const; - //! Returns true if this list has a hotkey with a combination for which other is a subset - //! Example: - //! List contains CTRL-F and other has combination CTRL + //! Returns true if this list has a hotkey with a combination for which other is a superset of other + //! Example: List contains CTRL-F and other has combination CTRL CActionHotkeyList findSupersetsOf(const CActionHotkey &other) const; - //! Contains action + //! Find hotkeys for the same machine + CActionHotkeyList findBySameMachine(const CActionHotkey &key) const; + + //! Contains action? bool containsAction(const QString &action) const; }; } // ns