map, theme & style selection won't be lost on data updata now (except the selected map/theme/style is deleted ofc). enabling F5 key to reload data :>
authorsheepluva
Sun, 29 Apr 2012 20:52:10 +0200
changeset 6960 822f8269e13f
parent 6959 fce378ee4191
child 6961 d5ac09894a1b
map, theme & style selection won't be lost on data updata now (except the selected map/theme/style is deleted ofc). enabling F5 key to reload data :>
QTfrontend/hwform.cpp
QTfrontend/ui/widget/gamecfgwidget.cpp
QTfrontend/ui/widget/gamecfgwidget.h
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/hwform.cpp	Sun Apr 29 17:23:05 2012 +0200
+++ b/QTfrontend/hwform.cpp	Sun Apr 29 20:52:10 2012 +0200
@@ -155,8 +155,10 @@
     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
 #else
     // ctrl+q closes frontend for consistency
-    QShortcut *closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
+    QShortcut * closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
+    QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
+    connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
 #endif
 
     UpdateTeamsLists();
--- a/QTfrontend/ui/widget/gamecfgwidget.cpp	Sun Apr 29 17:23:05 2012 +0200
+++ b/QTfrontend/ui/widget/gamecfgwidget.cpp	Sun Apr 29 20:52:10 2012 +0200
@@ -112,6 +112,8 @@
     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
     connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap()));
     connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &)));
+
+    connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews()));
 }
 
 void GameCFGWidget::jumpToSchemes()
@@ -491,10 +493,13 @@
 
 void GameCFGWidget::scriptChanged(int index)
 {
+    const QString & name = Scripts->itemText(index);
+    m_curScript = name;
+
     if(isEnabled() && index > 0)
     {
-        QString scheme = Scripts->itemData(Scripts->currentIndex(), GameStyleModel::SchemeRole).toString();
-        QString weapons = Scripts->itemData(Scripts->currentIndex(), GameStyleModel::WeaponsRole).toString();
+        QString scheme = Scripts->itemData(index, GameStyleModel::SchemeRole).toString();
+        QString weapons = Scripts->itemData(index, GameStyleModel::WeaponsRole).toString();
 
         if (scheme == "locked")
         {
@@ -537,7 +542,7 @@
         WeaponsName->setEnabled(true);
         bindEntries->setEnabled(true);
     }
-    emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index)));
+    emit paramChanged("SCRIPT", QStringList(name));
 }
 
 void GameCFGWidget::mapgenChanged(MapGenerator m)
@@ -559,3 +564,17 @@
 {
     emit paramChanged("DRAWNMAP", QStringList(qCompress(data, 9).toBase64()));
 }
+
+
+void GameCFGWidget::updateModelViews()
+{
+    // restore game-style selection
+    if (!m_curScript.isEmpty())
+    {
+        int idx = Scripts->findText(m_curScript);
+        if (idx >= 0)
+            Scripts->setCurrentIndex(idx);
+        else
+            Scripts->setCurrentIndex(0);
+    }
+}
--- a/QTfrontend/ui/widget/gamecfgwidget.h	Sun Apr 29 17:23:05 2012 +0200
+++ b/QTfrontend/ui/widget/gamecfgwidget.h	Sun Apr 29 20:52:10 2012 +0200
@@ -72,6 +72,7 @@
         void mapgenChanged(MapGenerator m);
         void maze_sizeChanged(int s);
         void onDrawnMapChanged(const QByteArray & data);
+        void updateModelViews();
 
     private:
         QGridLayout mainLayout;
@@ -79,6 +80,7 @@
         QString curNetAmmoName;
         QString curNetAmmo;
         QRegExp seedRegexp;
+        QString m_curScript;
 
         void setNetAmmo(const QString& name, const QString& ammo);
 
--- a/QTfrontend/ui/widget/mapContainer.cpp	Sun Apr 29 17:23:05 2012 +0200
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Sun Apr 29 20:52:10 2012 +0200
@@ -178,7 +178,7 @@
 
     chooseMap->setCurrentIndex(0);
     mapChanged(0);
-    connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int)));
+    connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
 
     updateModelViews();
 }
@@ -212,7 +212,8 @@
 void HWMapContainer::mapChanged(int index)
 {
     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
-    m_mapInfo = chooseMap->itemData(chooseMap->currentIndex(), Qt::UserRole + 1).value<MapModel::MapInfo>();
+    m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
+    m_curMap = chooseMap->currentText();
 
     switch(m_mapInfo.type)
     {
@@ -437,7 +438,6 @@
             // get random map of same type
             idx = m_mapModel->randomMap(m_mapInfo.type);
             chooseMap->setCurrentIndex(idx);
-            mapChanged(idx);
             break;
         case MapModel::Invalid:
             Q_ASSERT(false);
@@ -595,8 +595,25 @@
 
 void HWMapContainer::updateModelViews()
 {
-    // TODO: reselect theme
-    // FIXME: issues with generated maps?
-    if (!m_mapInfo.name.isEmpty())
-        intSetMap(m_mapInfo.name);
+    // restore theme selection
+    // do this before map selection restore, because map may overwrite theme
+    if (!m_theme.isEmpty())
+    {
+        QModelIndexList mdl = m_themeModel->match(m_themeModel->index(0), Qt::DisplayRole, m_theme);
+        if (mdl.size() > 0)
+            lvThemes->setCurrentIndex(mdl.at(0));
+        else
+            setRandomTheme();
+    }
+
+    // restore map selection
+    if (!m_curMap.isEmpty())
+    {
+        int idx = chooseMap->findText(m_curMap);
+        if (idx >= 0)
+            chooseMap->setCurrentIndex(idx);
+        else
+            chooseMap->setCurrentIndex(0);
+    }
+
 }
--- a/QTfrontend/ui/widget/mapContainer.h	Sun Apr 29 17:23:05 2012 +0200
+++ b/QTfrontend/ui/widget/mapContainer.h	Sun Apr 29 20:52:10 2012 +0200
@@ -129,6 +129,7 @@
 
         MapModel::MapInfo m_mapInfo;
         QString m_theme;
+        QString m_curMap;
 };
 
 #endif // _HWMAP_CONTAINER_INCLUDED