--- a/QTfrontend/ammoSchemeModel.cpp Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.cpp Mon Mar 16 19:55:56 2009 +0000
@@ -18,11 +18,37 @@
#include <QDebug>
#include <QModelIndex>
+
#include "ammoSchemeModel.h"
+#include "hwconsts.h"
-AmmoSchemeModel::AmmoSchemeModel(QObject* parent) :
- QAbstractTableModel(parent)
+AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) :
+ QAbstractTableModel(parent),
+ fileConfig(fileName, QSettings::IniFormat)
{
+ spNames
+ << "name" // 0
+ << "fortsmode" // 1
+ << "divteams" // 2
+ << "solidland" // 3
+ << "border" // 4
+ << "lowgrav" // 5
+ << "laser" // 6
+ << "invulnerability" // 7
+ << "mines" // 8
+ << "damagefactor" // 9
+ << "turntime" // 10
+ << "health" // 11
+ << "suddendeath" // 12
+ << "caseprobability" // 13
+ ;
+
+
+ QStringList predefSchemesNames;
+ predefSchemesNames
+ << tr("Default")
+ << tr("Pro mode");
+
defaultScheme
<< QVariant(tr("Default")) // name 0
<< QVariant(false) // fortsmode 1
@@ -40,7 +66,43 @@
<< QVariant(5) // case prob 13
;
+ QList<QVariant> proMode;
+ proMode
+ << QVariant(tr("Pro mode"))// name 0
+ << QVariant(false) // fortsmode 1
+ << QVariant(false) // team divide 2
+ << QVariant(false) // solid land 3
+ << QVariant(false) // border 4
+ << QVariant(false) // low gravity 5
+ << QVariant(false) // laser sight 6
+ << QVariant(false) // invulnerable 7
+ << QVariant(false) // add mines 8
+ << QVariant(100) // damage modfier 9
+ << QVariant(15) // turn time 10
+ << QVariant(100) // init health 11
+ << QVariant(15) // sudden death 12
+ << QVariant(0) // case prob 13
+ ;
+
schemes.append(defaultScheme);
+ schemes.append(proMode);
+
+
+ int size = fileConfig.beginReadArray("schemes");
+ for (int i = 0; i < size; ++i) {
+ fileConfig.setArrayIndex(i);
+
+ if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString()))
+ {
+ QList<QVariant> scheme;
+
+ for (int k = 0; k < spNames.size(); ++k)
+ scheme << fileConfig.value(spNames[k], defaultScheme[k]);
+
+ schemes.append(scheme);
+ }
+ }
+ fileConfig.endArray();
}
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -102,6 +164,7 @@
{
beginRemoveRows(parent, row, row);
+ fileConfig.remove(schemes[row][0].toString());
schemes.removeAt(row);
endRemoveRows();
@@ -118,3 +181,17 @@
return schemes[index.row()][index.column()];
}
+
+void AmmoSchemeModel::Save()
+{
+ fileConfig.beginWriteArray("schemes");
+ for (int i = 0; i < schemes.size(); ++i) {
+ fileConfig.setArrayIndex(i);
+
+ QList<QVariant> scheme = schemes[i];
+
+ for (int k = 0; k < spNames.size(); ++k)
+ fileConfig.setValue(spNames[k], scheme[k]);
+ }
+ fileConfig.endArray();
+}