I guess "Fix weapon scheme lookup being unnecesarily persisted"?.. or something
authoralfadur
Sun, 08 Apr 2018 00:26:33 +0200
changeset 13319 fe85ba81b01b
parent 13318 93780a3b846a
child 13320 3546bb36c8fb
I guess "Fix weapon scheme lookup being unnecesarily persisted"?.. or something
QTfrontend/ui/widget/selectWeapon.cpp
QTfrontend/ui/widget/selectWeapon.h
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Sat Apr 07 23:38:19 2018 +0200
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Sun Apr 08 00:26:33 2018 +0200
@@ -85,28 +85,29 @@
     QFrame(parent),
     m_numItems(numItems)
 {
+    wconf = new QMap<QString, QString>();
+    for(int i = 0; i < cDefaultAmmos.size(); ++i)
+        wconf->insert(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
+
     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
     }
     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
         qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini.");
         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
-        wconf = new QSettings("Hedgewars", "Hedgewars");
-        wconf->clear();
+
         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
 
         QStringList defaultAmmos;
-        for(int i = 0; i < cDefaultAmmos.size(); ++i) {
-            wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
-            defaultAmmos.append(cDefaultAmmos[i].first);
-        }
+        for(int i = 0; i < cDefaultAmmos.size(); ++i) 
+            defaultAmmos.append(cDefaultAmmos[i].first);        
 
         QStringList keys = old_wconf.allKeys();
         int imported = 0;
         for(int i = 0; i < keys.size(); i++)
         {
             if (!defaultAmmos.contains(keys[i])) {
-                wconf->setValue(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
+                wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
                 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa");
                 if (file.open(QIODevice::WriteOnly)) {
                     QTextStream stream( &file );
@@ -117,13 +118,7 @@
             }
         }
         qDebug("%d weapon scheme(s) imported.", imported);
-    } else {
-        wconf = new QSettings("Hedgewars", "Hedgewars");
-        wconf->clear();
-
-        for(int i = 0; i < cDefaultAmmos.size(); ++i)
-            wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
-
+    } else {        
         QStringList schemes = QDir(cfgdir->absolutePath() + "/Schemes/Ammo").entryList();
 
         for(int i = 0; i < schemes.size(); i++)
@@ -143,7 +138,7 @@
             if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) {
                 schemeName.chop(4);
             }
-            wconf->setValue(schemeName, fixWeaponSet(config));
+            wconf->insert(schemeName, fixWeaponSet(config));
         }
     }
 
@@ -301,7 +296,7 @@
         // remove old entry
         wconf->remove(curWeaponsName);
     }
-    wconf->setValue(m_name->text(), stateFull);
+    wconf->insert(m_name->text(), stateFull);
     QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + m_name->text()+ ".hwa");
     if (file.open(QIODevice::WriteOnly)) {
         QTextStream stream( &file );
@@ -319,7 +314,7 @@
 
 QString SelWeaponWidget::getWeaponsString(const QString& name) const
 {
-    return wconf->value(name).toString();
+    return wconf->find(name).value();
 }
 
 void SelWeaponWidget::deleteWeaponsName()
@@ -366,7 +361,7 @@
         while(wconf->contains(newName = tr("New (%1)").arg(i++))) ;
     }
     setWeaponsName(newName);
-    wconf->setValue(newName, *cEmptyAmmoStore);
+    wconf->insert(newName, *cEmptyAmmoStore);
     emit weaponsAdded(newName, *cEmptyAmmoStore);
 }
 
@@ -378,7 +373,7 @@
 
     if(name != "" && wconf->contains(name))
     {
-        setWeapons(wconf->value(name).toString());
+        setWeapons(wconf->find(name).value());
     }
     else
     {
@@ -395,7 +390,7 @@
 
 QStringList SelWeaponWidget::getWeaponNames() const
 {
-    return wconf->allKeys();
+    return wconf->keys();
 }
 
 void SelWeaponWidget::copy()
@@ -413,7 +408,7 @@
         }
         setWeaponsName(newName);
         setWeapons(ammo);
-        wconf->setValue(newName, ammo);
+        wconf->insert(newName, ammo);
         emit weaponsAdded(newName, ammo);
     }
 }
--- a/QTfrontend/ui/widget/selectWeapon.h	Sat Apr 07 23:38:19 2018 +0200
+++ b/QTfrontend/ui/widget/selectWeapon.h	Sun Apr 08 00:26:33 2018 +0200
@@ -80,7 +80,7 @@
         QLineEdit* m_name;
 
         //storage for all the weapons sets
-        QSettings* wconf;
+        QMap<QString, QString>* wconf;
 
         const int m_numItems;
         int operator [] (unsigned int weaponIndex) const;