QTfrontend/model/MapModel.cpp
changeset 6947 1be3e48e1d53
parent 6943 1fe601a2761b
child 6948 7271ce89950f
equal deleted inserted replaced
6946:576c453822bf 6947:1be3e48e1d53
   113             // add a mission caption prefix to missions
   113             // add a mission caption prefix to missions
   114             if (isMission)
   114             if (isMission)
   115             {
   115             {
   116                 // TODO: icon
   116                 // TODO: icon
   117                 caption = QComboBox::tr("Mission") + ": " + map;
   117                 caption = QComboBox::tr("Mission") + ": " + map;
   118                 m_nMissions++;
       
   119             }
   118             }
   120             else
   119             else
   121                 caption = map;
   120                 caption = map;
   122 
   121 
   123             // we know everything there is about the map, let's get am item for it
   122             // we know everything there is about the map, let's get am item for it
   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,