MythTV  master
action.h
Go to the documentation of this file.
1 /* -*- myth -*- */
23 #ifndef ACTION_H
24 #define ACTION_H
25 
26 #include <utility>
27 
28 // Qt headers
29 #include <QHash>
30 #include <QStringList>
31 
40 class Action
41 {
42  public:
44  explicit Action(QString description) : m_description(std::move(description)) {}
45  Action(QString description, const QString &keys);
46 
47  // Commands
48  bool AddKey(const QString &key);
49  bool ReplaceKey(const QString &newkey, const QString &oldkey);
52  bool RemoveKey(const QString &key)
53  {
54  return m_keys.removeAll(key) != 0;
55  }
56 
57  // Gets
59  QString GetDescription(void) const { return m_description; }
62  QStringList GetKeys(void) const { return m_keys; }
64  QString GetKeyString(void) const { return m_keys.join(","); }
66  bool IsEmpty(void) const { return m_keys.empty(); }
67  bool HasKey(const QString &key) const;
68 
69  public:
71  static const unsigned int kMaximumNumberOfBindings = 4;
72 
73  private:
74  QString m_description;
75  QStringList m_keys;
76 };
77 using Context = QHash<QString, Action*>;
78 
84 class ActionID
85 {
86  public:
88  ActionID(void);
89 
94  ActionID(QString context, QString action)
95  : m_context(std::move(context)), m_action(std::move(action)) {}
96  ActionID(const ActionID&) = default;
97  ActionID& operator=(const ActionID&) = default;
98 
100  QString GetContext(void) const { return m_context; }
101 
103  QString GetAction(void) const { return m_action; }
104 
105  bool operator==(const ActionID &other) const
106  {
107  return ((m_action == other.m_action) &&
108  (m_context == other.m_context));
109  }
110 
111  private:
112  QString m_context;
113  QString m_action;
114 };
115 using ActionList = QList<ActionID>;
116 
117 #endif /* ACTION_H */
Action::GetKeys
QStringList GetKeys(void) const
Returns the key sequence(s) that trigger this action.
Definition: action.h:62
Action::Action
Action(QString description)
Create a new empty action.
Definition: action.h:44
ActionList
QList< ActionID > ActionList
Definition: action.h:115
ActionID::ActionID
ActionID(QString context, QString action)
Create a new action identifier.
Definition: action.h:94
Context
QHash< QString, Action * > Context
Definition: action.h:77
ActionID::ActionID
ActionID(void)
Create an empty action.
Action
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:41
ActionID::GetAction
QString GetAction(void) const
Returns the action name.
Definition: action.h:103
ActionID::m_action
QString m_action
Definition: action.h:113
Action::kMaximumNumberOfBindings
static const unsigned int kMaximumNumberOfBindings
The maximum number of keys that can be bound to an action.
Definition: action.h:71
ActionID::operator==
bool operator==(const ActionID &other) const
Definition: action.h:105
Action::m_keys
QStringList m_keys
The keys bound to the action.
Definition: action.h:75
Action::RemoveKey
bool RemoveKey(const QString &key)
Remove a key from this action.
Definition: action.h:52
Action::GetKeyString
QString GetKeyString(void) const
Returns comma delimited string of key bindings.
Definition: action.h:64
Action::HasKey
bool HasKey(const QString &key) const
Determine if the action already has a key.
Definition: action.cpp:52
Action::AddKey
bool AddKey(const QString &key)
Add a key sequence to this action.
Definition: action.cpp:68
ActionID::m_context
QString m_context
Definition: action.h:112
Action::GetDescription
QString GetDescription(void) const
Returns the action description. (note: not threadsafe)
Definition: action.h:59
Action::IsEmpty
bool IsEmpty(void) const
Returns true iff the action has no keys.
Definition: action.h:66
Action::ReplaceKey
bool ReplaceKey(const QString &newkey, const QString &oldkey)
Replace a key.
Definition: action.cpp:85
Action::m_description
QString m_description
The actions description.
Definition: action.h:74
build_compdb.action
action
Definition: build_compdb.py:9
ActionID::ActionID
ActionID(const ActionID &)=default
ActionID
A class that uniquely identifies an action.
Definition: action.h:85
ActionID::operator=
ActionID & operator=(const ActionID &)=default
ActionID::GetContext
QString GetContext(void) const
Returns the context name.
Definition: action.h:100