diff -r 8d41d22a291d -r ede55af89e78 QTfrontend/model/MapModel.cpp --- a/QTfrontend/model/MapModel.cpp Tue May 01 19:56:55 2012 +0200 +++ b/QTfrontend/model/MapModel.cpp Tue May 01 21:24:04 2012 +0200 @@ -148,18 +148,35 @@ items.append(separator.clone()); items.append(staticMaps); + + // create row-index lookup table + + m_mapIndexes.clear(); + + int count = items.size(); + + for (int i = 0; i < count; i++) + { + QStandardItem * si = items.at(i); + QVariant v = si->data(Qt::UserRole + 1); + if (v.canConvert()) + m_mapIndexes.insert(v.value().name, i); + } + + // store start-index and count of relevant types - typeLoc.insert(GeneratedMap, QPair(0, 1)); - typeLoc.insert(GeneratedMaze, QPair(1, 1)); - typeLoc.insert(HandDrawnMap, QPair(2, 1)); + + m_typeLoc.insert(GeneratedMap, QPair(0, 1)); + m_typeLoc.insert(GeneratedMaze, QPair(1, 1)); + m_typeLoc.insert(HandDrawnMap, QPair(2, 1)); // mission maps int startIdx = genMaps.size() + 2; // start after genMaps and 2 separators - int count = missionMaps.size(); - typeLoc.insert(MissionMap, QPair(startIdx, count)); + count = missionMaps.size(); + m_typeLoc.insert(MissionMap, QPair(startIdx, count)); // static maps startIdx += count + 1; // start after missions and 2 separators count = staticMaps.size(); - typeLoc.insert(StaticMap, QPair(startIdx, count)); + m_typeLoc.insert(StaticMap, QPair(startIdx, count)); // store list contents in the item model QStandardItemModel::appendColumn(items); @@ -169,18 +186,10 @@ } -int MapModel::mapCount(MapType type) const -{ - // return the count for this type - // fetch it from the second int in typeLoc, return 0 if no entry - return typeLoc.value(type, QPair(0,0)).second; -} - - int MapModel::randomMap(MapType type) const { // return a random index for this type or -1 if none available - QPair loc = typeLoc.value(type, QPair(-1,0)); + QPair loc = m_typeLoc.value(type, QPair(-1,0)); int startIdx = loc.first; int count = loc.second; @@ -220,3 +229,10 @@ return item; } + + +int MapModel::indexOf(const QString & map) const +{ + return m_mapIndexes.value(map, -1); +} +