src/config.h

changeset 467
59549731151a
parent 465
0f67ff766458
child 468
7b3159f1a9e2
equal deleted inserted replaced
466:17f2fd25066c 467:59549731151a
21 21
22 #include "common.h" 22 #include "common.h"
23 23
24 // ============================================================================= 24 // =============================================================================
25 #include <QString> 25 #include <QString>
26 #include <QVariant>
26 #include <QKeySequence> 27 #include <QKeySequence>
27 class QSettings; 28 class QSettings;
28 29
29 typedef QChar qchar; 30 typedef QChar qchar;
30 typedef QString str; 31 typedef QString str;
42 Int, 43 Int,
43 String, 44 String,
44 Float, 45 Float,
45 Bool, 46 Bool,
46 KeySequence, 47 KeySequence,
48 List,
47 }; 49 };
48 50
49 Config (const char* name, const char* defstring); 51 Config (const char* name, const char* defstring);
50 const char* name; 52 const char* name;
51 53
52 virtual Type getType() const { 54 virtual Type getType() const {
53 return (Type) 0; 55 return (Type) 0;
54 } 56 }
55 57
56 str toString() const;
57 str defaultString() const; 58 str defaultString() const;
58 virtual void resetValue() {} 59 virtual void resetValue() {}
59 virtual void loadFromConfig (const QSettings* cfg) { (void) cfg; } 60 virtual void loadFromConfig (const QSettings* cfg) { (void) cfg; }
60 virtual bool isDefault() const { return false; } 61 virtual bool isDefault() const { return false; }
62 virtual QVariant toVariant() const { return QVariant(); }
61 63
62 // ------------------------------------------ 64 // ------------------------------------------
63 static bool load(); 65 static bool load();
64 static bool save(); 66 static bool save();
65 static void reset(); 67 static void reset();
82 \ 84 \
83 operator const T&() const { return value; } \ 85 operator const T&() const { return value; } \
84 Config::Type getType() const override { return Config::NAME; } \ 86 Config::Type getType() const override { return Config::NAME; } \
85 virtual void resetValue() { value = defval; } \ 87 virtual void resetValue() { value = defval; } \
86 virtual bool isDefault() const { return value == defval; } \ 88 virtual bool isDefault() const { return value == defval; } \
87 virtual void loadFromConfig (const QSettings* cfg) override; 89 virtual void loadFromConfig (const QSettings* cfg) override; \
90 virtual QVariant toVariant() const { return QVariant::fromValue<T> (value); }
88 91
89 #define DEFINE_UNARY_OPERATOR(T, OP) \ 92 #define DEFINE_UNARY_OPERATOR(T, OP) \
90 T operator OP() { \ 93 T operator OP() { \
91 return OP value; \ 94 return OP value; \
92 } 95 }
200 IMPLEMENT_CONFIG (KeySequence, QKeySequence) 203 IMPLEMENT_CONFIG (KeySequence, QKeySequence)
201 DEFINE_ALL_COMPARE_OPERATORS (QKeySequence) 204 DEFINE_ALL_COMPARE_OPERATORS (QKeySequence)
202 DEFINE_ASSIGN_OPERATOR (QKeySequence, =) 205 DEFINE_ASSIGN_OPERATOR (QKeySequence, =)
203 }; 206 };
204 207
208 // =============================================================================
209 class ListConfig : public Config {
210 public:
211 IMPLEMENT_CONFIG (List, QList<QVariant>)
212 DEFINE_ASSIGN_OPERATOR (QList<QVariant>, =)
213
214 typedef QList<QVariant>::iterator it;
215 typedef QList<QVariant>::const_iterator c_it;
216
217 it begin() {
218 return value.begin();
219 }
220
221 c_it begin() const {
222 return value.constBegin();
223 }
224
225 it end() {
226 return value.end();
227 }
228
229 c_it end() const {
230 return value.constEnd();
231 }
232 };
233
205 #endif // CONFIG_H 234 #endif // CONFIG_H

mercurial