LibrePCB Developers Documentation
keyboardshortcutsmodel.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_KEYBOARDSHORTCUTSMODEL_H
21#define LIBREPCB_EDITOR_KEYBOARDSHORTCUTSMODEL_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32namespace editor {
33
34class EditorCommand;
35class EditorCommandCategory;
36
37/*******************************************************************************
38 * Class KeyboardShortcutsModel
39 ******************************************************************************/
40
44class KeyboardShortcutsModel final : public QAbstractItemModel {
45 struct Category {
47 QList<const EditorCommand*> commands;
48 };
49
50public:
51 // Constructors / Destructor
54 explicit KeyboardShortcutsModel(QObject* parent = nullptr) noexcept;
55 ~KeyboardShortcutsModel() noexcept;
56
57 // General Methods
58 const QMap<QString, QList<QKeySequence>>& getOverrides() const noexcept {
59 return mOverrides;
60 }
61 void setOverrides(
62 const QMap<QString, QList<QKeySequence>>& overrides) noexcept;
63
64 // Inherited Methods
65 int columnCount(
66 const QModelIndex& parent = QModelIndex()) const noexcept override;
67 int rowCount(
68 const QModelIndex& parent = QModelIndex()) const noexcept override;
69 QModelIndex index(
70 int row, int column,
71 const QModelIndex& parent = QModelIndex()) const noexcept override;
72 QModelIndex parent(const QModelIndex& index) const noexcept override;
73 Qt::ItemFlags flags(const QModelIndex& index) const noexcept override;
74 QVariant data(const QModelIndex& index,
75 int role = Qt::DisplayRole) const noexcept override;
76 bool setData(const QModelIndex& index, const QVariant& value,
77 int role = Qt::EditRole) noexcept override;
78
79 // Operator Overloadings
80 KeyboardShortcutsModel& operator=(const KeyboardShortcutsModel& rhs) = delete;
81
82private: // Methods
83 Category* categoryFromIndex(const QModelIndex& index) const noexcept;
85 const QModelIndex& index) const noexcept;
86 static QString format(const QList<QKeySequence>& sequences,
87 bool showNone) noexcept;
88
89private: // Data
91 QMap<QString, QList<QKeySequence>> mOverrides;
92};
93
94} // namespace editor
95} // namespace librepcb
96
97/*******************************************************************************
98 * End of File
99 ******************************************************************************/
100
101#endif
Category for librepcb::editor::EditorCommand.
Definition: editorcommandcategory.h:42
Command for editors, e.g. to be added to a QMenu.
Definition: editorcommand.h:42
A QAbstractItemModel to represent keyboard shortcut workspace settings.
Definition: keyboardshortcutsmodel.h:44
static QString format(const QList< QKeySequence > &sequences, bool showNone) noexcept
Definition: keyboardshortcutsmodel.cpp:249
Qt::ItemFlags flags(const QModelIndex &index) const noexcept override
Definition: keyboardshortcutsmodel.cpp:117
QMap< QString, QList< QKeySequence > > mOverrides
Definition: keyboardshortcutsmodel.h:91
QModelIndex parent(const QModelIndex &index) const noexcept override
Definition: keyboardshortcutsmodel.cpp:105
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) noexcept override
Definition: keyboardshortcutsmodel.cpp:207
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const noexcept override
Definition: keyboardshortcutsmodel.cpp:94
Category * categoryFromIndex(const QModelIndex &index) const noexcept
Definition: keyboardshortcutsmodel.cpp:228
int columnCount(const QModelIndex &parent=QModelIndex()) const noexcept override
Definition: keyboardshortcutsmodel.cpp:78
const EditorCommand * commandFromIndex(const QModelIndex &index) const noexcept
Definition: keyboardshortcutsmodel.cpp:238
const QMap< QString, QList< QKeySequence > > & getOverrides() const noexcept
Definition: keyboardshortcutsmodel.h:58
int rowCount(const QModelIndex &parent=QModelIndex()) const noexcept override
Definition: keyboardshortcutsmodel.cpp:84
QList< Category * > mCategories
Definition: keyboardshortcutsmodel.h:90
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const noexcept override
Definition: keyboardshortcutsmodel.cpp:126
void setOverrides(const QMap< QString, QList< QKeySequence > > &overrides) noexcept
Definition: keyboardshortcutsmodel.cpp:67
KeyboardShortcutsModel(const KeyboardShortcutsModel &other)=delete
Definition: occmodel.cpp:77
Definition: keyboardshortcutsmodel.h:45
const EditorCommandCategory * category
Definition: keyboardshortcutsmodel.h:46
QList< const EditorCommand * > commands
Definition: keyboardshortcutsmodel.h:47