Fri, 10 Jan 2014 03:35:50 +0200
- configuration is now always situated and read from the application working directory
- primitive scanner now works for sure
- some minor cleanup
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; |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
603
diff
changeset
|
43 | static QMap<QString, Config*> g_configsByName; |
590
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 | { |
611
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
51 | QString path = getApplicationDirectory() + DIRSLASH UNIXNAME EXTENSION; |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
52 | |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
53 | #if DIRSLASH_CHAR != '/' |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
54 | path.replace (DIRSLASH, "/"); |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
55 | #endif |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
56 | |
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
57 | return new QSettings (path, QSettings::IniFormat); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
603
diff
changeset
|
60 | Config::Config (QString name) : |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
61 | m_Name (name) {} |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | // Load the configuration from file |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | bool Config::load() |
603 | 67 | { |
68 | QSettings* settings = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | 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
|
70 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | for (Config* cfg : g_configPointers) |
603 | 72 | { |
73 | if (!cfg) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | break; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
76 | 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
|
77 | cfg->loadFromVariant (val); |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
78 | g_configsByName[cfg->getName()] = cfg; |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
79 | g_configs << cfg; |
557
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 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | settings->deleteLater(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | // Save the configuration to disk |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | bool Config::save() |
603 | 90 | { |
91 | QSettings* settings = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | 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
|
93 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
94 | for (Config* cfg : g_configs) |
603 | 95 | { |
96 | if (!cfg->isDefault()) | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
97 | 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
|
98 | else |
b77aecd27fb0
- when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
99 | 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
|
100 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | settings->sync(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | settings->deleteLater(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | // ============================================================================= |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
108 | // Reset configuration to defaults. |
557
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 | void Config::reset() |
603 | 111 | { |
112 | for (Config* cfg : g_configs) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | cfg->resetValue(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | // ============================================================================= |
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
|
117 | // 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
|
118 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
603
diff
changeset
|
119 | QString Config::filepath (QString file) |
603 | 120 | { |
121 | return Config::dirpath() + DIRSLASH + file; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | // ============================================================================= |
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
|
125 | // Directory of the configuration file. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
603
diff
changeset
|
127 | QString Config::dirpath() |
603 | 128 | { |
129 | QSettings* cfg = getSettingsObject(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | return dirname (cfg->fileName()); |
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 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | // 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
|
135 | // 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
|
136 | // 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
|
137 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | void Config::addToArray (Config* ptr) |
603 | 139 | { |
140 | if (g_cfgPointerCursor == 0) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | memset (g_configPointers, 0, sizeof g_configPointers); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | assert (g_cfgPointerCursor < MAX_CONFIG); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | g_configPointers[g_cfgPointerCursor++] = ptr; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | } |
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
|
146 | |
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
|
147 | // ============================================================================= |
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
|
148 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
603
diff
changeset
|
149 | template<class T> T* getConfigByName (QString name, Config::Type type) |
603 | 150 | { |
151 | auto it = g_configsByName.find (name); | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
152 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
153 | if (it == g_configsByName.end()) |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
154 | 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
|
155 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
156 | Config* cfg = it.value(); |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
157 | |
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
158 | if (cfg->getType() != type) |
603 | 159 | { |
160 | 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
|
161 | 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
|
162 | } |
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 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
164 | 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
|
165 | } |
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
|
166 | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
167 | // ============================================================================= |
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 | #undef IMPLEMENT_CONFIG |
611
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
170 | |
603 | 171 | #define IMPLEMENT_CONFIG(NAME) \ |
611
6679e47b019f
- configuration is now always situated and read from the application working directory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
172 | NAME##Config* NAME##Config::getByName (QString name) \ |
603 | 173 | { \ |
174 | return getConfigByName<NAME##Config> (name, NAME); \ | |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
175 | } |
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
|
176 | |
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
|
177 | 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
|
178 | 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
|
179 | 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
|
180 | 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
|
181 | IMPLEMENT_CONFIG (List) |
590
7aec744ce97b
- refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
589
diff
changeset
|
182 | IMPLEMENT_CONFIG (KeySequence) |