src/dialogs/shortcutsmodel.h

changeset 1433
bd3a9e237ef5
equal deleted inserted replaced
1432:4cc687851fbb 1433:bd3a9e237ef5
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 - 2018 Teemu Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20 #include <QAbstractItemModel>
21 #include <QAction>
22 #include <QStyledItemDelegate>
23 #include "main.h"
24
25 /*
26 * Implements a delegate for editing key sequence cells.
27 */
28 class KeySequenceDelegate : public QStyledItemDelegate
29 {
30 public:
31 KeySequenceDelegate(QObject* parent = nullptr);
32 QWidget* createEditor(
33 QWidget *parent,
34 const QStyleOptionViewItem &option,
35 const QModelIndex &index) const override;
36 void setEditorData(QWidget *widget, const QModelIndex &index) const override;
37 void setModelData(
38 QWidget *widget,
39 QAbstractItemModel *model,
40 const QModelIndex &index) const override;
41 void updateEditorGeometry(
42 QWidget *editor,
43 const QStyleOptionViewItem &option,
44 const QModelIndex &index) const override;
45 };
46
47 /*
48 * Models a table of shortcuts. Each action in the provided main window is given
49 * a row, which contains editable shortcuts.
50 *
51 * Calling saveChanges updates the actions and updates the settings object.
52 */
53 class ShortcutsModel : public QAbstractItemModel
54 {
55 public:
56 enum Column
57 {
58 ActionColumn,
59 KeySequenceColumn
60 };
61
62 enum
63 {
64 DefaultKeySequenceRole = Qt::UserRole
65 };
66
67 ShortcutsModel(class MainWindow* parent);
68 int rowCount(QModelIndex const&) const override;
69 int columnCount(QModelIndex const&) const override;
70 QVariant data(const QModelIndex &index, int role) const override;
71 Qt::ItemFlags flags(const QModelIndex& index) const override;
72 bool isValidRow(int row) const;
73 bool isValidIndex(const QModelIndex &index) const;
74 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
75 void saveChanges();
76 QModelIndex index(int row, int column, const QModelIndex& parent) const override;
77 QModelIndex parent(const QModelIndex& child) const override;
78 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
79
80 private:
81 struct Item
82 {
83 QAction* action;
84 QKeySequence sequence;
85 const QKeySequence defaultSequence;
86 };
87
88 QVector<Item> shortcuts;
89 };

mercurial