author | nemo |
Sun, 28 Feb 2010 15:41:42 +0000 | |
changeset 2881 | 70d7976fa829 |
parent 2762 | 2fbc8d35eb52 |
child 2882 | b9aceb3fe3d6 |
permissions | -rw-r--r-- |
1881 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
1885 | 19 |
#include <QDebug> |
1881 | 20 |
#include <QModelIndex> |
1897 | 21 |
|
1881 | 22 |
#include "ammoSchemeModel.h" |
1897 | 23 |
#include "hwconsts.h" |
1881 | 24 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
25 |
QList<QVariant> defaultScheme = QList<QVariant>() |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
26 |
<< QVariant("Default") // name 0 |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
27 |
<< QVariant(false) // fortsmode 1 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
28 |
<< QVariant(false) // team divide 2 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
29 |
<< QVariant(false) // solid land 3 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
30 |
<< QVariant(false) // border 4 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
31 |
<< QVariant(false) // low gravity 5 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
32 |
<< QVariant(false) // laser sight 6 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
33 |
<< QVariant(false) // invulnerable 7 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
34 |
<< QVariant(true) // add mines 8 |
2017 | 35 |
<< QVariant(false) // vampiric 9 |
36 |
<< QVariant(false) // karma 10 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
37 |
<< QVariant(false) // artillery 11 |
2703 | 38 |
<< QVariant(true) // random order 12 |
2726 | 39 |
<< QVariant(false) // king 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
40 |
<< QVariant(false) // place hog 14 |
2881 | 41 |
<< QVariant(false) // shared ammo 15 |
42 |
<< QVariant(100) // damage modfier 16 |
|
43 |
<< QVariant(45) // turn time 17 |
|
44 |
<< QVariant(100) // init health 18 |
|
45 |
<< QVariant(15) // sudden death 19 |
|
46 |
<< QVariant(5) // case prob 20 |
|
47 |
<< QVariant(3) // mines time 21 |
|
48 |
<< QVariant(4) // landadds 22 |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
49 |
; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
50 |
|
1897 | 51 |
AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : |
52 |
QAbstractTableModel(parent), |
|
1974 | 53 |
numberOfDefaultSchemes(4), |
1940 | 54 |
fileConfig(fileName, QSettings::IniFormat) |
1881 | 55 |
{ |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
56 |
QStringList predefSchemesNames; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
57 |
predefSchemesNames |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
58 |
<< "Default" |
1968 | 59 |
<< "Pro mode" |
1974 | 60 |
<< "Shoppa" |
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
61 |
<< "Basketball" |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
62 |
<< "Minefield"; |
2377 | 63 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
64 |
spNames = QStringList() |
1897 | 65 |
<< "name" // 0 |
66 |
<< "fortsmode" // 1 |
|
67 |
<< "divteams" // 2 |
|
68 |
<< "solidland" // 3 |
|
69 |
<< "border" // 4 |
|
70 |
<< "lowgrav" // 5 |
|
71 |
<< "laser" // 6 |
|
72 |
<< "invulnerability" // 7 |
|
73 |
<< "mines" // 8 |
|
2017 | 74 |
<< "vampiric" // 9 |
75 |
<< "karma" // 10 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
76 |
<< "artillery" // 11 |
2703 | 77 |
<< "randomorder" // 12 |
2726 | 78 |
<< "king" // 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
79 |
<< "placehog" // 14 |
2881 | 80 |
<< "sharedammo" // 15 |
81 |
<< "damagefactor" // 16 |
|
82 |
<< "turntime" // 17 |
|
83 |
<< "health" // 18 |
|
84 |
<< "suddendeath" // 19 |
|
85 |
<< "caseprobability" // 20 |
|
86 |
<< "minestime" // 21 |
|
87 |
<< "landadds" // 22 |
|
1897 | 88 |
; |
89 |
||
90 |
QList<QVariant> proMode; |
|
91 |
proMode |
|
1968 | 92 |
<< predefSchemesNames[1] // name 0 |
1897 | 93 |
<< QVariant(false) // fortsmode 1 |
94 |
<< QVariant(false) // team divide 2 |
|
95 |
<< QVariant(false) // solid land 3 |
|
96 |
<< QVariant(false) // border 4 |
|
97 |
<< QVariant(false) // low gravity 5 |
|
98 |
<< QVariant(false) // laser sight 6 |
|
99 |
<< QVariant(false) // invulnerable 7 |
|
100 |
<< QVariant(false) // add mines 8 |
|
2017 | 101 |
<< QVariant(false) // vampiric 9 |
102 |
<< QVariant(false) // karma 10 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
103 |
<< QVariant(false) // artillery 11 |
2703 | 104 |
<< QVariant(true) // random order 12 |
2726 | 105 |
<< QVariant(false) // king 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
106 |
<< QVariant(false) // place hog 14 |
2881 | 107 |
<< QVariant(true) // shared ammo 15 |
108 |
<< QVariant(100) // damage modfier 16 |
|
109 |
<< QVariant(15) // turn time 17 |
|
110 |
<< QVariant(100) // init health 18 |
|
111 |
<< QVariant(15) // sudden death 19 |
|
112 |
<< QVariant(0) // case prob 20 |
|
113 |
<< QVariant(3) // mines time 21 |
|
114 |
<< QVariant(4) // landadds 22 |
|
1897 | 115 |
; |
116 |
||
1968 | 117 |
QList<QVariant> shoppa; |
118 |
shoppa |
|
119 |
<< predefSchemesNames[2] // name 0 |
|
120 |
<< QVariant(false) // fortsmode 1 |
|
121 |
<< QVariant(false) // team divide 2 |
|
122 |
<< QVariant(true) // solid land 3 |
|
123 |
<< QVariant(true) // border 4 |
|
124 |
<< QVariant(false) // low gravity 5 |
|
125 |
<< QVariant(false) // laser sight 6 |
|
126 |
<< QVariant(false) // invulnerable 7 |
|
127 |
<< QVariant(false) // add mines 8 |
|
2017 | 128 |
<< QVariant(false) // vampiric 9 |
129 |
<< QVariant(false) // karma 10 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
130 |
<< QVariant(false) // artillery 11 |
2703 | 131 |
<< QVariant(true) // random order 12 |
2726 | 132 |
<< QVariant(false) // king 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
133 |
<< QVariant(false) // place hog 14 |
2881 | 134 |
<< QVariant(true) // shared ammo 15 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
135 |
<< QVariant(100) // damage modfier 15 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
136 |
<< QVariant(30) // turn time 16 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
137 |
<< QVariant(100) // init health 17 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
138 |
<< QVariant(50) // sudden death 18 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
139 |
<< QVariant(1) // case prob 19 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
140 |
<< QVariant(3) // mines time 20 |
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
141 |
<< QVariant(4) // landadds 21 |
1974 | 142 |
; |
143 |
||
144 |
QList<QVariant> basketball; |
|
145 |
basketball |
|
146 |
<< predefSchemesNames[3] // name 0 |
|
147 |
<< QVariant(false) // fortsmode 1 |
|
148 |
<< QVariant(false) // team divide 2 |
|
149 |
<< QVariant(true) // solid land 3 |
|
150 |
<< QVariant(true) // border 4 |
|
151 |
<< QVariant(true) // low gravity 5 |
|
152 |
<< QVariant(false) // laser sight 6 |
|
153 |
<< QVariant(true) // invulnerable 7 |
|
154 |
<< QVariant(false) // add mines 8 |
|
2017 | 155 |
<< QVariant(false) // vampiric 9 |
156 |
<< QVariant(false) // karma 10 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
157 |
<< QVariant(false) // artillery 11 |
2703 | 158 |
<< QVariant(true) // random order 12 |
2726 | 159 |
<< QVariant(false) // king 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
160 |
<< QVariant(false) // place hog 14 |
2881 | 161 |
<< QVariant(true) // shared ammo 15 |
162 |
<< QVariant(100) // damage modfier 16 |
|
163 |
<< QVariant(30) // turn time 17 |
|
164 |
<< QVariant(100) // init health 18 |
|
165 |
<< QVariant(15) // sudden death 19 |
|
166 |
<< QVariant(0) // case prob 20 |
|
167 |
<< QVariant(3) // mines time 21 |
|
168 |
<< QVariant(4) // landadds 22 |
|
1968 | 169 |
; |
170 |
||
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
171 |
QList<QVariant> minefield; |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
172 |
minefield |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
173 |
<< predefSchemesNames[4] // name 0 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
174 |
<< QVariant(false) // fortsmode 1 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
175 |
<< QVariant(false) // team divide 2 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
176 |
<< QVariant(false) // solid land 3 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
177 |
<< QVariant(false) // border 4 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
178 |
<< QVariant(false) // low gravity 5 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
179 |
<< QVariant(false) // laser sight 6 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
180 |
<< QVariant(false) // invulnerable 7 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
181 |
<< QVariant(true) // add mines 8 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
182 |
<< QVariant(false) // vampiric 9 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
183 |
<< QVariant(false) // karma 10 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
184 |
<< QVariant(false) // artillery 11 |
2703 | 185 |
<< QVariant(true) // random order 12 |
2726 | 186 |
<< QVariant(false) // king 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
187 |
<< QVariant(false) // place hog 14 |
2881 | 188 |
<< QVariant(true) // shared ammo 15 |
189 |
<< QVariant(150) // damage modfier 16 |
|
190 |
<< QVariant(30) // turn time 17 |
|
191 |
<< QVariant(50) // init health 18 |
|
192 |
<< QVariant(15) // sudden death 19 |
|
193 |
<< QVariant(0) // case prob 20 |
|
194 |
<< QVariant(0) // mines time 21 |
|
195 |
<< QVariant(50) // landadds 22 |
|
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
196 |
; |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
197 |
|
1884 | 198 |
schemes.append(defaultScheme); |
1897 | 199 |
schemes.append(proMode); |
1968 | 200 |
schemes.append(shoppa); |
1974 | 201 |
schemes.append(basketball); |
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
202 |
schemes.append(minefield); |
1897 | 203 |
|
204 |
||
205 |
int size = fileConfig.beginReadArray("schemes"); |
|
206 |
for (int i = 0; i < size; ++i) { |
|
207 |
fileConfig.setArrayIndex(i); |
|
208 |
||
209 |
if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) |
|
210 |
{ |
|
211 |
QList<QVariant> scheme; |
|
212 |
||
213 |
for (int k = 0; k < spNames.size(); ++k) |
|
214 |
scheme << fileConfig.value(spNames[k], defaultScheme[k]); |
|
215 |
||
216 |
schemes.append(scheme); |
|
217 |
} |
|
218 |
} |
|
219 |
fileConfig.endArray(); |
|
1881 | 220 |
} |
221 |
||
222 |
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
223 |
{ |
|
224 |
return QVariant(); |
|
225 |
} |
|
226 |
||
227 |
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const |
|
228 |
{ |
|
229 |
if (parent.isValid()) |
|
230 |
return 0; |
|
231 |
else |
|
232 |
return schemes.size(); |
|
233 |
} |
|
234 |
||
235 |
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const |
|
236 |
{ |
|
237 |
if (parent.isValid()) |
|
238 |
return 0; |
|
239 |
else |
|
1884 | 240 |
return defaultScheme.size(); |
1881 | 241 |
} |
242 |
||
243 |
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const |
|
244 |
{ |
|
245 |
return |
|
246 |
Qt::ItemIsEnabled |
|
247 |
| Qt::ItemIsSelectable |
|
248 |
| Qt::ItemIsEditable; |
|
249 |
} |
|
250 |
||
251 |
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) |
|
252 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
253 |
if (!index.isValid() || index.row() < numberOfDefaultSchemes |
1884 | 254 |
|| index.row() >= schemes.size() |
255 |
|| index.column() >= defaultScheme.size() |
|
1885 | 256 |
|| role != Qt::EditRole) |
1884 | 257 |
return false; |
258 |
||
1890 | 259 |
schemes[index.row()][index.column()] = value; |
1885 | 260 |
|
1881 | 261 |
emit dataChanged(index, index); |
1884 | 262 |
return true; |
1881 | 263 |
} |
1884 | 264 |
|
265 |
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent) |
|
266 |
{ |
|
267 |
beginInsertRows(parent, row, row); |
|
268 |
||
1890 | 269 |
QList<QVariant> newScheme = defaultScheme; |
270 |
newScheme[0] = QVariant(tr("new")); |
|
2377 | 271 |
|
1889 | 272 |
schemes.insert(row, newScheme); |
1884 | 273 |
|
274 |
endInsertRows(); |
|
2377 | 275 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
276 |
return true; |
1884 | 277 |
} |
278 |
||
279 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) |
|
280 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
281 |
if(count != 1 |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
282 |
|| row < numberOfDefaultSchemes |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
283 |
|| row >= schemes.size()) |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
284 |
return false; |
2377 | 285 |
|
1884 | 286 |
beginRemoveRows(parent, row, row); |
287 |
||
288 |
schemes.removeAt(row); |
|
289 |
||
290 |
endRemoveRows(); |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
291 |
|
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
292 |
return true; |
1884 | 293 |
} |
294 |
||
295 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const |
|
296 |
{ |
|
297 |
if (!index.isValid() || index.row() < 0 |
|
298 |
|| index.row() >= schemes.size() |
|
299 |
|| index.column() >= defaultScheme.size() |
|
1889 | 300 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
301 |
) |
|
1884 | 302 |
return QVariant(); |
303 |
||
1890 | 304 |
return schemes[index.row()][index.column()]; |
1884 | 305 |
} |
1897 | 306 |
|
307 |
void AmmoSchemeModel::Save() |
|
308 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
309 |
fileConfig.beginWriteArray("schemes", schemes.size()); |
2377 | 310 |
|
1897 | 311 |
for (int i = 0; i < schemes.size(); ++i) { |
312 |
fileConfig.setArrayIndex(i); |
|
313 |
||
314 |
QList<QVariant> scheme = schemes[i]; |
|
2377 | 315 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
316 |
for (int k = 0; k < scheme.size(); ++k) |
1897 | 317 |
fileConfig.setValue(spNames[k], scheme[k]); |
318 |
} |
|
319 |
fileConfig.endArray(); |
|
320 |
} |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
321 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
322 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
323 |
NetAmmoSchemeModel::NetAmmoSchemeModel(QObject * parent) : |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
324 |
QAbstractTableModel(parent) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
325 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
326 |
netScheme = defaultScheme; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
327 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
328 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
329 |
QVariant NetAmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
330 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
331 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
332 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
333 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
334 |
int NetAmmoSchemeModel::rowCount(const QModelIndex & parent) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
335 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
336 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
337 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
338 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
339 |
return 1; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
340 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
341 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
342 |
int NetAmmoSchemeModel::columnCount(const QModelIndex & parent) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
343 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
344 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
345 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
346 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
347 |
return defaultScheme.size(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
348 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
349 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
350 |
QVariant NetAmmoSchemeModel::data(const QModelIndex &index, int role) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
351 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
352 |
if (!index.isValid() || index.row() < 0 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
353 |
|| index.row() > 1 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
354 |
|| index.column() >= defaultScheme.size() |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
355 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
356 |
) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
357 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
358 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
359 |
return netScheme[index.column()]; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
360 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
361 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
362 |
void NetAmmoSchemeModel::setNetSchemeConfig(QStringList & cfg) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
363 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
364 |
if(cfg.size() != netScheme.size()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
365 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
366 |
qWarning("Incorrect scheme cfg size"); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
367 |
return; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
368 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
369 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
370 |
for(int i = 0; i < cfg.size(); ++i) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
371 |
netScheme[i] = QVariant(cfg[i]); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
372 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
373 |
reset(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
374 |
} |