QTfrontend/ui/widget/mapContainer.cpp
changeset 9744 1ee4842a9c86
parent 9739 c2c9dd2544b8
child 9745 258c320256dc
--- a/QTfrontend/ui/widget/mapContainer.cpp	Tue Dec 03 18:09:54 2013 +0100
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Tue Dec 03 23:54:58 2013 +0400
@@ -57,6 +57,8 @@
 {
     // don't show preview anything until first show event
     m_previewEnabled = false;
+    m_missionsViewSetup = false;
+    m_staticViewSetup = false;
 
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
@@ -161,28 +163,14 @@
     /* Static maps list */
 
     staticMapList = new QListView;
-    staticMapList->setModel(m_staticMapModel);
     rightLayout->addWidget(staticMapList, 1);
-    staticMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
     m_childWidgets << staticMapList;
-    QItemSelectionModel * staticSelectionModel = staticMapList->selectionModel();
-    connect(staticSelectionModel,
-            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
-            this,
-            SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
 
     /* Mission maps list */
 
-    missionMapList = new QListView;
-    missionMapList->setModel(m_missionMapModel);
-    missionMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    missionMapList = new QListView(this);
     rightLayout->addWidget(missionMapList, 1);
     m_childWidgets << missionMapList;
-    QItemSelectionModel * missionSelectionModel = missionMapList->selectionModel();
-    connect(missionSelectionModel,
-            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
-            this,
-            SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
 
     /* Map load and edit buttons */
 
@@ -742,6 +730,7 @@
             btnEditMap->show();
             break;
         case MapModel::MissionMap:
+            setupMissionMapsView();
             mapgen = MAPGEN_MAP;
             missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex());
             lblMapList->setText(tr("Mission:"));
@@ -752,6 +741,7 @@
             emit mapChanged(m_curMap);
             break;
         case MapModel::StaticMap:
+            setupStaticMapsView();
             mapgen = MAPGEN_MAP;
             staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex());
             lblMapList->setText(tr("Map:"));
@@ -951,3 +941,35 @@
     btnTheme->setIcon(QIcon());
     btnTheme->setText(tr("Theme: %1").arg(name));
 }
+
+void HWMapContainer::setupMissionMapsView()
+{
+    if(m_missionsViewSetup) return;
+    m_missionsViewSetup = true;
+
+    m_missionMapModel->loadMaps();
+    missionMapList->setModel(m_missionMapModel);
+    missionMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    QItemSelectionModel * missionSelectionModel = missionMapList->selectionModel();
+    connect(missionSelectionModel,
+            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
+            this,
+            SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
+    missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+}
+
+void HWMapContainer::setupStaticMapsView()
+{
+    if(m_staticViewSetup) return;
+    m_staticViewSetup = true;
+
+    m_staticMapModel->loadMaps();
+    staticMapList->setModel(m_staticMapModel);
+    staticMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    QItemSelectionModel * staticSelectionModel = staticMapList->selectionModel();
+    connect(staticSelectionModel,
+            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
+            this,
+            SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
+    staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
+}