src/configuration.h

changeset 789
4b7306f52bb5
parent 757
8ab9fa53142b
child 794
c254ddc6618b
equal deleted inserted replaced
788:c9d1dad83ad0 789:4b7306f52bb5
41 namespace Config 41 namespace Config
42 { 42 {
43 bool load(); 43 bool load();
44 bool save(); 44 bool save();
45 void reset(); 45 void reset();
46 String dirpath(); 46 QString dirpath();
47 String filepath (String file); 47 QString filepath (QString file);
48 } 48 }
49 49
50 // ========================================================= 50 // =========================================================
51 class ConfigEntry 51 class ConfigEntry
52 { 52 {
53 PROPERTY (private, String, name, setName, STOCK_WRITE) 53 PROPERTY (private, QString, name, setName, STOCK_WRITE)
54 54
55 public: 55 public:
56 enum Type 56 enum Type
57 { 57 {
58 EIntType, 58 EIntType,
63 EListType, 63 EListType,
64 EVertexType, 64 EVertexType,
65 }; 65 };
66 66
67 using IntType = int; 67 using IntType = int;
68 using StringType = String; 68 using StringType = QString;
69 using FloatType = float; 69 using FloatType = float;
70 using BoolType = bool; 70 using BoolType = bool;
71 using KeySequenceType = QKeySequence; 71 using KeySequenceType = QKeySequence;
72 using ListType = QList<QVariant>; 72 using ListType = QList<QVariant>;
73 using VertexType = Vertex; 73 using VertexType = Vertex;
74 74
75 ConfigEntry (String name); 75 ConfigEntry (QString name);
76 76
77 virtual QVariant getDefaultAsVariant() const = 0; 77 virtual QVariant getDefaultAsVariant() const = 0;
78 virtual Type getType() const = 0; 78 virtual Type getType() const = 0;
79 virtual bool isDefault() const = 0; 79 virtual bool isDefault() const = 0;
80 virtual void loadFromVariant (const QVariant& val) = 0; 80 virtual void loadFromVariant (const QVariant& val) = 0;
88 // ============================================================================= 88 // =============================================================================
89 #define IMPLEMENT_CONFIG(NAME) \ 89 #define IMPLEMENT_CONFIG(NAME) \
90 public: \ 90 public: \
91 using ValueType = ConfigEntry::NAME##Type; \ 91 using ValueType = ConfigEntry::NAME##Type; \
92 \ 92 \
93 NAME##ConfigEntry (ValueType* valueptr, String name, ValueType def) : \ 93 NAME##ConfigEntry (ValueType* valueptr, QString name, ValueType def) : \
94 ConfigEntry (name), \ 94 ConfigEntry (name), \
95 m_valueptr (valueptr), \ 95 m_valueptr (valueptr), \
96 m_default (def) \ 96 m_default (def) \
97 { \ 97 { \
98 ConfigEntry::addToArray (this); \ 98 ConfigEntry::addToArray (this); \
142 virtual QVariant getDefaultAsVariant() const \ 142 virtual QVariant getDefaultAsVariant() const \
143 { \ 143 { \
144 return QVariant::fromValue<ValueType> (m_default); \ 144 return QVariant::fromValue<ValueType> (m_default); \
145 } \ 145 } \
146 \ 146 \
147 static NAME##ConfigEntry* getByName (String name); \ 147 static NAME##ConfigEntry* getByName (QString name); \
148 \ 148 \
149 private: \ 149 private: \
150 ValueType* m_valueptr; \ 150 ValueType* m_valueptr; \
151 ValueType m_default; 151 ValueType m_default;
152 152

mercurial