--- 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<QVariant> defaultScheme = QList<QVariant>()
- << QVariant("Default") // name 0
+QList<QVariant> defaultScheme = QList<QVariant>()
+ << 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<QVariant> 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();
--- a/QTfrontend/ammoSchemeModel.h Wed Mar 18 21:42:50 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.h Wed Mar 18 21:43:22 2009 +0000
@@ -53,6 +53,8 @@
QSettings fileConfig;
QStringList spNames;
+
+ const int numberOfDefaultSchemes;
};
class NetAmmoSchemeModel : public QAbstractTableModel
--- a/QTfrontend/hwform.cpp Wed Mar 18 21:42:50 2009 +0000
+++ b/QTfrontend/hwform.cpp Wed Mar 18 21:43:22 2009 +0000
@@ -146,7 +146,6 @@
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
this, SLOT(GoBack())); // executed third
- connect(ui.pageScheme->BtnSave, SIGNAL(clicked()), this, SLOT(GoBack()));
connect(ui.pageScheme->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
@@ -356,6 +355,9 @@
if (id == ID_PAGE_NET) {
if(hwnet || pnetserver) NetDisconnect();
}
+
+ if (curid == ID_PAGE_SCHEME)
+ ammoSchemeModel->Save();
}
void HWForm::btnExitPressed()
@@ -365,8 +367,6 @@
void HWForm::btnExitClicked()
{
- ammoSchemeModel->Save();
-
if (eggTimer.elapsed() < 3000)
close();
else
--- a/QTfrontend/pages.cpp Wed Mar 18 21:42:50 2009 +0000
+++ b/QTfrontend/pages.cpp Wed Mar 18 21:43:22 2009 +0000
@@ -925,20 +925,21 @@
mapper = new QDataWidgetMapper(this);
BtnBack = addButton(":/res/Exit.png", pageLayout, 15, 0, true);
- BtnNew = addButton(tr("New"), pageLayout, 15, 1);
- BtnPrev = addButton(tr("Prev"), pageLayout, 15, 2);
- BtnNext = addButton(tr("Next"), pageLayout, 15, 3);
- BtnSave = addButton(":/res/Save.png", pageLayout, 15, 4, true);
+ BtnNew = addButton(tr("New"), pageLayout, 15, 2);
+ BtnDelete = addButton(tr("Delete"), pageLayout, 15, 3);
- connect(BtnSave, SIGNAL(clicked()), mapper, SLOT(toFirst()));
+ selectScheme = new QComboBox(this);
+ pageLayout->addWidget(selectScheme, 15, 1);
+
connect(BtnNew, SIGNAL(clicked()), this, SLOT(newRow()));
- connect(BtnPrev, SIGNAL(clicked()), mapper, SLOT(toPrevious()));
- connect(BtnNext, SIGNAL(clicked()), mapper, SLOT(toNext()));
+ connect(BtnDelete, SIGNAL(clicked()), this, SLOT(deleteRow()));
+ connect(selectScheme, SIGNAL(currentIndexChanged(int)), mapper, SLOT(setCurrentIndex(int)));
}
void PageScheme::setModel(QAbstractItemModel * model)
{
mapper->setModel(model);
+ selectScheme->setModel(model);
mapper->addMapping(LE_name, 0);
mapper->addMapping(CB_mode_Forts, 1);
@@ -962,5 +963,11 @@
{
QAbstractItemModel * model = mapper->model();
model->insertRow(model->rowCount());
- mapper->toLast();
+ selectScheme->setCurrentIndex(model->rowCount() - 1);
}
+
+void PageScheme::deleteRow()
+{
+ QAbstractItemModel * model = mapper->model();
+ model->removeRow(selectScheme->currentIndex());
+}
--- a/QTfrontend/pages.h Wed Mar 18 21:42:50 2009 +0000
+++ b/QTfrontend/pages.h Wed Mar 18 21:43:22 2009 +0000
@@ -409,8 +409,7 @@
QPushButton * BtnBack;
QPushButton * BtnNew;
- QPushButton * BtnPrev;
- QPushButton * BtnNext;
+ QPushButton * BtnDelete;
QPushButton * BtnSave;
void setModel(QAbstractItemModel * model);
@@ -432,9 +431,11 @@
QSpinBox * SB_SuddenDeath;
FreqSpinBox * SB_CaseProb;
QLineEdit * LE_name;
+ QComboBox * selectScheme;
private slots:
void newRow();
+ void deleteRow();
};
#endif // PAGES_H