author | sheepluva |
Wed, 18 Jun 2014 01:37:28 +0200 | |
changeset 10324 | 5d90d8ca9657 |
parent 10108 | c68cf030eded |
child 10391 | ce3ccc45d790 |
permissions | -rw-r--r-- |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
1 |
/* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
4 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
8 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
13 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
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 |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
17 |
*/ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
18 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
19 |
/** |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
20 |
* @file |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
21 |
* @brief MapModel class definition |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
22 |
*/ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
23 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
24 |
#ifndef HEDGEWARS_MAPMODEL_H |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
25 |
#define HEDGEWARS_MAPMODEL_H |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
26 |
|
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
27 |
#include <QStandardItemModel> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
28 |
#include <QStringList> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
29 |
#include <QTextStream> |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
30 |
#include <QHash> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
31 |
#include <QMap> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
32 |
#include <QIcon> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
33 |
#include <QComboBox> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
34 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
35 |
#include "DataManager.h" |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
36 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
37 |
/** |
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
38 |
* @brief A model that vertically lists available maps |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
39 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
40 |
* @author sheepluva |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
41 |
* @since 0.9.18 |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
42 |
*/ |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
43 |
class MapModel : public QStandardItemModel |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
44 |
{ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
45 |
Q_OBJECT |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
46 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
47 |
public: |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
48 |
enum MapType { |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
49 |
Invalid, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
50 |
GeneratedMap, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
51 |
GeneratedMaze, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
52 |
HandDrawnMap, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
53 |
MissionMap, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
54 |
StaticMap |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
55 |
}; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
56 |
|
6943 | 57 |
/// a struct for holding the attributes of a map. |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
58 |
struct MapInfo |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
59 |
{ |
6943 | 60 |
MapType type; ///< The map-type |
61 |
QString name; ///< The internal name. |
|
62 |
QString theme; ///< The theme to be used. (can be empty) |
|
63 |
quint32 limit; ///< The maximum allowed number of hedgehogs. |
|
64 |
QString scheme; ///< Default scheme name or "locked", for mission-maps. |
|
65 |
QString weapons; ///< Default weaponset name or "locked", for missions-maps. |
|
8377 | 66 |
QString desc; ///< The brief 1-2 sentence description of the mission, for mission-maps. |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
67 |
bool dlc; ///< True if this map was not packaged with the game |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
68 |
}; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
69 |
|
9744 | 70 |
MapModel(MapType maptype, QObject *parent = 0); |
71 |
||
6943 | 72 |
/** |
8377 | 73 |
* @brief Searches maps in model to find out if one exists |
74 |
* @param map map of which to check existence |
|
75 |
* @return true if it exists |
|
6943 | 76 |
*/ |
9744 | 77 |
bool mapExists(const QString & map); |
8377 | 78 |
|
79 |
/** |
|
80 |
* @brief Finds a map index (column, row) for a map name |
|
81 |
* @param map map of which to find index+column |
|
82 |
* @return QPair<int, int> with column, index, or (-1, -1) if map not found |
|
83 |
*/ |
|
84 |
//QPair<int, int> findMap(const QString & map) const; |
|
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
85 |
|
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
86 |
/** |
8377 | 87 |
* @brief Finds a map index for a map name |
88 |
* @param map map of which to find index |
|
89 |
* @return int of index, or -1 if map not found |
|
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
90 |
*/ |
9744 | 91 |
int findMap(const QString & map); |
8377 | 92 |
|
93 |
/** |
|
94 |
* @brief Finds and returns a map item for a map name |
|
95 |
* @param map map |
|
96 |
* @return QStandardItem of map, or NULL if map not found |
|
97 |
*/ |
|
98 |
QStandardItem * getMap(const QString & map); |
|
99 |
||
100 |
// Static MapInfos for drawn and generated maps |
|
101 |
static MapInfo MapInfoRandom, MapInfoMaze, MapInfoDrawn; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
102 |
|
9744 | 103 |
/// Loads the maps |
104 |
bool loadMaps(); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
105 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
106 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
107 |
private: |
8377 | 108 |
/// map index lookup table. QPair<int, int> contains: <column, index> |
109 |
//QHash<QString, QPair<int, int> > m_mapIndexes; |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
110 |
QHash<QString, int> m_mapIndexes; |
9744 | 111 |
MapType m_maptype; |
112 |
bool m_loaded; |
|
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
113 |
|
6943 | 114 |
/** |
115 |
* @brief Creates a QStandardItem, that holds the map info and item appearance. |
|
116 |
* The used role for the data is Qt::UserRole + 1. |
|
117 |
* @param icon the icon to be displayed (can be an empty QIcon()). |
|
118 |
* @param caption the text to be displayed. |
|
119 |
* @param type the type of the map. |
|
120 |
* @param name the internal name of the map. |
|
121 |
* @param theme the theme of the map (or empty if none). |
|
122 |
* @param limit the hedgehog limit of the map. |
|
123 |
* @param scheme mission map: default scheme name or "locked". |
|
124 |
* @param weapons mission map: default weaponset name or "locked". |
|
8377 | 125 |
* @param desc mission map: description of mission. |
6943 | 126 |
* @return pointer to item representing the map info: at Qt::UserRole + 1. |
127 |
*/ |
|
8377 | 128 |
static QStandardItem * infoToItem( |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
129 |
const QIcon & icon, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
130 |
const QString caption, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
131 |
MapType type = Invalid, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
132 |
QString name = "", |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
133 |
QString theme = "", |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
134 |
quint32 limit = 0, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
135 |
QString scheme = "", |
8377 | 136 |
QString weapons = "", |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
137 |
QString desc = "", |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
138 |
bool dlc = false); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
139 |
}; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
140 |
|
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
141 |
Q_DECLARE_METATYPE(MapModel::MapInfo) |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
142 |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
143 |
#endif // HEDGEWARS_MAPMODEL_H |