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 Class Reference

#include <src/ckb/kbprofile.h>

+ Inheritance diagram for KbProfile:
+ Collaboration diagram for KbProfile:

Public Types

typedef QList< KbMode * > ModeList
 

Public Member Functions

 KbProfile (Kb *parent, const KeyMap &keyMap, const KbProfile &other)
 
 KbProfile (Kb *parent, const KeyMap &keyMap, const QString &guid="", const QString &modified="")
 
 KbProfile (Kb *parent, const KeyMap &keyMap, CkbSettings &settings, const QString &guid)
 
void save (CkbSettings &settings)
 
bool needsSave () const
 
void setNeedsSave ()
 
QString name () const
 
void name (const QString &newName)
 
UsbIdid ()
 
void id (const UsbId &newId)
 
void newId ()
 
const KeyMapkeyMap () const
 
void keyMap (const KeyMap &newKeyMap)
 
const ModeListmodes () const
 
void modes (const QList< KbMode * > &newModes)
 
void append (KbMode *newMode)
 
void insert (int index, KbMode *newMode)
 
void removeAll (KbMode *mode)
 
void move (int from, int to)
 
int modeCount () const
 
int indexOf (KbMode *mode) const
 
KbModefind (const QUuid &id)
 
KbModecurrentMode () const
 
void currentMode (KbMode *newCurrentMode)
 

Private Member Functions

void setNeedsUpdate ()
 

Private Attributes

KbMode_currentMode
 
QString _name
 
UsbId _id
 
KeyMap _keyMap
 
ModeList _modes
 
bool _needsSave
 

Detailed Description

Definition at line 11 of file kbprofile.h.

Member Typedef Documentation

typedef QList<KbMode*> KbProfile::ModeList

Definition at line 41 of file kbprofile.h.

Constructor & Destructor Documentation

KbProfile::KbProfile ( Kb parent,
const KeyMap keyMap,
const KbProfile other 
)
explicit

Definition at line 4 of file kbprofile.cpp.

References _currentMode, _modes, and modes().

4  :
5  QObject(parent), _currentMode(0), _name(other._name), _id(other._id), _keyMap(keyMap), _needsSave(true)
6 {
7  foreach(KbMode* mode, other.modes()){
8  KbMode* newMode = new KbMode(parent, keyMap, *mode);
9  if(!_currentMode || mode == other._currentMode)
10  _currentMode = newMode;
11  _modes.append(newMode);
12  }
13 }
KbMode * _currentMode
Definition: kbprofile.h:58
QString _name
Definition: kbprofile.h:59
const ModeList & modes() const
Definition: kbprofile.h:42
bool _needsSave
Definition: kbprofile.h:63
KeyMap _keyMap
Definition: kbprofile.h:61
ModeList _modes
Definition: kbprofile.h:62
UsbId _id
Definition: kbprofile.h:60
Definition: kbmode.h:36

+ Here is the call graph for this function:

KbProfile::KbProfile ( Kb parent,
const KeyMap keyMap,
const QString &  guid = "",
const QString &  modified = "" 
)
explicit

Definition at line 15 of file kbprofile.cpp.

References _id, and UsbId::guid.

15  :
16  QObject(parent), _currentMode(0), _id(guid, modified.toUInt(0, 16)), _keyMap(keyMap), _needsSave(true)
17 {
18  if(_id.guid.isNull())
19  _id.guid = QUuid::createUuid();
20 }
KbMode * _currentMode
Definition: kbprofile.h:58
QUuid guid
Definition: kbmode.h:12
bool _needsSave
Definition: kbprofile.h:63
KeyMap _keyMap
Definition: kbprofile.h:61
UsbId _id
Definition: kbprofile.h:60
KbProfile::KbProfile ( Kb parent,
const KeyMap keyMap,
CkbSettings settings,
const QString &  guid 
)
explicit

Definition at line 22 of file kbprofile.cpp.

References _currentMode, _id, _keyMap, _modes, _name, CkbSettings::contains(), current, UsbId::guid, UsbId::hwModified, UsbId::hwModifiedString(), KbMode::id(), UsbId::modified, UsbId::modifiedString(), and CkbSettings::value().

