Fix frontend from messing with legacy schemes.ini, just read it, never write
authorWuzzy <Wuzzy2@mail.ru>
Wed, 14 Mar 2018 15:55:38 +0100
changeset 13203 ceae8e01af98
parent 13202 0bc5f618ca7c
child 13205 a0ce9573bfe8
Fix frontend from messing with legacy schemes.ini, just read it, never write
QTfrontend/model/gameSchemeModel.cpp
QTfrontend/model/gameSchemeModel.h
QTfrontend/ui/page/pageroomslist.cpp
--- a/QTfrontend/model/gameSchemeModel.cpp	Wed Mar 14 15:19:08 2018 +0100
+++ b/QTfrontend/model/gameSchemeModel.cpp	Wed Mar 14 15:55:38 2018 +0100
@@ -19,6 +19,7 @@
 #include <QDebug>
 #include <QModelIndex>
 #include <QFile>
+#include <QSettings>
 #include <QTextStream>
 #include <QHash>
 
@@ -73,8 +74,7 @@
                                 ;
 
 GameSchemeModel::GameSchemeModel(QObject* parent, const QString & directory) :
-    QAbstractTableModel(parent),
-    fileConfig(cfgdir->absolutePath() + "/schemes.ini", QSettings::IniFormat)
+    QAbstractTableModel(parent)
 {
     predefSchemesNames = QStringList()
                          << "Default"
@@ -743,13 +743,14 @@
 
         qDebug("No /Schemes/Game directory found. Trying to import game schemes from schemes.ini.");
 
-        int size = fileConfig.beginReadArray("schemes");
+        QSettings legacyFileConfig(cfgdir->absolutePath() + "/schemes.ini", QSettings::IniFormat);
+        int size = legacyFileConfig.beginReadArray("schemes");
         int imported = 0;
         for (int i = 0; i < size; ++i)
         {
-            fileConfig.setArrayIndex(i);
+            legacyFileConfig.setArrayIndex(i);
 
-            QString schemeName = fileConfig.value(spNames[0]).toString();
+            QString schemeName = legacyFileConfig.value(spNames[0]).toString();
             if (!schemeName.isNull() && !predefSchemesNames.contains(schemeName))
             {
                 QList<QVariant> scheme;
@@ -760,14 +761,14 @@
                     QTextStream stream(&file);
 
                     for (int k = 0; k < spNames.size(); ++k) {
-                        scheme << fileConfig.value(spNames[k], defaultScheme[k]);
+                        scheme << legacyFileConfig.value(spNames[k], defaultScheme[k]);
 
                         // File handling
                         // We skip the name key (k==0), it is not stored redundantly in file.
                         // The file name is used for that already.
                         if(k != 0) {
                             // The file is just a list of key=value pairs
-                            stream << spNames[k] << "=" << fileConfig.value(spNames[k], defaultScheme[k]).toString();
+                            stream << spNames[k] << "=" << legacyFileConfig.value(spNames[k], defaultScheme[k]).toString();
                             stream << endl;
                         }
                     }
@@ -779,7 +780,7 @@
             }
         }
         qDebug("%d game scheme(s) imported.", imported);
-        fileConfig.endArray();
+        legacyFileConfig.endArray();
     } else {
         QStringList scheme_dir = QDir(directory).entryList(QDir::Files);
 
@@ -962,7 +963,6 @@
 
 void GameSchemeModel::Save()
 {
-    fileConfig.beginWriteArray("schemes");
     for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i)
     {
         QList<QVariant> scheme = schemes[i + numberOfDefaultSchemes];
@@ -984,7 +984,6 @@
             file.close();
         }
     }
-    fileConfig.endArray();
 }
 
 
--- a/QTfrontend/model/gameSchemeModel.h	Wed Mar 14 15:19:08 2018 +0100
+++ b/QTfrontend/model/gameSchemeModel.h	Wed Mar 14 15:55:38 2018 +0100
@@ -22,7 +22,6 @@
 #include <QAbstractTableModel>
 #include <QStringList>
 #include <QList>
-#include <QSettings>
 
 class GameSchemeModel : public QAbstractTableModel
 {
@@ -48,14 +47,8 @@
     public slots:
         void Save();
 
-//    signals:
-//        void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
-
     protected:
         QList< QList<QVariant> > schemes;
-
-    private:
-        QSettings fileConfig;
 };
 
 class NetGameSchemeModel : public QAbstractTableModel
--- a/QTfrontend/ui/page/pageroomslist.cpp	Wed Mar 14 15:19:08 2018 +0100
+++ b/QTfrontend/ui/page/pageroomslist.cpp	Wed Mar 14 15:55:38 2018 +0100
@@ -29,6 +29,7 @@
 #include <QMenu>
 #include <QDebug>
 #include <QSplitter>
+#include <QSettings>
 
 #include <QSortFilterProxyModel>