author | unc0rr |
Wed, 29 May 2013 15:12:06 -0400 | |
changeset 9080 | 9b42757d7e71 |
parent 8920 | caa614af152d |
child 9389 | 3aae70f72126 |
permissions | -rw-r--r-- |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
1 |
/* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
9080 | 3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
4 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
8 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
13 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
17 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
18 |
|
6168 | 19 |
/** |
6170 | 20 |
* @file |
6930 | 21 |
* @brief DataManager class implementation |
6168 | 22 |
*/ |
23 |
||
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
24 |
#include <QMap> |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
25 |
#include <QStringList> |
7258 | 26 |
#include <QStandardItemModel> |
6199
582e85254110
on file save: create parent directories if needed
sheepluva
parents:
6196
diff
changeset
|
27 |
#include <QFileInfo> |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
28 |
#include <QSettings> |
8920 | 29 |
#include <QColor> |
6199
582e85254110
on file save: create parent directories if needed
sheepluva
parents:
6196
diff
changeset
|
30 |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
31 |
#include "hwconsts.h" |
7260 | 32 |
#include "HWApplication.h" |
33 |
#include "sdlkeys.h" |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
34 |
|
6930 | 35 |
#include "DataManager.h" |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
36 |
|
7258 | 37 |
#include "GameStyleModel.h" |
38 |
#include "HatModel.h" |
|
39 |
#include "MapModel.h" |
|
40 |
#include "ThemeModel.h" |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
41 |
|
6930 | 42 |
DataManager::DataManager() |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
43 |
{ |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
44 |
m_hatModel = NULL; |
8377 | 45 |
m_staticMapModel = NULL; |
46 |
m_missionMapModel = NULL; |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
47 |
m_themeModel = NULL; |
7258 | 48 |
m_colorsModel = NULL; |
7260 | 49 |
m_bindsModel = NULL; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
50 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
51 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
52 |
|
6930 | 53 |
DataManager & DataManager::instance() |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
54 |
{ |
6930 | 55 |
static DataManager instance; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
56 |
return instance; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
57 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
58 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
59 |
|
6930 | 60 |
QStringList DataManager::entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
61 |
const QString & subDirectory, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
62 |
QDir::Filters filters, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
63 |
const QStringList & nameFilters |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
64 |
) const |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
65 |
{ |
7774
27f9b9362f47
Simplify DataManager as physfs partially implements its functions
unc0rr
parents:
7681
diff
changeset
|
66 |
QDir tmpDir(QString("physfs://%1").arg(subDirectory)); |
27f9b9362f47
Simplify DataManager as physfs partially implements its functions
unc0rr
parents:
7681
diff
changeset
|
67 |
QStringList result = tmpDir.entryList(nameFilters, filters); |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
68 |
|
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
69 |
// sort case-insensitive |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
70 |
QMap<QString, QString> sortedFileNames; |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
71 |
foreach ( QString fn, result) |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
72 |
{ |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
73 |
sortedFileNames.insert(fn.toLower(), fn); |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
74 |
} |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
75 |
result = sortedFileNames.values(); |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
76 |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
77 |
return result; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
78 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
79 |
|
6958 | 80 |
GameStyleModel * DataManager::gameStyleModel() |
81 |
{ |
|
82 |
if (m_gameStyleModel == NULL) { |
|
83 |
m_gameStyleModel = new GameStyleModel(); |
|
84 |
m_gameStyleModel->loadGameStyles(); |
|
85 |
} |
|
86 |
return m_gameStyleModel; |
|
87 |
} |
|
88 |
||
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
89 |
HatModel * DataManager::hatModel() |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
90 |
{ |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
91 |
if (m_hatModel == NULL) { |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
92 |
m_hatModel = new HatModel(); |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
93 |
m_hatModel->loadHats(); |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
94 |
} |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
95 |
return m_hatModel; |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
96 |
} |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
97 |
|
8377 | 98 |
MapModel * DataManager::staticMapModel() |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
99 |
{ |
8377 | 100 |
if (m_staticMapModel == NULL) { |
101 |
m_staticMapModel = new MapModel(); |
|
102 |
m_staticMapModel->loadMaps(MapModel::StaticMap); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
103 |
} |
8377 | 104 |
return m_staticMapModel; |
105 |
} |
|
106 |
||
107 |
MapModel * DataManager::missionMapModel() |
|
108 |
{ |
|
109 |
if (m_missionMapModel == NULL) { |
|
110 |
m_missionMapModel = new MapModel(); |
|
111 |
m_missionMapModel->loadMaps(MapModel::MissionMap); |
|
112 |
} |
|
113 |
return m_missionMapModel; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
114 |
} |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
115 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
116 |
ThemeModel * DataManager::themeModel() |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
117 |
{ |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
118 |
if (m_themeModel == NULL) { |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
119 |
m_themeModel = new ThemeModel(); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
120 |
m_themeModel->loadThemes(); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
121 |
} |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
122 |
return m_themeModel; |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
123 |
} |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
124 |
|
7258 | 125 |
QStandardItemModel * DataManager::colorsModel() |
126 |
{ |
|
127 |
if(m_colorsModel == NULL) |
|
128 |
{ |
|
129 |
m_colorsModel = new QStandardItemModel(); |
|
130 |
||
131 |
int i = 0; |
|
132 |
while(colors[i]) |
|
133 |
{ |
|
134 |
QStandardItem * item = new QStandardItem(); |
|
135 |
item->setData(QColor(colors[i])); |
|
136 |
m_colorsModel->appendRow(item); |
|
137 |
++i; |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
return m_colorsModel; |
|
142 |
} |
|
143 |
||
7260 | 144 |
QStandardItemModel * DataManager::bindsModel() |
145 |
{ |
|
146 |
if(m_bindsModel == NULL) |
|
147 |
{ |
|
148 |
m_bindsModel = new QStandardItemModel(); |
|
149 |
||
8346 | 150 |
QStandardItem * firstItem = new QStandardItem(); |
151 |
firstItem->setData(tr("Use Default"), Qt::DisplayRole); |
|
152 |
firstItem->setData("default", Qt::UserRole + 1); |
|
153 |
m_bindsModel->appendRow(firstItem); |
|
154 |
||
7260 | 155 |
for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) |
156 |
{ |
|
157 |
QStandardItem * item = new QStandardItem(); |
|
158 |
item->setData(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), Qt::DisplayRole); |
|
159 |
item->setData(sdlkeys[j][0], Qt::UserRole + 1); |
|
160 |
m_bindsModel->appendRow(item); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
return m_bindsModel; |
|
165 |
} |
|
166 |
||
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
167 |
QString DataManager::settingsFileName() |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
168 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
169 |
if(m_settingsFileName.isEmpty()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
170 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
171 |
QFile settingsFile("physfs://settings.ini"); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
172 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
173 |
if(!settingsFile.exists()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
174 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
175 |
QFile oldSettingsFile("physfs://hedgewars.ini"); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
176 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
177 |
settingsFile.open(QFile::WriteOnly); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
178 |
settingsFile.close(); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
179 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
180 |
if(oldSettingsFile.exists()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
181 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
182 |
QSettings sOld(oldSettingsFile.fileName(), QSettings::IniFormat); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
183 |
QSettings sNew(settingsFile.fileName(), QSettings::IniFormat); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
184 |
sNew.setIniCodec("UTF-8"); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
185 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
186 |
foreach(const QString & key, sOld.allKeys()) |
8920 | 187 |
{ |
188 |
if(key.startsWith("colors/color")) |
|
189 |
sNew.setValue(key, sOld.value(key).value<QColor>().name()); |
|
190 |
else |
|
191 |
sNew.setValue(key, sOld.value(key)); |
|
192 |
} |
|
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
193 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
194 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
195 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
196 |
m_settingsFileName = settingsFile.fileName(); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
197 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
198 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
199 |
return m_settingsFileName; |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
200 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
201 |
|
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
202 |
void DataManager::reload() |
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
203 |
{ |
7824 | 204 |
// removed for now (also code was a bit unclean, could lead to segfault if |
205 |
// reload() is called before all members are initialized - because currently |
|
206 |
// they are initialized in the getter methods rather than the constructor) |
|
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
207 |
} |
7681 | 208 |
|
209 |
void DataManager::resetColors() |
|
210 |
{ |
|
211 |
for(int i = colorsModel()->rowCount() - 1; i >= 0; --i) |
|
212 |
{ |
|
213 |
m_colorsModel->item(i)->setData(QColor(colors[i])); |
|
214 |
} |
|
215 |
} |
|
8508
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
216 |
|
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
217 |
bool DataManager::ensureFileExists(const QString &fileName) |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
218 |
{ |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
219 |
QFile tmpfile(fileName); |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
220 |
if (!tmpfile.exists()) |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
221 |
return tmpfile.open(QFile::WriteOnly); |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
222 |
else |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
223 |
return true; |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
224 |
} |