QTfrontend/ui/widget/mapContainer.cpp
changeset 6960 822f8269e13f
parent 6947 1be3e48e1d53
child 6983 ede55af89e78
equal deleted inserted replaced
6959:fce378ee4191 6960:822f8269e13f
   176     setRandomSeed();
   176     setRandomSeed();
   177     setRandomTheme();
   177     setRandomTheme();
   178 
   178 
   179     chooseMap->setCurrentIndex(0);
   179     chooseMap->setCurrentIndex(0);
   180     mapChanged(0);
   180     mapChanged(0);
   181     connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int)));
   181     connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
   182 
   182 
   183     updateModelViews();
   183     updateModelViews();
   184 }
   184 }
   185 
   185 
   186 void HWMapContainer::setImage(const QImage newImage)
   186 void HWMapContainer::setImage(const QImage newImage)
   210 }
   210 }
   211 
   211 
   212 void HWMapContainer::mapChanged(int index)
   212 void HWMapContainer::mapChanged(int index)
   213 {
   213 {
   214     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
   214     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
   215     m_mapInfo = chooseMap->itemData(chooseMap->currentIndex(), Qt::UserRole + 1).value<MapModel::MapInfo>();
   215     m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
       
   216     m_curMap = chooseMap->currentText();
   216 
   217 
   217     switch(m_mapInfo.type)
   218     switch(m_mapInfo.type)
   218     {
   219     {
   219         case MapModel::GeneratedMap:
   220         case MapModel::GeneratedMap:
   220             mapgen = MAPGEN_REGULAR;
   221             mapgen = MAPGEN_REGULAR;
   435         case MapModel::MissionMap:
   436         case MapModel::MissionMap:
   436         case MapModel::StaticMap:
   437         case MapModel::StaticMap:
   437             // get random map of same type
   438             // get random map of same type
   438             idx = m_mapModel->randomMap(m_mapInfo.type);
   439             idx = m_mapModel->randomMap(m_mapInfo.type);
   439             chooseMap->setCurrentIndex(idx);
   440             chooseMap->setCurrentIndex(idx);
   440             mapChanged(idx);
       
   441             break;
   441             break;
   442         case MapModel::Invalid:
   442         case MapModel::Invalid:
   443             Q_ASSERT(false);
   443             Q_ASSERT(false);
   444     }
   444     }
   445 }
   445 }
   593 }
   593 }
   594 
   594 
   595 
   595 
   596 void HWMapContainer::updateModelViews()
   596 void HWMapContainer::updateModelViews()
   597 {
   597 {
   598     // TODO: reselect theme
   598     // restore theme selection
   599     // FIXME: issues with generated maps?
   599     // do this before map selection restore, because map may overwrite theme
   600     if (!m_mapInfo.name.isEmpty())
   600     if (!m_theme.isEmpty())
   601         intSetMap(m_mapInfo.name);
   601     {
   602 }
   602         QModelIndexList mdl = m_themeModel->match(m_themeModel->index(0), Qt::DisplayRole, m_theme);
       
   603         if (mdl.size() > 0)
       
   604             lvThemes->setCurrentIndex(mdl.at(0));
       
   605         else
       
   606             setRandomTheme();
       
   607     }
       
   608 
       
   609     // restore map selection
       
   610     if (!m_curMap.isEmpty())
       
   611     {
       
   612         int idx = chooseMap->findText(m_curMap);
       
   613         if (idx >= 0)
       
   614             chooseMap->setCurrentIndex(idx);
       
   615         else
       
   616             chooseMap->setCurrentIndex(0);
       
   617     }
       
   618 
       
   619 }