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