author | nemo |
Sun, 28 Feb 2010 17:32:39 +0000 | |
changeset 2885 | 518e6e66239d |
parent 2882 | b9aceb3fe3d6 |
child 2891 | e1f902eb0cfe |
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 |
|
2882 | 49 |
<< QVariant(0) // mine dud pct 23 |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
50 |
; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
51 |
|
1897 | 52 |
AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : |
53 |
QAbstractTableModel(parent), |
|
1974 | 54 |
numberOfDefaultSchemes(4), |
1940 | 55 |
fileConfig(fileName, QSettings::IniFormat) |
1881 | 56 |
{ |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
57 |
QStringList predefSchemesNames; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
58 |
predefSchemesNames |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
59 |
<< "Default" |
1968 | 60 |
<< "Pro mode" |
1974 | 61 |
<< "Shoppa" |
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
62 |
<< "Basketball" |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
63 |
<< "Minefield"; |
2377 | 64 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
65 |
spNames = QStringList() |
1897 | 66 |
<< "name" // 0 |
67 |
<< "fortsmode" // 1 |
|
68 |
<< "divteams" // 2 |
|
69 |
<< "solidland" // 3 |
|
70 |
<< "border" // 4 |
|
71 |
<< "lowgrav" // 5 |
|
72 |
<< "laser" // 6 |
|
73 |
<< "invulnerability" // 7 |
|
74 |
<< "mines" // 8 |
|
2017 | 75 |
<< "vampiric" // 9 |
76 |
<< "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
|
77 |
<< "artillery" // 11 |
2703 | 78 |
<< "randomorder" // 12 |
2726 | 79 |
<< "king" // 13 |
2762
2fbc8d35eb52
Mode to place hogs at start of game. Will probably need a bit more testing.
nemo
parents:
2726
diff
changeset
|
80 |
<< "placehog" // 14 |
2881 | 81 |
<< "sharedammo" // 15 |
82 |
<< "damagefactor" // 16 |
|
83 |
<< "turntime" // 17 |
|
84 |
<< "health" // 18 |
|
85 |
<< "suddendeath" // 19 |
|
86 |
<< "caseprobability" // 20 |
|
87 |
<< "minestime" // 21 |
|
88 |
<< "landadds" // 22 |
|
2882 | 89 |
<< "minedudpct" // 23 |
1897 | 90 |
; |
91 |
||
92 |
QList<QVariant> proMode; |
|
93 |
proMode |
|
1968 | 94 |
<< predefSchemesNames[1] // name 0 |
1897 | 95 |
<< QVariant(false) // fortsmode 1 |
96 |
<< QVariant(false) // team divide 2 |
|
97 |
<< QVariant(false) // solid land 3 |
|
98 |
<< QVariant(false) // border 4 |
|
99 |
<< QVariant(false) // low gravity 5 |
|
100 |
<< QVariant(false) // laser sight 6 |
|
101 |
<< QVariant(false) // invulnerable 7 |
|
102 |
<< QVariant(false) // add mines 8 |
|
2017 | 103 |
<< QVariant(false) // vampiric 9 |
104 |
<< 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
|
105 |
<< QVariant(false) // artillery 11 |
2703 | 106 |
<< QVariant(true) // random order 12 |
2726 | 107 |
<< 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
|
108 |
<< QVariant(false) // place hog 14 |
2881 | 109 |
<< QVariant(true) // shared ammo 15 |
110 |
<< QVariant(100) // damage modfier 16 |
|
111 |
<< QVariant(15) // turn time 17 |
|
112 |
<< QVariant(100) // init health 18 |
|
113 |
<< QVariant(15) // sudden death 19 |
|
114 |
<< QVariant(0) // case prob 20 |
|
115 |
<< QVariant(3) // mines time 21 |
|
116 |
<< QVariant(4) // landadds 22 |
|
2882 | 117 |
<< QVariant(0) // mine dud pct 23 |
1897 | 118 |
; |
119 |
||
1968 | 120 |
QList<QVariant> shoppa; |
121 |
shoppa |
|
122 |
<< predefSchemesNames[2] // name 0 |
|
123 |
<< QVariant(false) // fortsmode 1 |
|
124 |
<< QVariant(false) // team divide 2 |
|
125 |
<< QVariant(true) // solid land 3 |
|
126 |
<< QVariant(true) // border 4 |
|
127 |
<< QVariant(false) // low gravity 5 |
|
128 |
<< QVariant(false) // laser sight 6 |
|
129 |
<< QVariant(false) // invulnerable 7 |
|
130 |
<< QVariant(false) // add mines 8 |
|
2017 | 131 |
<< QVariant(false) // vampiric 9 |
132 |
<< 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
|
133 |
<< QVariant(false) // artillery 11 |
2703 | 134 |
<< QVariant(true) // random order 12 |
2726 | 135 |
<< 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
|
136 |
<< QVariant(false) // place hog 14 |
2881 | 137 |
<< QVariant(true) // shared ammo 15 |
2882 | 138 |
<< QVariant(100) // damage modfier 16 |
139 |
<< QVariant(30) // turn time 17 |
|
140 |
<< QVariant(100) // init health 18 |
|
141 |
<< QVariant(50) // sudden death 19 |
|
142 |
<< QVariant(1) // case prob 20 |
|
143 |
<< QVariant(3) // mines time 21 |
|
144 |
<< QVariant(4) // landadds 22 |
|
145 |
<< QVariant(0) // mine dud pct 23 |
|
1974 | 146 |
; |
147 |
||
148 |
QList<QVariant> basketball; |
|
149 |
basketball |
|
150 |
<< predefSchemesNames[3] // name 0 |
|
151 |
<< QVariant(false) // fortsmode 1 |
|
152 |
<< QVariant(false) // team divide 2 |
|
153 |
<< QVariant(true) // solid land 3 |
|
154 |
<< QVariant(true) // border 4 |
|
155 |
<< QVariant(true) // low gravity 5 |
|
156 |
<< QVariant(false) // laser sight 6 |
|
157 |
<< QVariant(true) // invulnerable 7 |
|
158 |
<< QVariant(false) // add mines 8 |
|
2017 | 159 |
<< QVariant(false) // vampiric 9 |
160 |
<< 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
|
161 |
<< QVariant(false) // artillery 11 |
2703 | 162 |
<< QVariant(true) // random order 12 |
2726 | 163 |
<< 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
|
164 |
<< QVariant(false) // place hog 14 |
2881 | 165 |
<< QVariant(true) // shared ammo 15 |
166 |
<< QVariant(100) // damage modfier 16 |
|
167 |
<< QVariant(30) // turn time 17 |
|
168 |
<< QVariant(100) // init health 18 |
|
169 |
<< QVariant(15) // sudden death 19 |
|
170 |
<< QVariant(0) // case prob 20 |
|
171 |
<< QVariant(3) // mines time 21 |
|
172 |
<< QVariant(4) // landadds 22 |
|
2882 | 173 |
<< QVariant(0) // mine dud pct 23 |
1968 | 174 |
; |
175 |
||
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
176 |
QList<QVariant> minefield; |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
177 |
minefield |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
178 |
<< predefSchemesNames[4] // name 0 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
179 |
<< QVariant(false) // fortsmode 1 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
180 |
<< QVariant(false) // team divide 2 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
181 |
<< QVariant(false) // solid land 3 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
182 |
<< QVariant(false) // border 4 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
183 |
<< QVariant(false) // low gravity 5 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
184 |
<< QVariant(false) // laser sight 6 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
185 |
<< QVariant(false) // invulnerable 7 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
186 |
<< QVariant(true) // add mines 8 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
187 |
<< QVariant(false) // vampiric 9 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
188 |
<< QVariant(false) // karma 10 |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
189 |
<< QVariant(false) // artillery 11 |
2703 | 190 |
<< QVariant(true) // random order 12 |
2726 | 191 |
<< 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
|
192 |
<< QVariant(false) // place hog 14 |
2881 | 193 |
<< QVariant(true) // shared ammo 15 |
194 |
<< QVariant(150) // damage modfier 16 |
|
195 |
<< QVariant(30) // turn time 17 |
|
196 |
<< QVariant(50) // init health 18 |
|
197 |
<< QVariant(15) // sudden death 19 |
|
198 |
<< QVariant(0) // case prob 20 |
|
199 |
<< QVariant(0) // mines time 21 |
|
200 |
<< QVariant(50) // landadds 22 |
|
2882 | 201 |
<< QVariant(0) // mine dud pct 23 |
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
202 |
; |
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
203 |
|
1884 | 204 |
schemes.append(defaultScheme); |
1897 | 205 |
schemes.append(proMode); |
1968 | 206 |
schemes.append(shoppa); |
1974 | 207 |
schemes.append(basketball); |
2093
485e084cedc4
Portugese (european) translation, Tiy's "minefield" scheme/wepset, disable vampirism, update translations
nemo
parents:
2031
diff
changeset
|
208 |
schemes.append(minefield); |
1897 | 209 |
|
210 |
||
211 |
int size = fileConfig.beginReadArray("schemes"); |
|
212 |
for (int i = 0; i < size; ++i) { |
|
213 |
fileConfig.setArrayIndex(i); |
|
214 |
||
215 |
if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) |
|
216 |
{ |
|
217 |
QList<QVariant> scheme; |
|
218 |
||
219 |
for (int k = 0; k < spNames.size(); ++k) |
|
220 |
scheme << fileConfig.value(spNames[k], defaultScheme[k]); |
|
221 |
||
222 |
schemes.append(scheme); |
|
223 |
} |
|
224 |
} |
|
225 |
fileConfig.endArray(); |
|
1881 | 226 |
} |
227 |
||
228 |
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
229 |
{ |
|
230 |
return QVariant(); |
|
231 |
} |
|
232 |
||
233 |
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const |
|
234 |
{ |
|
235 |
if (parent.isValid()) |
|
236 |
return 0; |
|
237 |
else |
|
238 |
return schemes.size(); |
|
239 |
} |
|
240 |
||
241 |
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const |
|
242 |
{ |
|
243 |
if (parent.isValid()) |
|
244 |
return 0; |
|
245 |
else |
|
1884 | 246 |
return defaultScheme.size(); |
1881 | 247 |
} |
248 |
||
249 |
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const |
|
250 |
{ |
|
251 |
return |
|
252 |
Qt::ItemIsEnabled |
|
253 |
| Qt::ItemIsSelectable |
|
254 |
| Qt::ItemIsEditable; |
|
255 |
} |
|
256 |
||
257 |
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) |
|
258 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
259 |
if (!index.isValid() || index.row() < numberOfDefaultSchemes |
1884 | 260 |
|| index.row() >= schemes.size() |
261 |
|| index.column() >= defaultScheme.size() |
|
1885 | 262 |
|| role != Qt::EditRole) |
1884 | 263 |
return false; |
264 |
||
1890 | 265 |
schemes[index.row()][index.column()] = value; |
1885 | 266 |
|
1881 | 267 |
emit dataChanged(index, index); |
1884 | 268 |
return true; |
1881 | 269 |
} |
1884 | 270 |
|
271 |
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent) |
|
272 |
{ |
|
273 |
beginInsertRows(parent, row, row); |
|
274 |
||
1890 | 275 |
QList<QVariant> newScheme = defaultScheme; |
276 |
newScheme[0] = QVariant(tr("new")); |
|
2377 | 277 |
|
1889 | 278 |
schemes.insert(row, newScheme); |
1884 | 279 |
|
280 |
endInsertRows(); |
|
2377 | 281 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
282 |
return true; |
1884 | 283 |
} |
284 |
||
285 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) |
|
286 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
287 |
if(count != 1 |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
288 |
|| row < numberOfDefaultSchemes |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
289 |
|| row >= schemes.size()) |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
290 |
return false; |
2377 | 291 |
|
1884 | 292 |
beginRemoveRows(parent, row, row); |
293 |
||
294 |
schemes.removeAt(row); |
|
295 |
||
296 |
endRemoveRows(); |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
297 |
|
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
298 |
return true; |
1884 | 299 |
} |
300 |
||
301 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const |
|
302 |
{ |
|
303 |
if (!index.isValid() || index.row() < 0 |
|
304 |
|| index.row() >= schemes.size() |
|
305 |
|| index.column() >= defaultScheme.size() |
|
1889 | 306 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
307 |
) |
|
1884 | 308 |
return QVariant(); |
309 |
||
1890 | 310 |
return schemes[index.row()][index.column()]; |
1884 | 311 |
} |
1897 | 312 |
|
313 |
void AmmoSchemeModel::Save() |
|
314 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
315 |
fileConfig.beginWriteArray("schemes", schemes.size()); |
2377 | 316 |
|
1897 | 317 |
for (int i = 0; i < schemes.size(); ++i) { |
318 |
fileConfig.setArrayIndex(i); |
|
319 |
||
320 |
QList<QVariant> scheme = schemes[i]; |
|
2377 | 321 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
322 |
for (int k = 0; k < scheme.size(); ++k) |
1897 | 323 |
fileConfig.setValue(spNames[k], scheme[k]); |
324 |
} |
|
325 |
fileConfig.endArray(); |
|
326 |
} |
|
1899
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 |
NetAmmoSchemeModel::NetAmmoSchemeModel(QObject * parent) : |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
330 |
QAbstractTableModel(parent) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
331 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
332 |
netScheme = defaultScheme; |
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 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
335 |
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
|
336 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
337 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
338 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
339 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
340 |
int NetAmmoSchemeModel::rowCount(const QModelIndex & parent) const |
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 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
343 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
344 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
345 |
return 1; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
346 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
347 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
348 |
int NetAmmoSchemeModel::columnCount(const QModelIndex & parent) const |
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 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
351 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
352 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
353 |
return defaultScheme.size(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
354 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
355 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
356 |
QVariant NetAmmoSchemeModel::data(const QModelIndex &index, int role) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
357 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
358 |
if (!index.isValid() || index.row() < 0 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
359 |
|| index.row() > 1 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
360 |
|| index.column() >= defaultScheme.size() |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
361 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
362 |
) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
363 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
364 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
365 |
return netScheme[index.column()]; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
366 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
367 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
368 |
void NetAmmoSchemeModel::setNetSchemeConfig(QStringList & cfg) |
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 |
if(cfg.size() != netScheme.size()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
371 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
372 |
qWarning("Incorrect scheme cfg size"); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
373 |
return; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
374 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
375 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
376 |
for(int i = 0; i < cfg.size(); ++i) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
377 |
netScheme[i] = QVariant(cfg[i]); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
378 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
379 |
reset(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
380 |
} |