Tue, 07 Jan 2014 08:53:27 +0200
- reformatting
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
600
209e3f1f7b2c
- updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
299
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
299
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
299
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
19 | #ifndef LDFORGE_CONFIG_H |
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
20 | #define LDFORGE_CONFIG_H |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
22 | #include "property.h" |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
23 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | // ============================================================================= |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include <QString> |
467
59549731151a
Added ListConfig type, using it in recent files now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
465
diff
changeset
|
26 | #include <QVariant> |
298
f945fc8dae9e
Nuked the now-empty string.cpp/.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
27 | #include <QKeySequence> |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
28 | class QSettings; |
298
f945fc8dae9e
Nuked the now-empty string.cpp/.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
29 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
497
diff
changeset
|
30 | typedef QChar QChar; |
298
f945fc8dae9e
Nuked the now-empty string.cpp/.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
31 | typedef QString str; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #define MAX_INI_LINE 512 |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
34 | #define MAX_CONFIG 512 |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
36 | #define cfg(T, NAME, DEFAULT) \ |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
37 | Config::T##Type NAME; \ |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
38 | T##Config config_##NAME (&NAME, #NAME, DEFAULT); |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
39 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
40 | #define extern_cfg(T, NAME) extern Config::T##Type NAME; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // ========================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
43 | class Config |
603 | 44 | { |
45 | PROPERTY (private, str, Name, STR_OPS, STOCK_WRITE) | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
46 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
47 | public: |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
48 | enum Type |
603 | 49 | { |
50 | Int, | |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
51 | String, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
52 | Float, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
53 | Bool, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
54 | KeySequence, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
55 | List, |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
56 | }; |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
299
diff
changeset
|
57 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
58 | using IntType = int; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
59 | using StringType = QString; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
60 | using FloatType = float; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
61 | using BoolType = bool; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
62 | using KeySequenceType = QKeySequence; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
63 | using ListType = QList<QVariant>; |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
299
diff
changeset
|
64 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
65 | Config (str name); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
66 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
67 | virtual QVariant getDefaultAsVariant() const = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
68 | virtual Type getType() const = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
69 | virtual bool isDefault() const = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
70 | virtual void loadFromVariant (const QVariant& val) = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
71 | virtual void resetValue() = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
72 | virtual QVariant toVariant() const = 0; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
73 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
74 | // ------------------------------------------ |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
75 | static bool load(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
76 | static bool save(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
77 | static void reset(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
78 | static str dirpath(); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
79 | static str filepath (str file); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
80 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
81 | protected: |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
82 | static void addToArray (Config* ptr); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | // ============================================================================= |
603 | 86 | #define IMPLEMENT_CONFIG(NAME) \ |
87 | public: \ | |
88 | using ValueType = Config::NAME##Type; \ | |
89 | \ | |
90 | NAME##Config (ValueType* valueptr, str name, ValueType def) : \ | |
91 | Config (name), \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
92 | m_valueptr (valueptr), \ |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
93 | m_default (def) \ |
603 | 94 | { \ |
95 | Config::addToArray (this); \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
96 | *m_valueptr = def; \ |
603 | 97 | } \ |
98 | \ | |
99 | inline ValueType getValue() const \ | |
100 | { \ | |
101 | return *m_valueptr; \ | |
102 | } \ | |
103 | \ | |
104 | inline void setValue (ValueType val) \ | |
105 | { \ | |
106 | *m_valueptr = val; \ | |
107 | } \ | |
108 | \ | |
109 | virtual Config::Type getType() const \ | |
110 | { \ | |
111 | return Config::NAME; \ | |
112 | } \ | |
113 | \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
114 | virtual void resetValue() \ |
603 | 115 | { \ |
116 | *m_valueptr = m_default; \ | |
117 | } \ | |
118 | \ | |
119 | virtual const ValueType& getDefault() const \ | |
120 | { \ | |
121 | return m_default; \ | |
122 | } \ | |
123 | \ | |
124 | virtual bool isDefault() const \ | |
125 | { \ | |
126 | return *m_valueptr == m_default; \ | |
127 | } \ | |
128 | \ | |
129 | virtual void loadFromVariant (const QVariant& val) \ | |
130 | { \ | |
131 | *m_valueptr = val.value<ValueType>(); \ | |
132 | } \ | |
133 | \ | |
134 | virtual QVariant toVariant() const \ | |
135 | { \ | |
136 | return QVariant::fromValue<ValueType> (*m_valueptr); \ | |
137 | } \ | |
138 | \ | |
139 | virtual QVariant getDefaultAsVariant() const \ | |
140 | { \ | |
141 | return QVariant::fromValue<ValueType> (m_default); \ | |
142 | } \ | |
143 | \ | |
144 | static NAME##Config* getByName (str name); \ | |
145 | \ | |
146 | private: \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
147 | ValueType* m_valueptr; \ |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
148 | ValueType m_default; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
151 | class IntConfig : public Config |
603 | 152 | { |
153 | IMPLEMENT_CONFIG (Int) | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
157 | class StringConfig : public Config |
603 | 158 | { |
159 | IMPLEMENT_CONFIG (String) | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
163 | class FloatConfig : public Config |
603 | 164 | { |
165 | IMPLEMENT_CONFIG (Float) | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
169 | class BoolConfig : public Config |
603 | 170 | { |
171 | IMPLEMENT_CONFIG (Bool) | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
175 | class KeySequenceConfig : public Config |
603 | 176 | { |
177 | IMPLEMENT_CONFIG (KeySequence) | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | }; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
467
59549731151a
Added ListConfig type, using it in recent files now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
465
diff
changeset
|
180 | // ============================================================================= |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
471
diff
changeset
|
181 | class ListConfig : public Config |
603 | 182 | { |
183 | IMPLEMENT_CONFIG (List) | |
467
59549731151a
Added ListConfig type, using it in recent files now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
465
diff
changeset
|
184 | }; |
59549731151a
Added ListConfig type, using it in recent files now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
465
diff
changeset
|
185 | |
497
c51941e590b6
a bit more cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
186 | #endif // LDFORGE_CONFIG_H |