Ref T218, find hotkeys by same machine

This commit is contained in:
Klaus Basan
2018-01-04 19:10:32 +01:00
parent fa6f83d87b
commit 4bc9b92c69
4 changed files with 51 additions and 36 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#include "blackmisc/input/actionhotkey.h" #include "blackmisc/input/actionhotkey.h"
#include <QStringBuilder>
namespace BlackMisc namespace BlackMisc
{ {
@@ -23,12 +24,12 @@ namespace BlackMisc
QString CActionHotkey::convertToQString(bool /* i18n */) const QString CActionHotkey::convertToQString(bool /* i18n */) const
{ {
QString s; const QString s =
s += m_identifier.getMachineName(); m_identifier.getMachineName() %
s += " "; QStringLiteral(" ") %
s += m_combination.toQString(); m_combination.toQString() %
s += " "; QStringLiteral(" ") %
s += m_action; m_action;
return s; return s;
} }
@@ -37,6 +38,11 @@ namespace BlackMisc
m_combination = combination; m_combination = combination;
} }
bool CActionHotkey::isForSameMachine(const CActionHotkey &key) const
{
return this->getApplicableMachine().hasSameMachineId(key.getApplicableMachine());
}
void CActionHotkey::setObject(const CActionHotkey &obj) void CActionHotkey::setObject(const CActionHotkey &obj)
{ {
m_action = obj.m_action; m_action = obj.m_action;
@@ -46,30 +52,23 @@ namespace BlackMisc
CVariant CActionHotkey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const CVariant CActionHotkey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{ {
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexIdentifier: case IndexIdentifier: return CVariant::from(m_identifier);
return CVariant::from(m_identifier); case IndexIdentifierAsString: return CVariant::from(m_identifier.getMachineName());
case IndexIdentifierAsString: case IndexAction: return CVariant::from(m_action);
return CVariant::from(m_identifier.getMachineName()); case IndexActionAsString: return CVariant::from(m_action);
case IndexAction: case IndexCombination: return CVariant::from(m_combination);
return CVariant::from(m_action); case IndexCombinationAsString: return CVariant::from(QString(m_combination.toQString()));
case IndexActionAsString: default: return CValueObject::propertyByIndex(index);
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) void CActionHotkey::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{ {
if (index.isMyself()) { (*this) = variant.to<CActionHotkey>(); return; } if (index.isMyself()) { (*this) = variant.to<CActionHotkey>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexAction: case IndexAction:
@@ -80,6 +79,7 @@ namespace BlackMisc
case IndexCombination: case IndexCombination:
case IndexCombinationAsString: case IndexCombinationAsString:
m_combination = variant.to<CHotkeyCombination>(); m_combination = variant.to<CHotkeyCombination>();
break;
case IndexObject: case IndexObject:
this->setObject(variant.value<CActionHotkey>()); this->setObject(variant.value<CActionHotkey>());
break; break;

View File

@@ -34,7 +34,7 @@ namespace BlackMisc
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexIdentifier = BlackMisc::CPropertyIndex::GlobalIndexCSettingKeyboardHotkey, IndexIdentifier = CPropertyIndex::GlobalIndexCSettingKeyboardHotkey,
IndexIdentifierAsString, IndexIdentifierAsString,
IndexCombination, IndexCombination,
IndexCombinationAsString, IndexCombinationAsString,
@@ -59,7 +59,7 @@ namespace BlackMisc
void setCombination(const CHotkeyCombination &combination); void setCombination(const CHotkeyCombination &combination);
//! Action //! Action
QString getAction() const { return m_action; } const QString &getAction() const { return m_action; }
//! Set function //! Set function
void setAction(const QString &action) { m_action = action; } void setAction(const QString &action) { m_action = action; }
@@ -68,7 +68,10 @@ namespace BlackMisc
void setApplicableMachine(const CIdentifier &identifier) { m_identifier = identifier; } void setApplicableMachine(const CIdentifier &identifier) { m_identifier = identifier; }
//! Get applicable machine //! 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 //! Set object
void setObject(const CActionHotkey &obj); 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(); } bool isValid() const { return !m_identifier.getMachineName().isEmpty() && !m_combination.isEmpty() && !m_action.isEmpty(); }
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex //! \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 //! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; CVariant propertyByIndex(const CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::String::toQString //! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const; QString convertToQString(bool i18n = false) const;
@@ -97,8 +100,8 @@ namespace BlackMisc
BLACK_METAMEMBER(action) BLACK_METAMEMBER(action)
); );
}; };
} } // ns
} } // ns
Q_DECLARE_METATYPE(BlackMisc::Input::CActionHotkey) Q_DECLARE_METATYPE(BlackMisc::Input::CActionHotkey)

View File

@@ -36,7 +36,7 @@ namespace BlackMisc
CActionHotkeyList CActionHotkeyList::findSupersetsOf(const CActionHotkey &other) const CActionHotkeyList CActionHotkeyList::findSupersetsOf(const CActionHotkey &other) const
{ {
CActionHotkeyList supersets; CActionHotkeyList supersets;
for (const auto &actionHotkey : *this) for (const CActionHotkey &actionHotkey : *this)
{ {
if (other.getCombination().isSubsetOf(actionHotkey.getCombination())) if (other.getCombination().isSubsetOf(actionHotkey.getCombination()))
{ {
@@ -46,6 +46,17 @@ namespace BlackMisc
return supersets; 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 bool CActionHotkeyList::containsAction(const QString &action) const
{ {
return this->contains(&CActionHotkey::getAction, action); return this->contains(&CActionHotkey::getAction, action);

View File

@@ -45,16 +45,17 @@ namespace BlackMisc
CActionHotkeyList(const CSequence<CActionHotkey> &baseClass); CActionHotkeyList(const CSequence<CActionHotkey> &baseClass);
//! Returns true if this list has a action hotkey with a combination which is a subset of other //! Returns true if this list has a action hotkey with a combination which is a subset of other
//! Example: //! Example: List contains CTRL and other has combination CTRL-F
//! List contains CTRL and other has combination CTRL-F
CActionHotkeyList findSubsetsOf(const CActionHotkey &other) const; CActionHotkeyList findSubsetsOf(const CActionHotkey &other) const;
//! Returns true if this list has a hotkey with a combination for which other is a subset //! Returns true if this list has a hotkey with a combination for which other is a superset of other
//! Example: //! Example: List contains CTRL-F and other has combination CTRL
//! List contains CTRL-F and other has combination CTRL
CActionHotkeyList findSupersetsOf(const CActionHotkey &other) const; 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; bool containsAction(const QString &action) const;
}; };
} // ns } // ns