22  :
23  QObject(parent), _currentMode(0), _id(guid, 0), _keyMap(keyMap), _needsSave(false)
24 {
25  // Load data from preferences
26  SGroup group(settings, guid);
27  _name = settings.value("Name").toString().trimmed();
28  if(_name == "")
29  _name = "Unnamed";
30  _id.modifiedString(settings.value("Modified").toString());
31  if(settings.contains("HwModified"))
32  _id.hwModifiedString(settings.value("HwModified").toString());
33  else
35  QUuid current = settings.value("CurrentMode").toString().trimmed();
36  // Load modes
37  uint count = settings.value("ModeCount").toUInt();
38  for(uint i = 0; i < count; i++){
39  SGroup group(settings, QString::number(i));
40  KbMode* mode = new KbMode(parent, _keyMap, settings);
41  _modes.append(mode);
42  // Set currentMode to the mode matching the current GUID, or the first mode in case it's not found
43  if(current == mode->id().guid || !_currentMode)
44  _currentMode = mode;
45  }
46 }
KbMode * _currentMode
Definition: kbprofile.h:58
QString _name
Definition: kbprofile.h:59
UsbId & id()
Definition: kbmode.h:52
QUuid guid
Definition: kbmode.h:12
rgb * current
Definition: main.c:46
QString modifiedString() const
Definition: kbmode.h:22
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
bool _needsSave
Definition: kbprofile.h:63
KeyMap _keyMap
Definition: kbprofile.h:61
bool contains(const QString &key) const
ModeList _modes
Definition: kbprofile.h:62
quint32 modified
Definition: kbmode.h:13
UsbId _id
Definition: kbprofile.h:60
Definition: kbmode.h:36
quint32 hwModified
Definition: kbmode.h:14
QString hwModifiedString() const
Definition: kbmode.h:24

+ Here is the call graph for this function:

Member Function Documentation

void KbProfile::append ( KbMode newMode)
inline

Definition at line 44 of file kbprofile.h.

References _modes, and setNeedsUpdate().

Referenced by Kb::hwSave(), KbWidget::on_modesList_itemClicked(), KbProfileDialog::profileList_reordered(), Kb::readNotify(), and Kb::setCurrentProfile().

44 { setNeedsUpdate(); _modes.append(newMode); }
ModeList _modes
Definition: kbprofile.h:62
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KbMode* KbProfile::currentMode ( ) const
inline

Definition at line 54 of file kbprofile.h.

References _currentMode.

Referenced by KeyAction::keyEvent(), KbBindWidget::on_copyButton_clicked(), KPerfWidget::on_copyButton_clicked(), MPerfWidget::on_copyButton_clicked(), Kb::setCurrentMode(), and Kb::setCurrentProfile().

54 { return _currentMode; }
KbMode * _currentMode
Definition: kbprofile.h:58

+ Here is the caller graph for this function:

void KbProfile::currentMode ( KbMode newCurrentMode)
inline

Definition at line 55 of file kbprofile.h.

References _currentMode, and _needsSave.

55 { _needsSave = true; _currentMode = newCurrentMode; }
KbMode * _currentMode
Definition: kbprofile.h:58
bool _needsSave
Definition: kbprofile.h:63
KbMode* KbProfile::find ( const QUuid &  id)
inline

Definition at line 51 of file kbprofile.h.

References _modes, UsbId::guid, id(), and KbMode::id().

Referenced by KbWidget::modesList_reordered(), and KbWidget::on_modesList_currentItemChanged().

51 { foreach(KbMode* mode, _modes) { if(mode->id().guid == id) return mode; } return 0; }
UsbId & id()
Definition: kbmode.h:52
QUuid guid
Definition: kbmode.h:12
ModeList _modes
Definition: kbprofile.h:62
UsbId & id()
Definition: kbprofile.h:30
Definition: kbmode.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfile::id ( const UsbId newId)
inline

Definition at line 31 of file kbprofile.h.

References _id, _needsSave, and newId().

31 { _needsSave = true; _id = newId; }
bool _needsSave
Definition: kbprofile.h:63
UsbId _id
Definition: kbprofile.h:60
void newId()
Definition: kbprofile.cpp:78

+ Here is the call graph for this function:

int KbProfile::indexOf ( KbMode mode) const
inline

Definition at line 50 of file kbprofile.h.

References _modes.

