26 #include <QVariant> |
26 #include <QVariant> |
27 #include <QKeySequence> |
27 #include <QKeySequence> |
28 class QSettings; |
28 class QSettings; |
29 |
29 |
30 typedef QChar QChar; |
30 typedef QChar QChar; |
31 typedef QString str; |
31 typedef QString QString; |
32 |
32 |
33 #define MAX_INI_LINE 512 |
33 #define MAX_INI_LINE 512 |
34 #define MAX_CONFIG 512 |
34 #define MAX_CONFIG 512 |
35 |
35 |
36 #define cfg(T, NAME, DEFAULT) \ |
36 #define cfg(T, NAME, DEFAULT) \ |
40 #define extern_cfg(T, NAME) extern Config::T##Type NAME; |
40 #define extern_cfg(T, NAME) extern Config::T##Type NAME; |
41 |
41 |
42 // ========================================================= |
42 // ========================================================= |
43 class Config |
43 class Config |
44 { |
44 { |
45 PROPERTY (private, str, Name, STR_OPS, STOCK_WRITE) |
45 PROPERTY (private, QString, Name, STR_OPS, STOCK_WRITE) |
46 |
46 |
47 public: |
47 public: |
48 enum Type |
48 enum Type |
49 { |
49 { |
50 Int, |
50 Int, |
53 Bool, |
53 Bool, |
54 KeySequence, |
54 KeySequence, |
55 List, |
55 List, |
56 }; |
56 }; |
57 |
57 |
58 using IntType = int; |
58 using IntType = int; |
59 using StringType = QString; |
59 using StringType = QString; |
60 using FloatType = float; |
60 using FloatType = float; |
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 |
64 |
65 Config (str name); |
65 Config (QString name); |
66 |
66 |
67 virtual QVariant getDefaultAsVariant() const = 0; |
67 virtual QVariant getDefaultAsVariant() const = 0; |
68 virtual Type getType() const = 0; |
68 virtual Type getType() const = 0; |
69 virtual bool isDefault() const = 0; |
69 virtual bool isDefault() const = 0; |
70 virtual void loadFromVariant (const QVariant& val) = 0; |
70 virtual void loadFromVariant (const QVariant& val) = 0; |
73 |
73 |
74 // ------------------------------------------ |
74 // ------------------------------------------ |
75 static bool load(); |
75 static bool load(); |
76 static bool save(); |
76 static bool save(); |
77 static void reset(); |
77 static void reset(); |
78 static str dirpath(); |
78 static QString dirpath(); |
79 static str filepath (str file); |
79 static QString filepath (QString file); |
80 |
80 |
81 protected: |
81 protected: |
82 static void addToArray (Config* ptr); |
82 static void addToArray (Config* ptr); |
83 }; |
83 }; |
84 |
84 |
85 // ============================================================================= |
85 // ============================================================================= |
86 #define IMPLEMENT_CONFIG(NAME) \ |
86 #define IMPLEMENT_CONFIG(NAME) \ |
87 public: \ |
87 public: \ |
88 using ValueType = Config::NAME##Type; \ |
88 using ValueType = Config::NAME##Type; \ |
89 \ |
89 \ |
90 NAME##Config (ValueType* valueptr, str name, ValueType def) : \ |
90 NAME##Config (ValueType* valueptr, QString name, ValueType def) : \ |
91 Config (name), \ |
91 Config (name), \ |
92 m_valueptr (valueptr), \ |
92 m_valueptr (valueptr), \ |
93 m_default (def) \ |
93 m_default (def) \ |
94 { \ |
94 { \ |
95 Config::addToArray (this); \ |
95 Config::addToArray (this); \ |