diff -r 6bfa989c70f3 -r aeadb10c2d77 QTfrontend/ammoSchemeModel.cpp --- a/QTfrontend/ammoSchemeModel.cpp Wed Mar 18 21:42:50 2009 +0000 +++ b/QTfrontend/ammoSchemeModel.cpp Wed Mar 18 21:43:22 2009 +0000 @@ -22,8 +22,8 @@ #include "ammoSchemeModel.h" #include "hwconsts.h" -QList defaultScheme = QList() - << QVariant("Default") // name 0 +QList defaultScheme = QList() + << QVariant("Default") // name 0 << QVariant(false) // fortsmode 1 << QVariant(false) // team divide 2 << QVariant(false) // solid land 3 @@ -41,14 +41,15 @@ AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : QAbstractTableModel(parent), - fileConfig(fileName, QSettings::IniFormat) + fileConfig(fileName, QSettings::IniFormat), + numberOfDefaultSchemes(2) { QStringList predefSchemesNames; predefSchemesNames << "Default" << "Pro mode"; -QStringList spNames = QStringList() + spNames = QStringList() << "name" // 0 << "fortsmode" // 1 << "divteams" // 2 @@ -135,7 +136,7 @@ bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) { - if (!index.isValid() || index.row() < 0 + if (!index.isValid() || index.row() < numberOfDefaultSchemes || index.row() >= schemes.size() || index.column() >= defaultScheme.size() || role != Qt::EditRole) @@ -157,16 +158,24 @@ schemes.insert(row, newScheme); endInsertRows(); + + return true; } bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) { + if(count != 1 + || row < numberOfDefaultSchemes + || row >= schemes.size()) + return false; + beginRemoveRows(parent, row, row); - fileConfig.remove(schemes[row][0].toString()); schemes.removeAt(row); endRemoveRows(); + + return true; } QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const @@ -183,13 +192,14 @@ void AmmoSchemeModel::Save() { - fileConfig.beginWriteArray("schemes"); + fileConfig.beginWriteArray("schemes", schemes.size()); + for (int i = 0; i < schemes.size(); ++i) { fileConfig.setArrayIndex(i); QList scheme = schemes[i]; - - for (int k = 0; k < spNames.size(); ++k) + + for (int k = 0; k < scheme.size(); ++k) fileConfig.setValue(spNames[k], scheme[k]); } fileConfig.endArray();