Referenced by Kb::frameUpdate(), KeyAction::keyEvent(), KbWidget::modeChanged(), KbWidget::on_modesList_customContextMenuRequested(), and Kb::readNotify().

50 { return _modes.indexOf(mode); }
ModeList _modes
Definition: kbprofile.h:62

+ Here is the caller graph for this function:

void KbProfile::insert ( int  index,
KbMode newMode 
)
inline

Definition at line 45 of file kbprofile.h.

References _modes, and setNeedsUpdate().

Referenced by KbWidget::on_modesList_customContextMenuRequested().

45 { setNeedsUpdate(); _modes.insert(index, newMode); }
ModeList _modes
Definition: kbprofile.h:62
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const KeyMap& KbProfile::keyMap ( ) const
inline

Definition at line 37 of file kbprofile.h.

References _keyMap.

Referenced by KPerfWidget::setPerf(), and Kb::updateLayout().

37 { return _keyMap; }
KeyMap _keyMap
Definition: kbprofile.h:61

+ Here is the caller graph for this function:

void KbProfile::keyMap ( const KeyMap newKeyMap)

Definition at line 85 of file kbprofile.cpp.

References _keyMap, _modes, KbMode::keyMap(), and setNeedsUpdate().

85  {
86  _keyMap = newKeyMap;
87  foreach(KbMode* mode, _modes)
88  mode->keyMap(newKeyMap);
90 }
KeyMap _keyMap
Definition: kbprofile.h:61
ModeList _modes
Definition: kbprofile.h:62
void keyMap(const KeyMap &keyMap)
Definition: kbmode.cpp:60
Definition: kbmode.h:36
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

int KbProfile::modeCount ( ) const
inline

Definition at line 49 of file kbprofile.h.

References _modes.

Referenced by Kb::hwSave(), KeyAction::keyEvent(), KbWidget::on_modesList_customContextMenuRequested(), Kb::readNotify(), save(), and Kb::setCurrentProfile().

49 { return _modes.count(); }
ModeList _modes
Definition: kbprofile.h:62

+ Here is the caller graph for this function:

void KbProfile::modes ( const QList< KbMode * > &  newModes)
inline

Definition at line 43 of file kbprofile.h.

References _modes, and setNeedsUpdate().

43 { setNeedsUpdate(); _modes = newModes; }
ModeList _modes
Definition: kbprofile.h:62
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

void KbProfile::move ( int  from,
int  to 
)
inline

Definition at line 47 of file kbprofile.h.

References _modes, and setNeedsUpdate().

Referenced by Kb::readNotify().

47 { setNeedsUpdate(); _modes.move(from, to); }
ModeList _modes
Definition: kbprofile.h:62
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbProfile::name ( ) const
inline

Definition at line 28 of file kbprofile.h.

References _name.

Referenced by KbProfileDialog::on_profileList_itemChanged(), Kb::readNotify(), KbProfileDialog::repopulate(), save(), KbWidget::updateProfileList(), and Kb::writeProfileHeader().

28 { return _name; }
QString _name
Definition: kbprofile.h:59

+ Here is the caller graph for this function:

void KbProfile::name ( const QString &  newName)
inline

Definition at line 29 of file kbprofile.h.

References _name, and _needsSave.

