author | nemo |
Tue, 19 May 2009 21:01:52 +0000 | |
changeset 2077 | 7320931f12a0 |
parent 2031 | b6f3e56fb100 |
child 2093 | 485e084cedc4 |
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 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
38 |
<< QVariant(100) // damage modfier 12 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
39 |
<< QVariant(45) // turn time 13 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
40 |
<< QVariant(100) // init health 14 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
41 |
<< QVariant(15) // sudden death 15 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
42 |
<< QVariant(5) // case prob 16 |
2031
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
43 |
<< QVariant(3) // mines time 17 |
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
44 |
<< QVariant(4) // landadds 18 |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
45 |
; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
46 |
|
1897 | 47 |
AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : |
48 |
QAbstractTableModel(parent), |
|
1974 | 49 |
numberOfDefaultSchemes(4), |
1940 | 50 |
fileConfig(fileName, QSettings::IniFormat) |
1881 | 51 |
{ |
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
52 |
QStringList predefSchemesNames; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
53 |
predefSchemesNames |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
54 |
<< "Default" |
1968 | 55 |
<< "Pro mode" |
1974 | 56 |
<< "Shoppa" |
57 |
<< "Basketball"; |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
58 |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
59 |
spNames = QStringList() |
1897 | 60 |
<< "name" // 0 |
61 |
<< "fortsmode" // 1 |
|
62 |
<< "divteams" // 2 |
|
63 |
<< "solidland" // 3 |
|
64 |
<< "border" // 4 |
|
65 |
<< "lowgrav" // 5 |
|
66 |
<< "laser" // 6 |
|
67 |
<< "invulnerability" // 7 |
|
68 |
<< "mines" // 8 |
|
2017 | 69 |
<< "vampiric" // 9 |
70 |
<< "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
|
71 |
<< "artillery" // 11 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
72 |
<< "damagefactor" // 12 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
73 |
<< "turntime" // 13 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
74 |
<< "health" // 14 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
75 |
<< "suddendeath" // 15 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
76 |
<< "caseprobability" // 16 |
2031
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
77 |
<< "minestime" // 17 |
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
78 |
<< "landadds" // 18 |
1897 | 79 |
; |
80 |
||
81 |
QList<QVariant> proMode; |
|
82 |
proMode |
|
1968 | 83 |
<< predefSchemesNames[1] // name 0 |
1897 | 84 |
<< QVariant(false) // fortsmode 1 |
85 |
<< QVariant(false) // team divide 2 |
|
86 |
<< QVariant(false) // solid land 3 |
|
87 |
<< QVariant(false) // border 4 |
|
88 |
<< QVariant(false) // low gravity 5 |
|
89 |
<< QVariant(false) // laser sight 6 |
|
90 |
<< QVariant(false) // invulnerable 7 |
|
91 |
<< QVariant(false) // add mines 8 |
|
2017 | 92 |
<< QVariant(false) // vampiric 9 |
93 |
<< 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
|
94 |
<< QVariant(false) // artillery 11 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
95 |
<< QVariant(100) // damage modfier 12 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
96 |
<< QVariant(15) // turn time 13 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
97 |
<< QVariant(100) // init health 14 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
98 |
<< QVariant(15) // sudden death 15 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
99 |
<< QVariant(0) // case prob 16 |
2031
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
100 |
<< QVariant(3) // mines time 17 |
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
101 |
<< QVariant(4) // landadds 18 |
1897 | 102 |
; |
103 |
||
1968 | 104 |
QList<QVariant> shoppa; |
105 |
shoppa |
|
106 |
<< predefSchemesNames[2] // name 0 |
|
107 |
<< QVariant(false) // fortsmode 1 |
|
108 |
<< QVariant(false) // team divide 2 |
|
109 |
<< QVariant(true) // solid land 3 |
|
110 |
<< QVariant(true) // border 4 |
|
111 |
<< QVariant(false) // low gravity 5 |
|
112 |
<< QVariant(false) // laser sight 6 |
|
113 |
<< QVariant(false) // invulnerable 7 |
|
114 |
<< QVariant(false) // add mines 8 |
|
2017 | 115 |
<< QVariant(false) // vampiric 9 |
116 |
<< 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
|
117 |
<< QVariant(false) // artillery 11 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
118 |
<< QVariant(100) // damage modfier 12 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
119 |
<< QVariant(30) // turn time 13 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
120 |
<< QVariant(100) // init health 14 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
121 |
<< QVariant(50) // sudden death 15 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
122 |
<< QVariant(1) // case prob 16 |
2031
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
123 |
<< QVariant(3) // mines time 17 |
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
124 |
<< QVariant(4) // landadds 18 |
1974 | 125 |
; |
126 |
||
127 |
QList<QVariant> basketball; |
|
128 |
basketball |
|
129 |
<< predefSchemesNames[3] // name 0 |
|
130 |
<< QVariant(false) // fortsmode 1 |
|
131 |
<< QVariant(false) // team divide 2 |
|
132 |
<< QVariant(true) // solid land 3 |
|
133 |
<< QVariant(true) // border 4 |
|
134 |
<< QVariant(true) // low gravity 5 |
|
135 |
<< QVariant(false) // laser sight 6 |
|
136 |
<< QVariant(true) // invulnerable 7 |
|
137 |
<< QVariant(false) // add mines 8 |
|
2017 | 138 |
<< QVariant(false) // vampiric 9 |
139 |
<< 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
|
140 |
<< QVariant(false) // artillery 11 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
141 |
<< QVariant(100) // damage modfier 12 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
142 |
<< QVariant(30) // turn time 13 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
143 |
<< QVariant(100) // init health 14 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
144 |
<< QVariant(15) // sudden death 15 |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
145 |
<< QVariant(0) // case prob 16 |
2031
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
146 |
<< QVariant(3) // mines time 17 |
b6f3e56fb100
david_ac's game scheme options for mine delay/quantity, tweaks to sniper rifle
nemo
parents:
2023
diff
changeset
|
147 |
<< QVariant(4) // landadds 18 |
1968 | 148 |
; |
149 |
||
1884 | 150 |
schemes.append(defaultScheme); |
1897 | 151 |
schemes.append(proMode); |
1968 | 152 |
schemes.append(shoppa); |
1974 | 153 |
schemes.append(basketball); |
1897 | 154 |
|
155 |
||
156 |
int size = fileConfig.beginReadArray("schemes"); |
|
157 |
for (int i = 0; i < size; ++i) { |
|
158 |
fileConfig.setArrayIndex(i); |
|
159 |
||
160 |
if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) |
|
161 |
{ |
|
162 |
QList<QVariant> scheme; |
|
163 |
||
164 |
for (int k = 0; k < spNames.size(); ++k) |
|
165 |
scheme << fileConfig.value(spNames[k], defaultScheme[k]); |
|
166 |
||
167 |
schemes.append(scheme); |
|
168 |
} |
|
169 |
} |
|
170 |
fileConfig.endArray(); |
|
1881 | 171 |
} |
172 |
||
173 |
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
174 |
{ |
|
175 |
return QVariant(); |
|
176 |
} |
|
177 |
||
178 |
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const |
|
179 |
{ |
|
180 |
if (parent.isValid()) |
|
181 |
return 0; |
|
182 |
else |
|
183 |
return schemes.size(); |
|
184 |
} |
|
185 |
||
186 |
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const |
|
187 |
{ |
|
188 |
if (parent.isValid()) |
|
189 |
return 0; |
|
190 |
else |
|
1884 | 191 |
return defaultScheme.size(); |
1881 | 192 |
} |
193 |
||
194 |
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const |
|
195 |
{ |
|
196 |
return |
|
197 |
Qt::ItemIsEnabled |
|
198 |
| Qt::ItemIsSelectable |
|
199 |
| Qt::ItemIsEditable; |
|
200 |
} |
|
201 |
||
202 |
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) |
|
203 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
204 |
if (!index.isValid() || index.row() < numberOfDefaultSchemes |
1884 | 205 |
|| index.row() >= schemes.size() |
206 |
|| index.column() >= defaultScheme.size() |
|
1885 | 207 |
|| role != Qt::EditRole) |
1884 | 208 |
return false; |
209 |
||
1890 | 210 |
schemes[index.row()][index.column()] = value; |
1885 | 211 |
|
1881 | 212 |
emit dataChanged(index, index); |
1884 | 213 |
return true; |
1881 | 214 |
} |
1884 | 215 |
|
216 |
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent) |
|
217 |
{ |
|
218 |
beginInsertRows(parent, row, row); |
|
219 |
||
1890 | 220 |
QList<QVariant> newScheme = defaultScheme; |
221 |
newScheme[0] = QVariant(tr("new")); |
|
1889 | 222 |
|
223 |
schemes.insert(row, newScheme); |
|
1884 | 224 |
|
225 |
endInsertRows(); |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
226 |
|
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
227 |
return true; |
1884 | 228 |
} |
229 |
||
230 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) |
|
231 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
232 |
if(count != 1 |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
233 |
|| row < numberOfDefaultSchemes |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
234 |
|| row >= schemes.size()) |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
235 |
return false; |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
236 |
|
1884 | 237 |
beginRemoveRows(parent, row, row); |
238 |
||
239 |
schemes.removeAt(row); |
|
240 |
||
241 |
endRemoveRows(); |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
242 |
|
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
243 |
return true; |
1884 | 244 |
} |
245 |
||
246 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const |
|
247 |
{ |
|
248 |
if (!index.isValid() || index.row() < 0 |
|
249 |
|| index.row() >= schemes.size() |
|
250 |
|| index.column() >= defaultScheme.size() |
|
1889 | 251 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
252 |
) |
|
1884 | 253 |
return QVariant(); |
254 |
||
1890 | 255 |
return schemes[index.row()][index.column()]; |
1884 | 256 |
} |
1897 | 257 |
|
258 |
void AmmoSchemeModel::Save() |
|
259 |
{ |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
260 |
fileConfig.beginWriteArray("schemes", schemes.size()); |
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
261 |
|
1897 | 262 |
for (int i = 0; i < schemes.size(); ++i) { |
263 |
fileConfig.setArrayIndex(i); |
|
264 |
||
265 |
QList<QVariant> scheme = schemes[i]; |
|
1902
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
266 |
|
aeadb10c2d77
Add delete button and scheme selection combobox to scheme edit page
unc0rr
parents:
1899
diff
changeset
|
267 |
for (int k = 0; k < scheme.size(); ++k) |
1897 | 268 |
fileConfig.setValue(spNames[k], scheme[k]); |
269 |
} |
|
270 |
fileConfig.endArray(); |
|
271 |
} |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
272 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
273 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
274 |
NetAmmoSchemeModel::NetAmmoSchemeModel(QObject * parent) : |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
275 |
QAbstractTableModel(parent) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
276 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
277 |
netScheme = defaultScheme; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
278 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
279 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
280 |
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
|
281 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
282 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
283 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
284 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
285 |
int NetAmmoSchemeModel::rowCount(const QModelIndex & parent) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
286 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
287 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
288 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
289 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
290 |
return 1; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
291 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
292 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
293 |
int NetAmmoSchemeModel::columnCount(const QModelIndex & parent) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
294 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
295 |
if (parent.isValid()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
296 |
return 0; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
297 |
else |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
298 |
return defaultScheme.size(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
299 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
300 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
301 |
QVariant NetAmmoSchemeModel::data(const QModelIndex &index, int role) const |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
302 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
303 |
if (!index.isValid() || index.row() < 0 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
304 |
|| index.row() > 1 |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
305 |
|| index.column() >= defaultScheme.size() |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
306 |
|| (role != Qt::EditRole && role != Qt::DisplayRole) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
307 |
) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
308 |
return QVariant(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
309 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
310 |
return netScheme[index.column()]; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
311 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
312 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
313 |
void NetAmmoSchemeModel::setNetSchemeConfig(QStringList & cfg) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
314 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
315 |
if(cfg.size() != netScheme.size()) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
316 |
{ |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
317 |
qWarning("Incorrect scheme cfg size"); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
318 |
return; |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
319 |
} |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
320 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
321 |
for(int i = 0; i < cfg.size(); ++i) |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
322 |
netScheme[i] = QVariant(cfg[i]); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
323 |
|
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
324 |
reset(); |
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1897
diff
changeset
|
325 |
} |