mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T218, find hotkeys by same machine
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/input/actionhotkey.h"
|
||||
#include <QStringBuilder>
|
||||
|
||||
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<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
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<CActionHotkey>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAction:
|
||||
@@ -80,6 +79,7 @@ namespace BlackMisc
|
||||
case IndexCombination:
|
||||
case IndexCombinationAsString:
|
||||
m_combination = variant.to<CHotkeyCombination>();
|
||||
break;
|
||||
case IndexObject:
|
||||
this->setObject(variant.value<CActionHotkey>());
|
||||
break;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -45,16 +45,17 @@ namespace BlackMisc
|
||||
CActionHotkeyList(const CSequence<CActionHotkey> &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
|
||||
|
||||
Reference in New Issue
Block a user