29 { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
QString _name
Definition: kbprofile.h:59
bool _needsSave
Definition: kbprofile.h:63
bool KbProfile::needsSave ( ) const

Definition at line 68 of file kbprofile.cpp.

References _modes, _needsSave, and KbMode::needsSave().

Referenced by Kb::needsSave().

68  {
69  if(_needsSave)
70  return true;
71  foreach(KbMode* mode, _modes){
72  if(mode->needsSave())
73  return true;
74  }
75  return false;
76 }
bool _needsSave
Definition: kbprofile.h:63
ModeList _modes
Definition: kbprofile.h:62
bool needsSave() const
Definition: kbmode.cpp:78
Definition: kbmode.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfile::newId ( )

Definition at line 78 of file kbprofile.cpp.

References _id, _modes, _needsSave, and KbMode::newId().

Referenced by id(), and KbProfileDialog::on_profileList_customContextMenuRequested().

78  {
79  _needsSave = true;
80  _id = UsbId();
81  foreach(KbMode* mode, _modes)
82  mode->newId();
83 }
bool _needsSave
Definition: kbprofile.h:63
Definition: kbmode.h:11
ModeList _modes
Definition: kbprofile.h:62
UsbId _id
Definition: kbprofile.h:60
Definition: kbmode.h:36
void newId()
Definition: kbmode.cpp:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfile::removeAll ( KbMode mode)
inline

Definition at line 46 of file kbprofile.h.

References _modes, and setNeedsUpdate().

Referenced by KbWidget::on_modesList_customContextMenuRequested(), and KbProfileDialog::on_profileList_customContextMenuRequested().

46 { setNeedsUpdate(); _modes.removeAll(mode); }
ModeList _modes
Definition: kbprofile.h:62
void setNeedsUpdate()
Definition: kbprofile.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfile::save ( CkbSettings settings)

Definition at line 48 of file kbprofile.cpp.

References _currentMode, _id, _modes, _needsSave, UsbId::guidString(), UsbId::hwModifiedString(), KbMode::id(), modeCount(), UsbId::modifiedString(), name(), UsbId::newModified(), KbMode::save(), and CkbSettings::setValue().

Referenced by Kb::save().

48  {
49  _needsSave = false;
50  _id.newModified();
51  // Save data to preferences
52  SGroup group(settings, id().guidString());
53  settings.setValue("Name", name());
54  settings.setValue("Modified", _id.modifiedString());
55  settings.setValue("HwModified", _id.hwModifiedString());
56  if(_currentMode)
57  settings.setValue("CurrentMode", _currentMode->id().guidString());
58  // Save modes
59  uint count = modeCount();
60  settings.setValue("ModeCount", count);
61  for(uint i = 0; i < count; i++){
62  SGroup group(settings, QString::number(i));
63  KbMode* mode = _modes.at(i);
64  mode->save(settings);
65  }
66 }
KbMode * _currentMode
Definition: kbprofile.h:58
void setValue(const QString &key, const QVariant &value)
UsbId & id()
Definition: kbmode.h:52
QString modifiedString() const
Definition: kbmode.h:22
bool _needsSave
Definition: kbprofile.h:63
ModeList _modes
Definition: kbprofile.h:62
QString guidString() const
Definition: kbmode.h:20
UsbId _id
Definition: kbprofile.h:60
Definition: kbmode.h:36
int modeCount() const
Definition: kbprofile.h:49
void newModified()
Definition: kbmode.h:29
QString name() const
Definition: kbprofile.h:28
void save(CkbSettings &settings)
Definition: kbmode.cpp:66
QString hwModifiedString() const
Definition: kbmode.h:24

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfile::setNeedsSave ( )
inline

Definition at line 25 of file kbprofile.h.

References _needsSave.

Referenced by Kb::hwSave(), Kb::readNotify(), and setNeedsUpdate().

25 { _needsSave = true; }
bool _needsSave
Definition: kbprofile.h:63

+ Here is the caller graph for this function:

void KbProfile::setNeedsUpdate ( )
inlineprivate

Definition at line 66 of file kbprofile.h.

References _modes, setNeedsSave(), and KbMode::setNeedsUpdate().

Referenced by append(), insert(), keyMap(), modes(), move(), and removeAll().

66 { setNeedsSave(); foreach(KbMode* mode, _modes){ mode->setNeedsUpdate(); } }
void setNeedsUpdate()
Definition: kbmode.h:68
ModeList _modes
Definition: kbprofile.h:62
Definition: kbmode.h:36
void setNeedsSave()
Definition: kbprofile.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

KbMode* KbProfile::_currentMode
private

Definition at line 58 of file kbprofile.h.

Referenced by currentMode(), KbProfile(), and save().

UsbId KbProfile::_id
private

Definition at line 60 of file kbprofile.h.

Referenced by id(), KbProfile(), newId(), and save().

KeyMap KbProfile::_keyMap
private

Definition at line 61 of file kbprofile.h.

Referenced by KbProfile(), and keyMap().

ModeList KbProfile::_modes
private
QString KbProfile::_name
private

Definition at line 59 of file kbprofile.h.

Referenced by KbProfile(), and name().

bool KbProfile::_needsSave
private

Definition at line 63 of file kbprofile.h.

Referenced by currentMode(), id(), name(), needsSave(), newId(), save(), and setNeedsSave().


The documentation for this class was generated from the following files: