src/config.cc

Wed, 01 Jan 2014 00:25:01 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 01 Jan 2014 00:25:01 +0200
changeset 600
209e3f1f7b2c
parent 599
b77aecd27fb0
child 603
47e7773c7841
permissions
-rw-r--r--

- updated copyright year. Best wishes for 2014!

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()
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
50 { 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
51 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
53 Config::Config (str name) :
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
54 m_Name (name) {}
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
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 // Load the configuration from file
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 bool Config::load()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 { QSettings* settings = getSettingsObject();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 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
62
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 for (Config* cfg : g_configPointers)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 { if (!cfg)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 break;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
67 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
68 cfg->loadFromVariant (val);
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
69 g_configsByName[cfg->getName()] = cfg;
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
70 g_configs << cfg;
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 settings->deleteLater();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 return true;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // Save the configuration to disk
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 bool Config::save()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 { QSettings* settings = getSettingsObject();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 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
83
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
84 for (Config* cfg : g_configs)
599
b77aecd27fb0 - when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents: 590
diff changeset
85 { if (!cfg->isDefault())
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
86 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
87 else
b77aecd27fb0 - when configuration options are default, they need to be removed from the settings
Santeri Piippo <crimsondusk64@gmail.com>
parents: 590
diff changeset
88 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
89 }
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 settings->sync();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 settings->deleteLater();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 return true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
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 // =============================================================================
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
97 // Reset configuration to defaults.
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 void Config::reset()
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
100 { for (Config* cfg : g_configs)
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 cfg->resetValue();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 }
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 // =============================================================================
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
105 // 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
106 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 str Config::filepath (str file)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 { return Config::dirpath() + DIRSLASH + file;
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // =============================================================================
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
112 // Directory of the configuration file.
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 str Config::dirpath()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 { QSettings* cfg = getSettingsObject();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 return dirname (cfg->fileName());
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
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 // 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
121 // 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
122 // 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
123 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 void Config::addToArray (Config* ptr)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 { if (g_cfgPointerCursor == 0)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 memset (g_configPointers, 0, sizeof g_configPointers);
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 assert (g_cfgPointerCursor < MAX_CONFIG);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 g_configPointers[g_cfgPointerCursor++] = ptr;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 }
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
131
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
132 // =============================================================================
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
133 // -----------------------------------------------------------------------------
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
134 template<class T> T* getConfigByName (str name, Config::Type type)
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
135 { auto it = g_configsByName.find (name);
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
136
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
137 if (it == g_configsByName.end())
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
138 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
139
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
140 Config* cfg = it.value();
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
141
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
142 if (cfg->getType() != type)
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
143 { fprint (stderr, "type of %1 is %2, not %3\n", name, cfg->getType(), type);
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
144 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
145 }
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
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
147 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
148 }
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 // =============================================================================
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
151 // -----------------------------------------------------------------------------
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
152 #undef IMPLEMENT_CONFIG
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
153 #define IMPLEMENT_CONFIG(NAME) \
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
154 NAME##Config* NAME##Config::getByName (str name) \
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
155 { return getConfigByName<NAME##Config> (name, NAME); \
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
156 }
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
157
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
158 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
159 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
160 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
161 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
162 IMPLEMENT_CONFIG (List)
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 589
diff changeset
163 IMPLEMENT_CONFIG (KeySequence)

mercurial