src/platform/qt/ShortcutModel.h (view raw)
1/* Copyright (c) 2013-2019 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#pragma once
7
8#include <QAbstractListModel>
9
10namespace QGBA {
11
12class ShortcutController;
13class Shortcut;
14
15class ShortcutModel : public QAbstractItemModel {
16Q_OBJECT
17
18public:
19 ShortcutModel(QObject* parent = nullptr);
20
21 void setController(ShortcutController* controller);
22
23 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
24
25 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
26
27 virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
28 virtual QModelIndex parent(const QModelIndex& index) const override;
29
30 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
31 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
32
33 QString name(const QModelIndex&) const;
34
35private slots:
36 void addRowNamed(const QString&);
37 void clearMenu(const QString&);
38
39private:
40 ShortcutController* m_controller = nullptr;
41
42 struct Item {
43 QString name;
44 const Shortcut* shortcut = nullptr;
45 };
46
47 QHash<QString, Item> m_cache;
48};
49
50}