MythTV  master
actionset.h
Go to the documentation of this file.
1 /* -*- myth -*- */
23 #ifndef ACTIONSET_H
24 #define ACTIONSET_H
25 
26 // Qt headers
27 #include <QStringList>
28 #include <QHash>
29 #include <QMap>
30 
36 class ActionSet
37 {
38  public:
40  ActionSet() = default;
41  ~ActionSet();
42 
43  // Commands
44  bool AddAction(const ActionID &id,
45  const QString &description,
46  const QString &keys);
47  bool Add(const ActionID &id, const QString &key);
48  bool Remove(const ActionID &id, const QString &key);
49  bool Replace(const ActionID &id,
50  const QString &newkey,
51  const QString &oldkey);
52 
53  // Sets
54  bool SetModifiedFlag(const ActionID &id, bool modified);
55 
56  // Gets
57  QStringList GetContextStrings(void) const;
58  QStringList GetActionStrings(const QString &context_name) const;
59  QString GetKeyString(const ActionID &id) const;
60  QStringList GetKeys(const ActionID &id) const;
61  QStringList GetContextKeys(const QString &context_name) const;
62  QStringList GetAllKeys(void) const;
63  QString GetDescription(const ActionID &id) const;
65  ActionList GetActions(const QString &key) const
66  { return m_keyToActionMap[key]; }
68  ActionList GetModified(void) const { return m_modified; }
70  bool HasModified(void) const { return !m_modified.isEmpty(); }
72  bool IsModified(const ActionID &id) const
73  { return m_modified.contains(id); }
74 
75  protected:
76  Action *GetAction(const ActionID &id);
77 
78  public:
80  static const QString kJumpContext;
82  static const QString kGlobalContext;
83 
84  private:
85  QMap<QString, ActionList> m_keyToActionMap;
86  using ContextMap = QHash<QString, ActionContext>;
89 };
90 
91 #endif /* ACTIONSET_H */
ActionSet::m_modified
ActionList m_modified
Definition: actionset.h:88
ActionSet::GetKeys
QStringList GetKeys(const ActionID &id) const
Get the keys bound to an action by its identifier.
Definition: actionset.cpp:240
ActionSet::~ActionSet
~ActionSet()
Definition: actionset.cpp:33
ActionSet::GetActionStrings
QStringList GetActionStrings(const QString &context_name) const
Returns a list of all action in the action set.
Definition: actionset.cpp:175
ActionSet
Maintains consistancy between actions and keybindings.
Definition: actionset.h:36
ActionList
QList< ActionID > ActionList
Definition: action.h:115
ActionSet::GetContextKeys
QStringList GetContextKeys(const QString &context_name) const
Definition: actionset.cpp:254
ActionSet::Replace
bool Replace(const ActionID &id, const QString &newkey, const QString &oldkey)
Replace a specific key in a specific action.
Definition: actionset.cpp:122
ActionSet::m_keyToActionMap
QMap< QString, ActionList > m_keyToActionMap
Definition: actionset.h:85
ActionSet::GetModified
ActionList GetModified(void) const
Returns the appropriate container of modified actions.
Definition: actionset.h:68
ActionSet::GetActions
ActionList GetActions(const QString &key) const
Returns the actions bound to the specified key.
Definition: actionset.h:65
Action
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:40
ActionSet::ContextMap
QHash< QString, ActionContext > ContextMap
Definition: actionset.h:86
ActionSet::Remove
bool Remove(const ActionID &id, const QString &key)
Remove a key from an action identifier.
Definition: actionset.cpp:91
ActionSet::ActionSet
ActionSet()=default
Create a new, empty set of action bindings.
ActionSet::GetContextStrings
QStringList GetContextStrings(void) const
Returns a list of all contexts in the action set.
Definition: actionset.cpp:162
ActionSet::GetAction
Action * GetAction(const ActionID &id)
Returns a pointer to an action by its identifier. (note: result not thread-safe)
Definition: actionset.cpp:301
ActionSet::HasModified
bool HasModified(void) const
Returns true iff changes have been made.
Definition: actionset.h:70
ActionSet::m_contexts
ContextMap m_contexts
Definition: actionset.h:87
ActionSet::AddAction
bool AddAction(const ActionID &id, const QString &description, const QString &keys)
Add an action.
Definition: actionset.cpp:200
ActionSet::kJumpContext
static const QString kJumpContext
The statically assigned context for jump point actions.
Definition: actionset.h:80
ActionSet::GetAllKeys
QStringList GetAllKeys(void) const
Get all keys (from every context) to which an action is bound.
Definition: actionset.cpp:269
ActionSet::IsModified
bool IsModified(const ActionID &id) const
Returns true iff the action is modified.
Definition: actionset.h:72
ActionSet::SetModifiedFlag
bool SetModifiedFlag(const ActionID &id, bool modified)
Mark an action as modified or unmodified by its identifier.
Definition: actionset.cpp:145
ActionSet::kGlobalContext
static const QString kGlobalContext
The name of global actions.
Definition: actionset.h:82
ActionID
A class that uniquely identifies an action.
Definition: action.h:84
ActionSet::GetDescription
QString GetDescription(const ActionID &id) const
Returns the description of an action by its identifier.
Definition: actionset.cpp:284
modified
static bool modified(uint64_t sig)
Definition: eitcache.cpp:91
ActionSet::Add
bool Add(const ActionID &id, const QString &key)
Add a binding.
Definition: actionset.cpp:59
ActionSet::GetKeyString
QString GetKeyString(const ActionID &id) const
Returns a string containing all the keys in bound to an action by its identifier.
Definition: actionset.cpp:224