src/settingseditor/keyboardshortcutseditor.cpp

Tue, 28 Jun 2022 19:49:45 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:49:45 +0300
changeset 301
8ccd6fdb30dc
parent 264
76a025db4948
permissions
-rw-r--r--

Move earcut.h outside src/ directory

16
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QAction>
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
2 #include "src/uiutilities.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
3 #include "src/settingseditor/keyboardshortcutseditor.h"
16
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 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 16
diff changeset
13 return static_cast<int>(this->actions.size());
16
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 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 16
diff changeset
25 QAction* const action = this->actions[static_cast<std::size_t>(index.row())];
16
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