author | unc0rr |
Tue, 13 Dec 2022 21:21:55 +0100 | |
changeset 15899 | 73cdc306888f |
parent 15879 | 4c58b320056c |
permissions | -rw-r--r-- |
6966 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6966 | 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6966 | 17 |
*/ |
18 |
||
19 |
/** |
|
20 |
* @file |
|
21 |
* @brief RoomsListModel class implementation |
|
22 |
*/ |
|
23 |
||
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
24 |
#include <QBrush> |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
25 |
#include <QColor> |
6973 | 26 |
#include <QIcon> |
27 |
||
7258 | 28 |
#include "roomslistmodel.h" |
29 |
#include "MapModel.h" |
|
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
30 |
#include "hwconsts.h" |
7258 | 31 |
|
6732 | 32 |
RoomsListModel::RoomsListModel(QObject *parent) : |
6973 | 33 |
QAbstractTableModel(parent), |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
34 |
c_nColumns(10) |
6732 | 35 |
{ |
12474
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
36 |
m_headerData = QStringList(); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
37 |
m_headerData << tr("In progress"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
38 |
m_headerData << tr("Room Name"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
39 |
//: Caption of the column for the number of connected clients in the list of rooms |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
40 |
m_headerData << tr("C"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
41 |
//: Caption of the column for the number of teams in the list of rooms |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
42 |
m_headerData << tr("T"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
43 |
m_headerData << tr("Owner"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
44 |
m_headerData << tr("Map"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
45 |
m_headerData << tr("Script"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
46 |
m_headerData << tr("Rules"); |
42da9d8d82ab
Provide translator context for a few less obvious engine strings
Wuzzy <almikes@aol.com>
parents:
11752
diff
changeset
|
47 |
m_headerData << tr("Weapons"); |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
48 |
m_headerData << tr("Version"); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
49 |
|
8377 | 50 |
m_staticMapModel = DataManager::instance().staticMapModel(); |
51 |
m_missionMapModel = DataManager::instance().missionMapModel(); |
|
6732 | 52 |
} |
53 |
||
6973 | 54 |
|
6732 | 55 |
QVariant RoomsListModel::headerData(int section, Qt::Orientation orientation, int role) const |
56 |
{ |
|
57 |
if(orientation == Qt::Vertical || role != Qt::DisplayRole) |
|
58 |
return QVariant(); |
|
59 |
else |
|
60 |
return QVariant(m_headerData.at(section)); |
|
61 |
} |
|
62 |
||
6973 | 63 |
|
6732 | 64 |
int RoomsListModel::rowCount(const QModelIndex & parent) const |
65 |
{ |
|
66 |
if(parent.isValid()) |
|
67 |
return 0; |
|
68 |
else |
|
69 |
return m_data.size(); |
|
70 |
} |
|
71 |
||
6973 | 72 |
|
6732 | 73 |
int RoomsListModel::columnCount(const QModelIndex & parent) const |
74 |
{ |
|
75 |
if(parent.isValid()) |
|
76 |
return 0; |
|
77 |
else |
|
6973 | 78 |
return c_nColumns; |
6732 | 79 |
} |
80 |
||
6973 | 81 |
|
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
82 |
QString RoomsListModel::protoToVersion(const QString & proto) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
83 |
{ |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
84 |
bool ok; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
85 |
uint protoNum = proto.toUInt(&ok); |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
86 |
if (!ok) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
87 |
return "Unknown"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
88 |
switch (protoNum) { |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
89 |
case 17: return "0.9.7-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
90 |
case 19: return "0.9.7"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
91 |
case 20: return "0.9.8-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
92 |
case 21: return "0.9.8"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
93 |
case 22: return "0.9.9-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
94 |
case 23: return "0.9.9"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
95 |
case 24: return "0.9.10-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
96 |
case 25: return "0.9.10"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
97 |
case 26: return "0.9.11-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
98 |
case 27: return "0.9.11"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
99 |
case 28: return "0.9.12-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
100 |
case 29: return "0.9.12"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
101 |
case 30: return "0.9.13-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
102 |
case 31: return "0.9.13"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
103 |
case 32: return "0.9.14-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
104 |
case 33: return "0.9.14"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
105 |
case 34: return "0.9.15-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
106 |
case 35: return "0.9.14.1"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
107 |
case 37: return "0.9.15"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
108 |
case 38: return "0.9.16-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
109 |
case 39: return "0.9.16"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
110 |
case 40: return "0.9.17-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
111 |
case 41: return "0.9.17"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
112 |
case 42: return "0.9.18-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
113 |
case 43: return "0.9.18"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
114 |
case 44: return "0.9.19-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
115 |
case 45: return "0.9.19"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
116 |
case 46: return "0.9.20-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
117 |
case 47: return "0.9.20"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
118 |
case 48: return "0.9.21-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
119 |
case 49: return "0.9.21"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
120 |
case 50: return "0.9.22-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
121 |
case 51: return "0.9.22"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
122 |
case 52: return "0.9.23-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
123 |
case 53: return "0.9.23"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
124 |
case 54: return "0.9.24-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
125 |
case 55: return "0.9.24"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
126 |
case 56: return "0.9.25-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
127 |
case 57: return "0.9.25"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
128 |
case 58: return "1.0.0-dev"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
129 |
case 59: return "1.0.0"; |
15879
4c58b320056c
Change the next major release version number to 1.1.0
S.D.
parents:
15878
diff
changeset
|
130 |
case 60: return "1.1.0-dev"; |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
131 |
default: return "Unknown"; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
132 |
} |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
133 |
} |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
134 |
|
6732 | 135 |
QVariant RoomsListModel::data(const QModelIndex &index, int role) const |
136 |
{ |
|
6973 | 137 |
int column = index.column(); |
138 |
int row = index.row(); |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
139 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
140 |
// invalid index |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
141 |
if (!index.isValid()) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
142 |
return QVariant(); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
143 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
144 |
// invalid row |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
145 |
if ((row < 0) || (row >= m_data.size())) |
6732 | 146 |
return QVariant(); |
147 |
||
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
148 |
// invalid column |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
149 |
if ((column < 0) || (column >= c_nColumns)) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
150 |
return QVariant(); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
151 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
152 |
// not a role we have data for |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
153 |
if (role != Qt::DisplayRole) |
6987
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
154 |
// only custom-align counters |
6993
47830cf50574
room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents:
6987
diff
changeset
|
155 |
if ((role != Qt::TextAlignmentRole) |
47830cf50574
room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents:
6987
diff
changeset
|
156 |
|| ((column != PlayerCountColumn) && (column != TeamCountColumn))) |
47830cf50574
room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents:
6987
diff
changeset
|
157 |
// only decorate name column |
47830cf50574
room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents:
6987
diff
changeset
|
158 |
if ((role != Qt::DecorationRole) || (column != NameColumn)) |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
159 |
if ((role != Qt::ForegroundRole)) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
160 |
// UserRole is used for version column filtering |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
161 |
if ((role != Qt::UserRole)) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
162 |
return QVariant(); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
163 |
|
6973 | 164 |
// decorate room name based on room state |
165 |
if (role == Qt::DecorationRole) |
|
166 |
{ |
|
167 |
const QIcon roomBusyIcon(":/res/iconDamage.png"); |
|
10739 | 168 |
const QIcon roomBusyIconGreen(":/res/iconDamageLockG.png"); |
169 |
const QIcon roomBusyIconRed(":/res/iconDamageLockR.png"); |
|
6973 | 170 |
const QIcon roomWaitingIcon(":/res/iconTime.png"); |
10739 | 171 |
const QIcon roomWaitingIconGreen(":/res/iconTimeLockG.png"); |
172 |
const QIcon roomWaitingIconRed(":/res/iconTimeLockR.png"); |
|
173 |
||
10745 | 174 |
QString flags = m_data.at(row).at(StateColumn); |
6973 | 175 |
|
10739 | 176 |
if (flags.contains("g")) |
177 |
{ |
|
178 |
if (flags.contains("j")) |
|
10741 | 179 |
return QVariant(roomBusyIconRed); |
180 |
else if (flags.contains("p")) |
|
181 |
return QVariant(roomBusyIconGreen); |
|
182 |
else |
|
183 |
return QVariant(roomBusyIcon); |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
if (flags.contains("j")) |
|
10739 | 188 |
return QVariant(roomWaitingIconRed); |
189 |
else if (flags.contains("p")) |
|
190 |
return QVariant(roomWaitingIconGreen); |
|
191 |
else |
|
192 |
return QVariant(roomWaitingIcon); |
|
193 |
} |
|
6973 | 194 |
} |
195 |
||
196 |
QString content = m_data.at(row).at(column); |
|
197 |
||
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
198 |
if (role == Qt::DisplayRole) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
199 |
{ |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
200 |
// display room names |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
201 |
if (column == 5) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
202 |
{ |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
203 |
// special names |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
204 |
if (content[0] == '+') |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
205 |
{ |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
206 |
if (content == "+rnd+") return tr("Random Map"); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
207 |
if (content == "+maze+") return tr("Random Maze"); |
10391 | 208 |
if (content == "+perlin+") return tr("Random Perlin"); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
209 |
if (content == "+drawn+") return tr("Hand-drawn"); |
11744
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11046
diff
changeset
|
210 |
if (content == "+forts+") return tr("Forts"); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
211 |
} |
6973 | 212 |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
213 |
// prefix ? if map not available |
8377 | 214 |
if (!m_staticMapModel->mapExists(content) && |
215 |
!m_missionMapModel->mapExists(content)) |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
216 |
return QString ("? %1").arg(content); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
217 |
} |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
218 |
else if (column == VersionColumn) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
219 |
{ |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
220 |
return protoToVersion(content); |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
221 |
} |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
222 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
223 |
return content; |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
224 |
} |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
225 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
226 |
// dye map names red if map not available |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
227 |
if (role == Qt::ForegroundRole) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
228 |
{ |
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
229 |
if (m_data[row][VersionColumn] != *cProtoVer) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
230 |
return QBrush(QColor("darkgrey")); |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
231 |
|
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
232 |
if (column == MapColumn) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
233 |
{ |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
234 |
if (content == "+rnd+" || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
235 |
content == "+maze+" || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
236 |
content == "+perlin+" || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
237 |
content == "+drawn+" || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
238 |
content == "+forts+" || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
239 |
m_staticMapModel->mapExists(content) || |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
240 |
m_missionMapModel->mapExists(content)) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
241 |
return QVariant(); |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
242 |
else |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
243 |
return QBrush(QColor("darkred")); |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
244 |
} |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
245 |
return QVariant(); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
246 |
} |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
247 |
|
6987
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
248 |
if (role == Qt::TextAlignmentRole) |
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
249 |
{ |
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
250 |
return (int)(Qt::AlignHCenter | Qt::AlignVCenter); |
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
251 |
} |
e34415c77342
allow custom sorting of roomslist (by clicking on header sections)
sheepluva
parents:
6983
diff
changeset
|
252 |
|
15878
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
253 |
if (role == Qt::UserRole && column == VersionColumn) |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
254 |
return content; |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
12474
diff
changeset
|
255 |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
256 |
Q_ASSERT(false); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6973
diff
changeset
|
257 |
return QVariant(); |
6732 | 258 |
} |
6733 | 259 |
|
6973 | 260 |
|
6733 | 261 |
void RoomsListModel::setRoomsList(const QStringList & rooms) |
262 |
{ |
|
6973 | 263 |
beginResetModel(); |
264 |
||
265 |
m_data.clear(); |
|
6733 | 266 |
|
6973 | 267 |
int nRooms = rooms.size(); |
268 |
||
269 |
for (int i = 0; i < nRooms; i += c_nColumns) |
|
6733 | 270 |
{ |
271 |
QStringList l; |
|
6973 | 272 |
|
273 |
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) |
|
274 |
l.reserve(c_nColumns); // small optimisation not supported in old Qt |
|
275 |
#endif |
|
276 |
||
277 |
for (int t = 0; t < c_nColumns; t++) |
|
278 |
{ |
|
6733 | 279 |
l.append(rooms[i + t]); |
6973 | 280 |
} |
6733 | 281 |
|
10739 | 282 |
m_data.append(l); |
6733 | 283 |
} |
284 |
||
6973 | 285 |
endResetModel(); |
6733 | 286 |
} |
287 |
||
6973 | 288 |
|
6733 | 289 |
void RoomsListModel::addRoom(const QStringList & info) |
290 |
{ |
|
291 |
beginInsertRows(QModelIndex(), 0, 0); |
|
292 |
||
10739 | 293 |
m_data.prepend(info); |
6733 | 294 |
|
295 |
endInsertRows(); |
|
296 |
} |
|
297 |
||
6973 | 298 |
|
299 |
int RoomsListModel::rowOfRoom(const QString & name) |
|
300 |
{ |
|
301 |
int size = m_data.size(); |
|
302 |
||
303 |
if (size < 1) |
|
304 |
return -1; |
|
305 |
||
306 |
int i = 0; |
|
307 |
||
308 |
// search for record with matching room name |
|
6993
47830cf50574
room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents:
6987
diff
changeset
|
309 |
while(m_data[i].at(NameColumn) != name) |
6973 | 310 |
{ |
311 |
i++; |
|
312 |
if(i >= size) |
|
313 |
return -1; |
|
314 |
} |
|
315 |
||
316 |
return i; |
|
317 |
} |
|
318 |
||
319 |
||
6733 | 320 |
void RoomsListModel::removeRoom(const QString & name) |
321 |
{ |
|
6973 | 322 |
int i = rowOfRoom(name); |
323 |
||
324 |
if (i < 0) |
|
6733 | 325 |
return; |
326 |
||
327 |
beginRemoveRows(QModelIndex(), i, i); |
|
328 |
||
329 |
m_data.removeAt(i); |
|
330 |
||
331 |
endRemoveRows(); |
|
332 |
} |
|
333 |
||
6973 | 334 |
|
6733 | 335 |
void RoomsListModel::updateRoom(const QString & name, const QStringList & info) |
336 |
{ |
|
6973 | 337 |
int i = rowOfRoom(name); |
338 |
||
339 |
if (i < 0) |
|
6733 | 340 |
return; |
341 |
||
10739 | 342 |
m_data[i] = info; |
6733 | 343 |
|
344 |
emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex()) - 1)); |
|
345 |
} |