all repos — mgba @ 0f2c4e5baf62ccd5c5d3eb3f8950ca1cad36f501

mGBA Game Boy Advance Emulator

src/platform/qt/ConfigController.h (view raw)

 1#ifndef QGBA_CONFIG_CONTROLLER
 2#define QGBA_CONFIG_CONTROLLER
 3
 4#include <QMap>
 5#include <QObject>
 6#include <QScopedPointer>
 7#include <QVariant>
 8
 9extern "C" {
10#include "gba-config.h"
11#include "util/configuration.h"
12}
13
14class QAction;
15class QMenu;
16
17struct GBAArguments;
18
19namespace QGBA {
20
21class ConfigOption : public QObject {
22Q_OBJECT
23
24public:
25	ConfigOption(QObject* parent = nullptr);
26
27	void connect(std::function<void(const QVariant&)>);
28
29	QAction* addValue(const QString& text, const QVariant& value, QMenu* parent = 0);
30	QAction* addValue(const QString& text, const char* value, QMenu* parent = 0);
31	QAction* addBoolean(const QString& text, QMenu* parent = 0);
32
33public slots:
34	void setValue(bool value);
35	void setValue(int value);
36	void setValue(unsigned value);
37	void setValue(const char* value);
38	void setValue(const QVariant& value);
39
40signals:
41	void valueChanged(const QVariant& value);
42
43private:
44	std::function<void(const QVariant&)> m_slot;
45	QList<QPair<QAction*, QVariant>> m_actions;
46};
47
48class ConfigController : public QObject {
49Q_OBJECT
50
51public:
52	constexpr static const char* const PORT = "qt";
53
54	ConfigController(QObject* parent = nullptr);
55	~ConfigController();
56
57	const GBAOptions* options() const { return &m_opts; }
58	bool parseArguments(GBAArguments* args, int argc, char* argv[]);
59
60	const Configuration* configuration() const { return &m_config.configTable; }
61	const Configuration* defaults() const { return &m_config.defaultsTable; }
62
63	ConfigOption* addOption(const char* key);
64	void updateOption(const char* key);
65
66public slots:
67	void setOption(const char* key, bool value);
68	void setOption(const char* key, int value);
69	void setOption(const char* key, unsigned value);
70	void setOption(const char* key, const char* value);
71	void setOption(const char* key, const QVariant& value);
72
73	void write();
74
75private:
76	GBAConfig m_config;
77	GBAOptions m_opts;
78
79	QMap<QString, ConfigOption*> m_optionSet;
80};
81
82}
83
84#endif