src/configuration.h

changeset 845
fec7023e91a7
parent 844
11587d419d2f
child 848
68410477c8bb
equal deleted inserted replaced
844:11587d419d2f 845:fec7023e91a7
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) \ 28 #define CFGENTRY(T, NAME, DEFAULT) namespace cfg { ConfigEntry::T##Type NAME; }
29 namespace cfg \ 29 #define EXTERN_CFGENTRY(T, NAME) namespace cfg { extern ConfigEntry::T##Type NAME; }
30 { \
31 ConfigEntry::T##Type NAME; \
32 T##ConfigEntry config_##NAME (&NAME, #NAME, DEFAULT); \
33 }
34
35 #define EXTERN_CFGENTRY(T, NAME) \
36 namespace cfg \
37 { \
38 extern ConfigEntry::T##Type NAME; \
39 }
40 30
41 namespace Config 31 namespace Config
42 { 32 {
33 void init();
43 bool load(); 34 bool load();
44 bool save(); 35 bool save();
45 void reset(); 36 void reset();
46 QString dirpath(); 37 QString dirpath();
47 QString filepath (QString file); 38 QString filepath (QString file);
78 virtual Type getType() const = 0; 69 virtual Type getType() const = 0;
79 virtual bool isDefault() const = 0; 70 virtual bool isDefault() const = 0;
80 virtual void loadFromVariant (const QVariant& val) = 0; 71 virtual void loadFromVariant (const QVariant& val) = 0;
81 virtual void resetValue() = 0; 72 virtual void resetValue() = 0;
82 virtual QVariant toVariant() const = 0; 73 virtual QVariant toVariant() const = 0;
83
84
85 protected:
86 static void addToArray (ConfigEntry* ptr);
87 }; 74 };
88 75
89 // ============================================================================= 76 // =============================================================================
90 #define IMPLEMENT_CONFIG(NAME) \ 77 #define IMPLEMENT_CONFIG(NAME) \
91 public: \ 78 public: \
94 NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) : \ 81 NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) : \
95 ConfigEntry (name), \ 82 ConfigEntry (name), \
96 m_valueptr (valueptr), \ 83 m_valueptr (valueptr), \
97 m_default (def) \ 84 m_default (def) \
98 { \ 85 { \
99 ConfigEntry::addToArray (this); \
100 *m_valueptr = def; \ 86 *m_valueptr = def; \
101 } \ 87 } \
102 \ 88 \
103 inline ValueType getValue() const \ 89 inline ValueType getValue() const \
104 { \ 90 { \

mercurial