swift
actionhotkey.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QStringBuilder>
7 
8 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::input, CActionHotkey)
9 
10 namespace swift::misc::input
11 {
12  CActionHotkey::CActionHotkey(const QString &action) : m_action(action) {}
13 
14  CActionHotkey::CActionHotkey(const CIdentifier &identifier, const CHotkeyCombination &combination,
15  const QString &action)
16  : m_identifier(identifier), m_combination(combination), m_action(action)
17  {}
18 
19  QString CActionHotkey::convertToQString(bool /* i18n */) const
20  {
21  const QString s = m_identifier.getMachineName() % u' ' % m_combination.asStringWithDeviceNames() %
22  // m_combination.toQString() %
23  u' ' % m_action;
24  return s;
25  }
26 
27  void CActionHotkey::setCombination(const CHotkeyCombination &combination) { m_combination = combination; }
28 
30  {
32  }
33 
35  {
37  }
38 
40  {
41  return this->isForSameMachineId(key) || this->isForSameMachineName(key);
42  }
43 
45 
47  {
48  m_action = obj.m_action;
49  m_combination = obj.m_combination;
50  }
51 
53  {
54  if (index.isMyself()) { return QVariant::fromValue(*this); }
55  const ColumnIndex i = index.frontCasted<ColumnIndex>();
56  switch (i)
57  {
58  case IndexIdentifier: return QVariant::fromValue(m_identifier);
59  case IndexIdentifierAsString: return QVariant::fromValue(m_identifier.getMachineName());
60  case IndexAction: return QVariant::fromValue(m_action);
61  case IndexActionAsString: return QVariant::fromValue(m_action);
62  case IndexCombination: return QVariant::fromValue(m_combination);
63  case IndexCombinationAsString: return QVariant::fromValue(QString(m_combination.toQString()));
64  default: return CValueObject::propertyByIndex(index);
65  }
66  }
67 
68  void CActionHotkey::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
69  {
70  if (index.isMyself())
71  {
72  (*this) = variant.value<CActionHotkey>();
73  return;
74  }
75  const ColumnIndex i = index.frontCasted<ColumnIndex>();
76  switch (i)
77  {
78  case IndexAction:
79  {
80  m_action = variant.value<QString>();
81  break;
82  }
83  case IndexCombination:
84  case IndexCombinationAsString: m_combination = variant.value<CHotkeyCombination>(); break;
85  case IndexObject: this->setObject(variant.value<CActionHotkey>()); break;
86  default: CValueObject::setPropertyByIndex(index, variant); break;
87  }
88  }
89 } // namespace swift::misc::input
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
bool hasSameMachineId(const CIdentifier &other) const
Check if other identifier is from the same machine id.
Definition: identifier.cpp:163
const QString & getMachineName() const
Machine name.
Definition: identifier.h:103
bool hasSameMachineName(const CIdentifier &other) const
Check if the other identifier has the same machine name.
Definition: identifier.cpp:158
void updateToCurrentMachine()
Update to current machine.
Definition: identifier.cpp:193
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Value object encapsulating a action hotkey.
Definition: actionhotkey.h:25
void setCombination(const CHotkeyCombination &combination)
Set hotkey combination.
CActionHotkey()=default
Default constructor.
const CIdentifier & getApplicableMachine() const
Get applicable machine.
Definition: actionhotkey.h:67
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isForSameMachineName(const CActionHotkey &key) const
Key for the same machine name.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
ColumnIndex
Properties by index.
Definition: actionhotkey.h:29
void setObject(const CActionHotkey &obj)
Set object.
void updateToCurrentMachine()
Local machine.
bool isForSameMachineId(const CActionHotkey &key) const
Key for the same machine id?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool isForSameMachine(const CActionHotkey &key) const
Key for the same machine (same name or id)?
Value object representing hotkey sequence.
QString asStringWithDeviceNames() const
Returns the button name with the device name prefix.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67