23 #include "macros.h" |
23 #include "macros.h" |
24 #include "basics.h" |
24 #include "basics.h" |
25 |
25 |
26 class QSettings; |
26 class QSettings; |
27 |
27 |
28 #define CFGENTRY(T, NAME, DEFAULT) namespace cfg { ConfigEntry::T##Type NAME; } |
28 #define CFGENTRY(T, NAME, DEFAULT) namespace cfg { AbstractConfigEntry::T##Type NAME; } |
29 #define EXTERN_CFGENTRY(T, NAME) namespace cfg { extern ConfigEntry::T##Type NAME; } |
29 #define EXTERN_CFGENTRY(T, NAME) namespace cfg { extern AbstractConfigEntry::T##Type NAME; } |
30 |
30 |
31 namespace Config |
31 namespace Config |
32 { |
32 { |
33 void init(); |
33 void Initialize(); |
34 bool load(); |
34 bool Load(); |
35 bool save(); |
35 bool Save(); |
36 void reset(); |
36 void ResetToDefaults(); |
37 QString dirpath(); |
37 QString DirectoryPath(); |
38 QString filepath (QString file); |
38 QString FilePath (QString file); |
39 QSettings* settingsObject(); |
39 QSettings* SettingsObject(); |
40 } |
40 } |
41 |
41 |
42 class ConfigEntry |
42 class AbstractConfigEntry |
43 { |
43 { |
44 PROPERTY (private, QString, name, setName, STOCK_WRITE) |
44 PROPERTY (private, QString, name, setName, STOCK_WRITE) |
45 |
45 |
46 public: |
46 public: |
47 enum Type |
47 enum Type |
61 using BoolType = bool; |
61 using BoolType = bool; |
62 using KeySequenceType = QKeySequence; |
62 using KeySequenceType = QKeySequence; |
63 using ListType = QList<QVariant>; |
63 using ListType = QList<QVariant>; |
64 using VertexType = Vertex; |
64 using VertexType = Vertex; |
65 |
65 |
66 ConfigEntry (QString name); |
66 AbstractConfigEntry (QString name); |
67 |
67 |
68 virtual QVariant getDefaultAsVariant() const = 0; |
68 virtual QVariant getDefaultAsVariant() const = 0; |
69 virtual Type getType() const = 0; |
69 virtual Type getType() const = 0; |
70 virtual bool isDefault() const = 0; |
70 virtual bool isDefault() const = 0; |
71 virtual void loadFromVariant (const QVariant& val) = 0; |
71 virtual void loadFromVariant (const QVariant& val) = 0; |
72 virtual void resetValue() = 0; |
72 virtual void resetValue() = 0; |
73 virtual QVariant toVariant() const = 0; |
73 virtual QVariant toVariant() const = 0; |
74 }; |
74 }; |
75 |
75 |
76 // ============================================================================= |
|
77 #define IMPLEMENT_CONFIG(NAME) \ |
76 #define IMPLEMENT_CONFIG(NAME) \ |
78 public: \ |
77 public: \ |
79 using ValueType = ConfigEntry::NAME##Type; \ |
78 using ValueType = AbstractConfigEntry::NAME##Type; \ |
80 \ |
79 \ |
81 NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) : \ |
80 NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) : \ |
82 ConfigEntry (name), \ |
81 AbstractConfigEntry (name), \ |
83 m_valueptr (valueptr), \ |
82 m_valueptr (valueptr), \ |
84 m_default (def) \ |
83 m_default (def) \ |
85 { \ |
84 { \ |
86 *m_valueptr = def; \ |
85 *m_valueptr = def; \ |
87 } \ |
86 } \ |
94 inline void setValue (ValueType val) \ |
93 inline void setValue (ValueType val) \ |
95 { \ |
94 { \ |
96 *m_valueptr = val; \ |
95 *m_valueptr = val; \ |
97 } \ |
96 } \ |
98 \ |
97 \ |
99 virtual ConfigEntry::Type getType() const \ |
98 virtual AbstractConfigEntry::Type getType() const \ |
100 { \ |
99 { \ |
101 return ConfigEntry::E##NAME##Type; \ |
100 return AbstractConfigEntry::E##NAME##Type; \ |
102 } \ |
101 } \ |
103 \ |
102 \ |
104 virtual void resetValue() \ |
103 virtual void resetValue() \ |
105 { \ |
104 { \ |
106 *m_valueptr = m_default; \ |
105 *m_valueptr = m_default; \ |
135 \ |
134 \ |
136 private: \ |
135 private: \ |
137 ValueType* m_valueptr; \ |
136 ValueType* m_valueptr; \ |
138 ValueType m_default; |
137 ValueType m_default; |
139 |
138 |
140 // ============================================================================= |
139 class IntConfigEntry : public AbstractConfigEntry |
141 // |
|
142 class IntConfigEntry : public ConfigEntry |
|
143 { |
140 { |
144 IMPLEMENT_CONFIG (Int) |
141 IMPLEMENT_CONFIG (Int) |
145 }; |
142 }; |
146 |
143 |
147 class StringConfigEntry : public ConfigEntry |
144 class StringConfigEntry : public AbstractConfigEntry |
148 { |
145 { |
149 IMPLEMENT_CONFIG (String) |
146 IMPLEMENT_CONFIG (String) |
150 }; |
147 }; |
151 |
148 |
152 class FloatConfigEntry : public ConfigEntry |
149 class FloatConfigEntry : public AbstractConfigEntry |
153 { |
150 { |
154 IMPLEMENT_CONFIG (Float) |
151 IMPLEMENT_CONFIG (Float) |
155 }; |
152 }; |
156 |
153 |
157 class BoolConfigEntry : public ConfigEntry |
154 class BoolConfigEntry : public AbstractConfigEntry |
158 { |
155 { |
159 IMPLEMENT_CONFIG (Bool) |
156 IMPLEMENT_CONFIG (Bool) |
160 }; |
157 }; |
161 |
158 |
162 class KeySequenceConfigEntry : public ConfigEntry |
159 class KeySequenceConfigEntry : public AbstractConfigEntry |
163 { |
160 { |
164 IMPLEMENT_CONFIG (KeySequence) |
161 IMPLEMENT_CONFIG (KeySequence) |
165 }; |
162 }; |
166 |
163 |
167 class ListConfigEntry : public ConfigEntry |
164 class ListConfigEntry : public AbstractConfigEntry |
168 { |
165 { |
169 IMPLEMENT_CONFIG (List) |
166 IMPLEMENT_CONFIG (List) |
170 }; |
167 }; |
171 |
168 |
172 class VertexConfigEntry : public ConfigEntry |
169 class VertexConfigEntry : public AbstractConfigEntry |
173 { |
170 { |
174 IMPLEMENT_CONFIG (Vertex) |
171 IMPLEMENT_CONFIG (Vertex) |
175 }; |
172 }; |