src/settingseditor/keyboardshortcutseditor.cpp

Fri, 31 Jan 2020 00:25:35 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 31 Jan 2020 00:25:35 +0200
changeset 36
bbb901b97404
parent 16
aeb5f203b3eb
child 259
c27612f0eac0
permissions
-rw-r--r--

added render style storage

16
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QAction>
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "keyboardshortcutseditor.h"
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "uiutilities.h"
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 KeyboardShortcutsEditor::KeyboardShortcutsEditor(QObject* subject, QObject* parent) :
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 QAbstractTableModel{parent},
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 actions{uiutilities::collectActions(subject)}
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 int KeyboardShortcutsEditor::rowCount(const QModelIndex&) const
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 return this->actions.size();
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 int KeyboardShortcutsEditor::columnCount(const QModelIndex&) const
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 return 2;
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 QVariant KeyboardShortcutsEditor::data(
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 const QModelIndex& index,
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 int role) const
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 QAction* const action = this->actions[index.row()];
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 const Column column = static_cast<Column>(index.column());
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 switch(role)
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 case Qt::DisplayRole:
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 switch (column) {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 case TitleColumn:
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 return action->text();
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 case ShortcutColumn:
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 return action->shortcut().toString(QKeySequence::NativeText);
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 break;
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 return {};
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 QVariant KeyboardShortcutsEditor::headerData(
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 int section,
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 Qt::Orientation orientation,
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 int role) const
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 if (orientation == Qt::Horizontal and role == Qt::DisplayRole)
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 switch (static_cast<Column>(section))
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 {
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 case TitleColumn:
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 return tr("Action");
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 case ShortcutColumn:
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 return tr("Shortcut");
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 return {};
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 }
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58

mercurial