Fix initial map preview being broken when joining room, part 2
authorWuzzy <Wuzzy2@mail.ru>
Wed, 21 Mar 2018 20:35:50 +0100
changeset 13266 01ac67500f50
parent 13265 2c0779260e8a
child 13267 2877c1ec5877
Fix initial map preview being broken when joining room, part 2
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/ui/widget/mapContainer.cpp	Wed Mar 21 15:38:20 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Wed Mar 21 20:35:50 2018 +0100
@@ -578,14 +578,16 @@
         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
         m_missingMap = true;
         m_curMap = map;
+        m_mapInfo.name = map;
+        setMapNameLabel(map);
         if (m_mapInfo.type == MapModel::StaticMap)
-            setupStaticMapsView();
+            setupStaticMapsView(m_curMap);
         else if (m_mapInfo.type == MapModel::MissionMap)
-            setupMissionMapsView();
+            setupMissionMapsView(m_curMap);
         else
         {
             m_mapInfo.type = MapModel::StaticMap;
-            setupStaticMapsView();
+            setupStaticMapsView(m_curMap);
             changeMapType(m_mapInfo.type, QModelIndex());
         }
         updatePreview();
@@ -1299,7 +1301,7 @@
     updateThemeButtonSize();
 }
 
-void HWMapContainer::setupMissionMapsView()
+void HWMapContainer::setupMissionMapsView(const QString & initialMap)
 {
     if(m_missionsViewSetup) return;
     m_missionsViewSetup = true;
@@ -1312,11 +1314,13 @@
             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
             this,
             SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
-    if(!missionSelectionModel->hasSelection())
-        missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+    int m = 0;
+    if(!initialMap.isNull())
+        m = m_missionMapModel->findMap(initialMap);
+    missionSelectionModel->setCurrentIndex(m_missionMapModel->index(m, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
 }
 
-void HWMapContainer::setupStaticMapsView()
+void HWMapContainer::setupStaticMapsView(const QString & initialMap)
 {
     if(m_staticViewSetup) return;
     m_staticViewSetup = true;
@@ -1329,8 +1333,10 @@
             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
             this,
             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
-    if(!staticSelectionModel->hasSelection())
-        staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+    int m = 0;
+    if(!initialMap.isNull())
+        m = m_staticMapModel->findMap(initialMap);
+    staticSelectionModel->setCurrentIndex(m_staticMapModel->index(m, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
 }
 
 // Call this function instead of setting the text of the map name label
--- a/QTfrontend/ui/widget/mapContainer.h	Wed Mar 21 15:38:20 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.h	Wed Mar 21 20:35:50 2018 +0100
@@ -185,8 +185,8 @@
         void updateHelpTexts(MapModel::MapType type);
         void updatePreview();
         void updateThemeButtonSize();
-        void setupMissionMapsView();
-        void setupStaticMapsView();
+        void setupMissionMapsView(const QString & initialMap = QString());
+        void setupStaticMapsView(const QString & initialMap = QString());
         void setMapNameLabel(QString mapName);
 
         MapModel::MapInfo m_mapInfo;