132 |
131 |
133 } |
132 } |
134 |
133 |
135 } |
134 } |
136 |
135 |
137 // update mission count member |
|
138 m_nMissions = missionMaps.size(); |
|
139 |
136 |
140 // define a separator item |
137 // define a separator item |
141 QStandardItem separator("---"); |
138 QStandardItem separator("---"); |
142 separator.setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole); |
139 separator.setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole); |
143 separator.setFlags(separator.flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) ); |
140 separator.setFlags(separator.flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) ); |
150 items.append(separator.clone()); |
147 items.append(separator.clone()); |
151 items.append(missionMaps); |
148 items.append(missionMaps); |
152 items.append(separator.clone()); |
149 items.append(separator.clone()); |
153 items.append(staticMaps); |
150 items.append(staticMaps); |
154 |
151 |
|
152 // store start-index and count of relevant types |
|
153 typeLoc.insert(GeneratedMap, QPair<int,int>(0, 1)); |
|
154 typeLoc.insert(GeneratedMaze, QPair<int,int>(1, 1)); |
|
155 typeLoc.insert(HandDrawnMap, QPair<int,int>(2, 1)); |
|
156 // mission maps |
|
157 int startIdx = genMaps.size() + 2; // start after genMaps and 2 separators |
|
158 int count = missionMaps.size(); |
|
159 typeLoc.insert(MissionMap, QPair<int,int>(startIdx, count)); |
|
160 // static maps |
|
161 startIdx += count + 1; // start after missions and 2 separators |
|
162 count = staticMaps.size(); |
|
163 typeLoc.insert(StaticMap, QPair<int,int>(startIdx, count)); |
|
164 |
155 // store list contents in the item model |
165 // store list contents in the item model |
156 QStandardItemModel::appendColumn(items); |
166 QStandardItemModel::appendColumn(items); |
157 |
167 |
158 |
168 |
159 endResetModel(); |
169 endResetModel(); |
160 } |
170 } |
161 |
171 |
162 |
172 |
163 int MapModel::missionCount() const |
173 int MapModel::mapCount(MapType type) const |
164 { |
174 { |
165 return m_nMissions; |
175 // return the count for this type |
|
176 // fetch it from the second int in typeLoc, return 0 if no entry |
|
177 return typeLoc.value(type, QPair<int,int>(0,0)).second; |
|
178 } |
|
179 |
|
180 |
|
181 int MapModel::randomMap(MapType type) const |
|
182 { |
|
183 // return a random index for this type or -1 if none available |
|
184 QPair<int,int> loc = typeLoc.value(type, QPair<int,int>(-1,0)); |
|
185 |
|
186 int startIdx = loc.first; |
|
187 int count = loc.second; |
|
188 |
|
189 if (count < 1) |
|
190 return -1; |
|
191 else |
|
192 return startIdx + (rand() % count); |
166 } |
193 } |
167 |
194 |
168 |
195 |
169 QStandardItem * MapModel::infoToItem( |
196 QStandardItem * MapModel::infoToItem( |
170 const QIcon & icon, |
197 const QIcon & icon, |