Partially fix wrong preview when joining host room with missing map
authorWuzzy <Wuzzy2@mail.ru>
Wed, 21 Mar 2018 15:38:20 +0100
changeset 13265 2c0779260e8a
parent 13264 e13777374583
child 13266 01ac67500f50
Partially fix wrong preview when joining host room with missing map
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/ui/widget/mapContainer.cpp	Wed Mar 21 14:36:26 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Wed Mar 21 15:38:20 2018 +0100
@@ -337,6 +337,24 @@
     changeMapType(MapModel::GeneratedMap);
 }
 
+void HWMapContainer::onImageReceived(const QPixmap &newImage)
+{
+    // When image received from the engine.
+    switch (m_mapInfo.type)
+    {
+        case MapModel::GeneratedMap:
+        case MapModel::GeneratedMaze:
+        case MapModel::GeneratedPerlin:
+        case MapModel::HandDrawnMap:
+        case MapModel::FortsMap:
+            setImage(newImage);
+            break;
+        // Throw away image if we have switched the map mode in the meantime
+        default:
+            return;
+    }
+}
+
 void HWMapContainer::setImage(const QPixmap &newImage)
 {
     addInfoToPreview(newImage);
@@ -399,7 +417,7 @@
 void HWMapContainer::askForGeneratedPreview()
 {
     pMap = new HWMap(this);
-    connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(setImage(const QPixmap)));
+    connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(onImageReceived(const QPixmap)));
     connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int)));
     connect(pMap, SIGNAL(destroyed(QObject *)), this, SLOT(onPreviewMapDestroyed(QObject *)));
     pMap->getImage(m_seed,
@@ -559,10 +577,15 @@
     {
         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
         m_missingMap = true;
-        setMapNameLabel(map);
-        if (m_mapInfo.type != MapModel::StaticMap && m_mapInfo.type != MapModel::MissionMap)
+        m_curMap = map;
+        if (m_mapInfo.type == MapModel::StaticMap)
+            setupStaticMapsView();
+        else if (m_mapInfo.type == MapModel::MissionMap)
+            setupMissionMapsView();
+        else
         {
             m_mapInfo.type = MapModel::StaticMap;
+            setupStaticMapsView();
             changeMapType(m_mapInfo.type, QModelIndex());
         }
         updatePreview();
@@ -773,7 +796,8 @@
 
 void HWMapContainer::showEvent(QShowEvent * event)
 {
-    if (!m_previewEnabled) {
+    if (!m_previewEnabled)
+    {
         m_previewEnabled = true;
         setRandomTheme();
         updatePreview();
@@ -789,8 +813,9 @@
 
     if (pMap)
     {
-        disconnect(pMap, 0, this, SLOT(setImage(const QPixmap)));
+        disconnect(pMap, 0, this, SLOT(onImageReceived(const QPixmap)));
         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
+        disconnect(pMap, 0, this, SLOT(onPreviewMapDestroyed(QObject *)));
         pMap = 0;
     }
 
@@ -1287,7 +1312,8 @@
             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
             this,
             SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
-    missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+    if(!missionSelectionModel->hasSelection())
+        missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
 }
 
 void HWMapContainer::setupStaticMapsView()
@@ -1303,7 +1329,8 @@
             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
             this,
             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
-    staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+    if(!staticSelectionModel->hasSelection())
+        staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 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 14:36:26 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.h	Wed Mar 21 15:38:20 2018 +0100
@@ -100,7 +100,7 @@
         void drawnMapChanged(const QByteArray & data);
 
     private slots:
-        void setImage(const QPixmap & newImage);
+        void onImageReceived(const QPixmap & newImage);
         void setHHLimit(int hhLimit);
         void setRandomSeed();
         void setRandomTheme();
@@ -176,6 +176,7 @@
         void intSetFeatureSize(int size);
         void setMissingTheme(const QString & name);
         void mapChanged(const QModelIndex & map, int type, const QModelIndex & old = QModelIndex());
+        void setImage(const QPixmap & newImage);
         void setImage(const QPixmap & newImage, const QLinearGradient & linearGrad, bool showHHLimit);
         void addInfoToPreview(const QPixmap & image);
         void addInfoToPreview(const QPixmap & image, const QLinearGradient & linearGrad, bool drawHHLimit);