Changeset View
Changeset View
Standalone View
Standalone View
plugins/meson/mesonoptions.h
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Daniel Mensinger <daniel@mensinger-ka.de> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include <QString> | ||||
23 | #include <QVector> | ||||
24 | #include <memory> | ||||
25 | | ||||
26 | class QJsonArray; | ||||
27 | class QJsonObject; | ||||
28 | class QWidget; | ||||
29 | class MesonOptionBase; | ||||
30 | class MesonOptions; | ||||
31 | | ||||
32 | using OPT_PTR = std::shared_ptr<MesonOptionBase>; | ||||
33 | using MESON_OPT_PTR = std::shared_ptr<MesonOptions>; | ||||
34 | | ||||
35 | /*! | ||||
36 | * Base class for a single meson option. | ||||
37 | */ | ||||
38 | class MesonOptionBase | ||||
39 | { | ||||
40 | public: | ||||
41 | enum Section { CORE, BACKEND, BASE, COMPILER, DIRECTORY, USER, TEST }; | ||||
42 | enum Type { ARRAY, BOOLEAN, COMBO, INTEGER, STRING }; | ||||
43 | | ||||
44 | public: | ||||
45 | explicit MesonOptionBase(QString name, QString description, Section section); | ||||
46 | virtual ~MesonOptionBase(); | ||||
47 | | ||||
48 | virtual Type type() const = 0; | ||||
49 | virtual QString value() const = 0; | ||||
50 | virtual QString initialValue() const = 0; | ||||
51 | virtual void reset() = 0; | ||||
52 | | ||||
53 | QString name() const; | ||||
54 | QString description() const; | ||||
55 | Section section() const; | ||||
56 | | ||||
57 | QString mesonArg() const; | ||||
58 | bool isUpdated() const; | ||||
59 | | ||||
60 | static OPT_PTR fromJSON(QJsonObject const& obj); | ||||
61 | | ||||
62 | private: | ||||
63 | QString m_name; | ||||
64 | QString m_description; | ||||
65 | Section m_section; | ||||
66 | }; | ||||
67 | | ||||
68 | class MesonOptionArray : public MesonOptionBase | ||||
69 | { | ||||
70 | public: | ||||
71 | MesonOptionArray(QString name, QString description, Section section, QStringList value); | ||||
72 | | ||||
73 | MesonOptionBase::Type type() const override; | ||||
74 | QString value() const override; | ||||
75 | QString initialValue() const override; | ||||
76 | void reset() override; | ||||
77 | | ||||
78 | QStringList rawValue() const; | ||||
79 | void setValue(QStringList val); | ||||
80 | | ||||
81 | private: | ||||
82 | QStringList m_value; | ||||
83 | QStringList m_initialValue; | ||||
84 | }; | ||||
85 | | ||||
86 | class MesonOptionBool : public MesonOptionBase | ||||
87 | { | ||||
88 | public: | ||||
89 | MesonOptionBool(QString name, QString description, Section section, bool value); | ||||
90 | | ||||
91 | MesonOptionBase::Type type() const override; | ||||
92 | QString value() const override; | ||||
93 | QString initialValue() const override; | ||||
94 | void reset() override; | ||||
95 | | ||||
96 | bool rawValue() const; | ||||
97 | void setValue(bool val); | ||||
98 | | ||||
99 | private: | ||||
100 | bool m_value; | ||||
101 | bool m_initialValue; | ||||
102 | }; | ||||
103 | | ||||
104 | class MesonOptionCombo : public MesonOptionBase | ||||
105 | { | ||||
106 | public: | ||||
107 | MesonOptionCombo(QString name, QString description, Section section, QString value, QStringList choices); | ||||
108 | | ||||
109 | MesonOptionBase::Type type() const override; | ||||
110 | QString value() const override; | ||||
111 | QString initialValue() const override; | ||||
112 | void reset() override; | ||||
113 | | ||||
114 | QString rawValue() const; | ||||
115 | void setValue(QString val); | ||||
116 | QStringList choices() const; | ||||
117 | | ||||
118 | private: | ||||
119 | QString m_value; | ||||
120 | QString m_initialValue; | ||||
121 | QStringList m_choices; | ||||
122 | }; | ||||
123 | | ||||
124 | class MesonOptionInteger : public MesonOptionBase | ||||
125 | { | ||||
126 | public: | ||||
127 | MesonOptionInteger(QString name, QString description, Section section, int value); | ||||
128 | | ||||
129 | MesonOptionBase::Type type() const override; | ||||
130 | QString value() const override; | ||||
131 | QString initialValue() const override; | ||||
132 | void reset() override; | ||||
133 | | ||||
134 | int rawValue() const; | ||||
135 | void setValue(int val); | ||||
136 | | ||||
137 | private: | ||||
138 | int m_value; | ||||
139 | int m_initialValue; | ||||
140 | }; | ||||
141 | | ||||
142 | class MesonOptionString : public MesonOptionBase | ||||
143 | { | ||||
144 | public: | ||||
145 | MesonOptionString(QString name, QString description, Section section, QString value); | ||||
146 | | ||||
147 | MesonOptionBase::Type type() const override; | ||||
148 | QString value() const override; | ||||
149 | QString initialValue() const override; | ||||
150 | void reset() override; | ||||
151 | | ||||
152 | QString rawValue() const; | ||||
153 | void setValue(QString val); | ||||
154 | | ||||
155 | private: | ||||
156 | QString m_value; | ||||
157 | QString m_initialValue; | ||||
158 | }; | ||||
159 | | ||||
160 | /*! | ||||
161 | * Container class for all meson project options. | ||||
162 | */ | ||||
163 | class MesonOptions | ||||
164 | { | ||||
165 | public: | ||||
166 | explicit MesonOptions(QJsonArray const& arr); | ||||
167 | | ||||
168 | int numChanged() const; | ||||
169 | QStringList getMesonArgs() const; | ||||
170 | void print() const; | ||||
171 | | ||||
172 | QVector<OPT_PTR> options(); | ||||
173 | | ||||
174 | private: | ||||
175 | QVector<OPT_PTR> m_options; | ||||
176 | | ||||
177 | void fromJSON(QJsonArray const& arr); | ||||
178 | }; |