all repos — mgba @ e7be40e80ccb6dbeee0b79c97f349859b1b4afb8

mGBA Game Boy Advance Emulator

src/platform/qt/input/InputModel.h (view raw)

 1/* Copyright (c) 2013-2017 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#ifndef QGBA_INPUT_MODEL
 7#define QGBA_INPUT_MODEL
 8
 9#include <mgba/core/core.h>
10
11#include "InputIndex.h"
12
13#include <QAbstractItemModel>
14#include <QMenu>
15#include <QSet>
16
17#include <functional>
18
19class QAction;
20class QKeyEvent;
21class QMenu;
22class QString;
23
24namespace QGBA {
25
26class ConfigController;
27class InputIndex;
28class InputProfile;
29
30class InputModel : public QAbstractItemModel {
31Q_OBJECT
32
33public:
34	InputModel(const InputIndex& index, QObject* parent = nullptr);
35	InputModel(QObject* parent = nullptr);
36
37	void clone(const InputIndex& index);
38
39	void setProfile(const QString& profile);
40
41	virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
42	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
43
44	virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
45	virtual QModelIndex parent(const QModelIndex& index) const override;
46
47	virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
48	virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
49
50	InputItem* itemAt(const QModelIndex& index);
51	const InputItem* itemAt(const QModelIndex& index) const;
52
53	InputIndex* inputIndex() { return &m_index; }
54
55private:
56	struct InputModelItem {
57		InputModelItem(InputItem* i) : item(i), obj(i) {}
58		InputModelItem(const QMenu* i) : menu(i), obj(i) {}
59		InputModelItem(const QObject* i) : obj(i) {}
60
61		InputItem* item = nullptr;
62		const QMenu* menu = nullptr;
63		const QObject* obj;
64
65		QString visibleName() const;
66		bool operator==(const InputModelItem& other) { return obj == other.obj; }
67	};
68
69	QModelIndex index(const QObject* item, int column = 0) const;
70
71	InputIndex m_index;
72	QList<InputModelItem> m_topLevelMenus;
73	QSet<const QObject*> m_menus;
74	QMap<const QObject*, QList<InputModelItem>> m_tree;
75	QString m_profileName;
76};
77
78}
79
80#endif