Tue, 07 Jan 2014 08:53:27 +0200
- reformatting
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
04e140bdeb0b
- changed source file extension from .cpp to .cc
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:
599
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | * ===================================================================== |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | * config.cpp: Configuration management. I don't like how unsafe QSettings |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | * is so this implements a type-safer and identifer-safer wrapping system of |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | * configuration variables. QSettings is used underlyingly, this is a matter |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | * of interface. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | */ |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include <errno.h> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include <QDir> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include <QTextStream> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include <QSettings> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "main.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "config.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "misc.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "gui.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "document.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #ifdef _WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | # define EXTENSION ".ini" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | #else |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | # define EXTENSION ".cfg" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | #endif // _WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
41 | Config* g_configPointers[MAX_CONFIG]; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
42 | static int g_cfgPointerCursor = 0; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
43 | static QMap<str, Config*> g_configsByName; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
44 | static QList<Config*> g_configs; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | // ============================================================================= |
589
1417828920e6
- use a local file with QSettings at all times. Registry is such a pain..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
47 | // Get the QSettings object. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | static QSettings* getSettingsObject() |
603 | 50 | { |
51 | return new QSettings (UNIXNAME EXTENSION, QSettings::IniFormat); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
54 | Config::Config (str name) : |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
55 | m_Name (name) {} |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // Load the configuration from file |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | bool Config::load() |
603 | 61 | { |
62 | QSettings* settings = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | log ("config::load: Loading configuration file from %1\n", settings->fileName()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | for (Config* cfg : g_configPointers) |
603 | 66 | { |
67 | if (!cfg) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | break; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
70 | QVariant val = settings->value (cfg->getName(), cfg->getDefaultAsVariant()); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | cfg->loadFromVariant (val); |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
72 | g_configsByName[cfg->getName()] = cfg; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
73 | g_configs << cfg; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | settings->deleteLater(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | // Save the configuration to disk |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | bool Config::save() |
603 | 84 | { |
85 | QSettings* settings = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | log ("Saving configuration to %1...\n", settings->fileName()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
88 | for (Config* cfg : g_configs) |
603 | 89 | { |
90 | if (!cfg->isDefault()) | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
91 | settings->setValue (cfg->getName(), cfg->toVariant()); |
599
b77aecd27fb0
- when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
92 | else |
b77aecd27fb0
- when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
93 | settings->remove (cfg->getName()); |
b77aecd27fb0
- when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
94 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | settings->sync(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | settings->deleteLater(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | // ============================================================================= |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
102 | // Reset configuration to defaults. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | void Config::reset() |
603 | 105 | { |
106 | for (Config* cfg : g_configs) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | cfg->resetValue(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | // ============================================================================= |
589
1417828920e6
- use a local file with QSettings at all times. Registry is such a pain..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
111 | // Where is the configuration file located at? |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | str Config::filepath (str file) |
603 | 114 | { |
115 | return Config::dirpath() + DIRSLASH + file; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // ============================================================================= |
589
1417828920e6
- use a local file with QSettings at all times. Registry is such a pain..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
587
diff
changeset
|
119 | // Directory of the configuration file. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | str Config::dirpath() |
603 | 122 | { |
123 | QSettings* cfg = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | return dirname (cfg->fileName()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | // We cannot just add config objects to a list or vector because that would rely |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | // on the vector's c-tor being called before the configs' c-tors. With global |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
130 | // variables we cannot assume that, therefore we need to use a C-style array here. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | void Config::addToArray (Config* ptr) |
603 | 133 | { |
134 | if (g_cfgPointerCursor == 0) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | memset (g_configPointers, 0, sizeof g_configPointers); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | assert (g_cfgPointerCursor < MAX_CONFIG); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | g_configPointers[g_cfgPointerCursor++] = ptr; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | } |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
140 | |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
141 | // ============================================================================= |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
142 | // ----------------------------------------------------------------------------- |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
143 | template<class T> T* getConfigByName (str name, Config::Type type) |
603 | 144 | { |
145 | auto it = g_configsByName.find (name); | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
146 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
147 | if (it == g_configsByName.end()) |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
148 | return null; |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
149 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
150 | Config* cfg = it.value(); |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
151 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
152 | if (cfg->getType() != type) |
603 | 153 | { |
154 | fprint (stderr, "type of %1 is %2, not %3\n", name, cfg->getType(), type); | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
155 | abort(); |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
156 | } |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
157 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
158 | return reinterpret_cast<T*> (cfg); |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
159 | } |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
160 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
161 | // ============================================================================= |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
162 | // ----------------------------------------------------------------------------- |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
163 | #undef IMPLEMENT_CONFIG |
603 | 164 | #define IMPLEMENT_CONFIG(NAME) \ |
165 | NAME##Config* NAME##Config::getByName (str name) \ | |
166 | { \ | |
167 | return getConfigByName<NAME##Config> (name, NAME); \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
168 | } |
587
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
169 | |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
170 | IMPLEMENT_CONFIG (Int) |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
171 | IMPLEMENT_CONFIG (String) |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
172 | IMPLEMENT_CONFIG (Bool) |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
173 | IMPLEMENT_CONFIG (Float) |
507e5d5c348c
- removed the horrible actions.h hack in favor of usage of Qt's meta object system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
174 | IMPLEMENT_CONFIG (List) |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
175 | IMPLEMENT_CONFIG (KeySequence) |