ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kbprofile.h
Go to the documentation of this file.
1 #ifndef KBPROFILE_H
2 #define KBPROFILE_H
3 
4 #include <QList>
5 #include <QObject>
6 #include <QSettings>
7 #include <QString>
8 #include <QUuid>
9 #include "kbmode.h"
10 
11 class KbProfile : public QObject
12 {
13  Q_OBJECT
14 public:
15  // Default constructor
16  explicit KbProfile(Kb *parent, const KeyMap& keyMap, const KbProfile& other);
17  // Construct empty profile with GUID/modification
18  explicit KbProfile(Kb* parent, const KeyMap& keyMap, const QString& guid = "", const QString& modified = "");
19  // Load profile from settings
20  explicit KbProfile(Kb* parent, const KeyMap& keyMap, CkbSettings& settings, const QString& guid);
21 
22  // Save profile to settings
23  void save(CkbSettings& settings);
24  bool needsSave() const;
25  inline void setNeedsSave() { _needsSave = true; }
26 
27  // Profile properties
28  inline QString name() const { return _name; }
29  inline void name(const QString& newName) { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
30  inline UsbId& id() { return _id; }
31  inline void id(const UsbId& newId) { _needsSave = true; _id = newId; }
32 
33  // Creates a new ID for the profile and all of its modes
34  void newId();
35 
36  // Profile key map
37  inline const KeyMap& keyMap() const { return _keyMap; }
38  void keyMap(const KeyMap& newKeyMap);
39 
40  // Modes in this profile
41  typedef QList<KbMode*> ModeList;
42  inline const ModeList& modes() const { return _modes; }
43  inline void modes(const QList<KbMode*>& newModes) { setNeedsUpdate(); _modes = newModes; }
44  inline void append(KbMode* newMode) { setNeedsUpdate(); _modes.append(newMode); }
45  inline void insert(int index, KbMode* newMode) { setNeedsUpdate(); _modes.insert(index, newMode); }
46  inline void removeAll(KbMode* mode) { setNeedsUpdate(); _modes.removeAll(mode); }
47  inline void move(int from, int to) { setNeedsUpdate(); _modes.move(from, to); }
48 
49  inline int modeCount() const { return _modes.count(); }
50  inline int indexOf(KbMode* mode) const { return _modes.indexOf(mode); }
51  inline KbMode* find(const QUuid& id) { foreach(KbMode* mode, _modes) { if(mode->id().guid == id) return mode; } return 0; }
52 
53  // Currently-selected mode
54  inline KbMode* currentMode() const { return _currentMode; }
55  inline void currentMode(KbMode* newCurrentMode) { _needsSave = true; _currentMode = newCurrentMode; }
56 
57 private:
59  QString _name;
63  bool _needsSave;
64 
65  // Make note that all modes should be re-sent to the driver
66  inline void setNeedsUpdate() { setNeedsSave(); foreach(KbMode* mode, _modes){ mode->setNeedsUpdate(); } }
67 };
68 
69 #endif // KBPROFILE_H
KbMode * currentMode() const
Definition: kbprofile.h:54
KbMode * _currentMode
Definition: kbprofile.h:58
QString _name
Definition: kbprofile.h:59
const ModeList & modes() const
Definition: kbprofile.h:42
UsbId & id()
Definition: kbmode.h:52
QUuid guid
Definition: kbmode.h:12
void setNeedsUpdate()
Definition: kbmode.h:68
bool needsSave() const
Definition: kbprofile.cpp:68
KbProfile(Kb *parent, const KeyMap &keyMap, const KbProfile &other)
Definition: kbprofile.cpp:4
bool _needsSave
Definition: kbprofile.h:63
KeyMap _keyMap
Definition: kbprofile.h:61
KbMode * find(const QUuid &id)
Definition: kbprofile.h:51
Definition: kbmode.h:11
ModeList _modes
Definition: kbprofile.h:62
void name(const QString &newName)
Definition: kbprofile.h:29
void save(CkbSettings &settings)
Definition: kbprofile.cpp:48
UsbId _id
Definition: kbprofile.h:60
void modes(const QList< KbMode * > &newModes)
Definition: kbprofile.h:43
UsbId & id()
Definition: kbprofile.h:30
void append(KbMode *newMode)
Definition: kbprofile.h:44
Definition: kbmode.h:36
int modeCount() const
Definition: kbprofile.h:49
Definition: kb.h:11
void setNeedsUpdate()
Definition: kbprofile.h:66
QList< KbMode * > ModeList
Definition: kbprofile.h:41
const KeyMap & keyMap() const
Definition: kbprofile.h:37
Definition: keymap.h:49
void removeAll(KbMode *mode)
Definition: kbprofile.h:46
void move(int from, int to)
Definition: kbprofile.h:47
int indexOf(KbMode *mode) const
Definition: kbprofile.h:50
void setNeedsSave()
Definition: kbprofile.h:25
void id(const UsbId &newId)
Definition: kbprofile.h:31
QString name() const
Definition: kbprofile.h:28
void currentMode(KbMode *newCurrentMode)
Definition: kbprofile.h:55
void insert(int index, KbMode *newMode)
Definition: kbprofile.h:45
void newId()
Definition: kbprofile.cpp:78