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, Context>;
89 };
90 
91 #endif /* ACTIONSET_H */
static const QString kJumpContext
The statically assigned context for jump point actions.
Definition: actionset.h:80
QStringList GetKeys(const ActionID &id) const
Get the keys bound to an action by its identifier.
Definition: actionset.cpp:238
bool Replace(const ActionID &id, const QString &newkey, const QString &oldkey)
Replace a specific key in a specific action.
Definition: actionset.cpp:120
ContextMap m_contexts
Definition: actionset.h:87
Maintains consistancy between actions and keybindings.
Definition: actionset.h:36
A class that uniquely identifies an action.
Definition: action.h:84
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:40
QStringList GetActionStrings(const QString &context_name) const
Returns a list of all action in the action set.
Definition: actionset.cpp:173
ActionList m_modified
Definition: actionset.h:88
bool Add(const ActionID &id, const QString &key)
Add a binding.
Definition: actionset.cpp:57
Action * GetAction(const ActionID &id)
Returns a pointer to an action by its identifier.
Definition: actionset.cpp:299
QStringList GetContextStrings(void) const
Returns a list of all contexts in the action set.
Definition: actionset.cpp:160
QStringList GetContextKeys(const QString &context_name) const
Definition: actionset.cpp:252
bool IsModified(const ActionID &id) const
Returns true iff the action is modified.
Definition: actionset.h:72
QString GetKeyString(const ActionID &id) const
Returns a string containing all the keys in bound to an action by its identifier.
Definition: actionset.cpp:222
QMap< QString, ActionList > m_keyToActionMap
Definition: actionset.h:85
ActionSet()=default
Create a new, empty set of action bindings.
static const QString kGlobalContext
The name of global actions.
Definition: actionset.h:82
QString GetDescription(const ActionID &id) const
Returns the description of an action by its identifier.
Definition: actionset.cpp:282
static bool modified(uint64_t sig)
Definition: eitcache.cpp:91
QList< ActionID > ActionList
Definition: action.h:115
QStringList GetAllKeys(void) const
Get all keys (from every context) to which an action is bound.
Definition: actionset.cpp:267
ActionList GetModified(void) const
Returns the appropriate container of modified actions.
Definition: actionset.h:68
bool Remove(const ActionID &id, const QString &key)
Remove a key from an action identifier.
Definition: actionset.cpp:89
ActionList GetActions(const QString &key) const
Returns the actions bound to the specified key.
Definition: actionset.h:65
QHash< QString, Context > ContextMap
Definition: actionset.h:86
bool AddAction(const ActionID &id, const QString &description, const QString &keys)
Add an action.
Definition: actionset.cpp:198
bool SetModifiedFlag(const ActionID &id, bool modified)
Mark an action as modified or unmodified by its identifier.
Definition: actionset.cpp:143
bool HasModified(void) const
Returns true iff changes have been made.
Definition: actionset.h:70