QTfrontend/ui/widget/mapContainer.cpp
changeset 7014 c0b32404ef74
parent 7008 25563f054ef3
child 7017 19a434fc91fc
--- a/QTfrontend/ui/widget/mapContainer.cpp	Thu May 03 12:21:16 2012 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Thu May 03 12:33:08 2012 +0200
@@ -211,6 +211,9 @@
 
 void HWMapContainer::mapChanged(int index)
 {
+    if (index < 0)
+        return;
+
     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
     m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
     m_curMap = chooseMap->currentText();
@@ -379,15 +382,19 @@
 {
     int id = m_mapModel->indexOf(map);
 
-    if(id >= 0)
+    if (pMap)
     {
-        if (pMap)
-        {
-            disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
-            disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
-            pMap = 0;
-        }
-        chooseMap->setCurrentIndex(id);
+        disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
+        disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
+        pMap = 0;
+    }
+
+    chooseMap->setCurrentIndex(id);
+
+    if(id < 0)
+    {
+        m_mapInfo.type = MapModel::Invalid;
+        m_curMap = map;
     }
 }
 
@@ -426,7 +433,7 @@
             chooseMap->setCurrentIndex(idx);
             break;
         case MapModel::Invalid:
-            Q_ASSERT(false);
+            chooseMap->setCurrentIndex(0);
     }
 }
 
@@ -538,8 +545,15 @@
 
 void HWMapContainer::updatePreview()
 {
+    QPixmap failIcon;
+
     switch(m_mapInfo.type)
     {
+        case MapModel::Invalid:
+            failIcon = QPixmap(":/res/btnDisabled.png");
+            imageButt->setIcon(failIcon);
+            imageButt->setIconSize(failIcon.size());
+            break;
         case MapModel::GeneratedMap:
             askForGeneratedPreview();
             break;
@@ -594,13 +608,7 @@
 
     // restore map selection
     if (!m_curMap.isEmpty())
-    {
-        int idx = chooseMap->findText(m_curMap);
-        if (idx >= 0)
-            chooseMap->setCurrentIndex(idx);
-        else
-            chooseMap->setCurrentIndex(0);
-    }
+        setMap(m_curMap);
 
 }