Continue work on new schemes implementation
authorunc0rr
Wed, 11 Mar 2009 14:32:28 +0000
changeset 1884 40e59e9f82ce
parent 1883 7c7476f56114
child 1885 75489216b5b0
Continue work on new schemes implementation
QTfrontend/ammoSchemeModel.cpp
QTfrontend/ammoSchemeModel.h
QTfrontend/gamecfgwidget.cpp
QTfrontend/hwform.h
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/ui_hwform.cpp
QTfrontend/ui_hwform.h
--- a/QTfrontend/ammoSchemeModel.cpp	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.cpp	Wed Mar 11 14:32:28 2009 +0000
@@ -22,7 +22,16 @@
 AmmoSchemeModel::AmmoSchemeModel(QObject* parent) :
   QAbstractTableModel(parent)
 {
+	defaultScheme
+		<< "Default"
+		<< "45"
+		<< "0"
+		<< "0"
+		<< "0"
+		<< "0"
+		;
 
+	schemes.append(defaultScheme);
 }
 
 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -43,7 +52,7 @@
 	if (parent.isValid())
 		return 0;
 	else
-		return 3;
+		return defaultScheme.size();
 }
 
 Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
@@ -56,5 +65,42 @@
 
 bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
 {
+	if (!index.isValid() || index.row() < 0
+		|| index.row() >= schemes.size()
+		|| index.column() >= defaultScheme.size()
+		|| role != Qt::DisplayRole)
+		return false;
+
+	schemes[index.row()][index.column()] = value.toString();
 	emit dataChanged(index, index);
+	return true;
 }
+
+bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
+{
+	beginInsertRows(parent, row, row);
+
+	schemes.insert(row, defaultScheme);
+
+	endInsertRows();
+}
+
+bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
+{
+	beginRemoveRows(parent, row, row);
+
+	schemes.removeAt(row);
+
+	endRemoveRows();
+}
+
+QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const
+{
+	if (!index.isValid() || index.row() < 0
+		|| index.row() >= schemes.size()
+		|| index.column() >= defaultScheme.size()
+		|| role != Qt::DisplayRole)
+		return QVariant();
+
+	return schemes[index.row()][index.column()];
+}
--- a/QTfrontend/ammoSchemeModel.h	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.h	Wed Mar 11 14:32:28 2009 +0000
@@ -34,12 +34,18 @@
 	int columnCount(const QModelIndex & parent) const;
 	Qt::ItemFlags flags(const QModelIndex & index) const;
 	bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
+	bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
+	bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
+	QVariant data(const QModelIndex &index, int role) const;
 
 signals:
 	void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
 
 protected:
 	QList<QStringList> schemes;
+
+private:
+	QStringList defaultScheme;
 };
 
 #endif // _AMMO_SCHEME_MODEL_INCLUDED
--- a/QTfrontend/gamecfgwidget.cpp	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Wed Mar 11 14:32:28 2009 +0000
@@ -23,10 +23,12 @@
 #include <QSpinBox>
 #include <QLabel>
 #include <QMessageBox>
+#include <QTableView>
 
 #include "gamecfgwidget.h"
 #include "igbox.h"
 #include "hwconsts.h"
+#include "ammoSchemeModel.h"
 
 GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
   QGroupBox(parent), mainLayout(this)
@@ -42,10 +44,14 @@
 	mainLayout.addWidget(GBoxOptions);
 
 	QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
+
+	QTableView * tv = new QTableView(this);
+	tv->setModel(new AmmoSchemeModel);
+	GBoxOptionsLayout->addWidget(tv, 0, 0, 1, 2);
 	
 	CB_mode_Forts = new QCheckBox(GBoxOptions);
 	CB_mode_Forts->setText(QCheckBox::tr("Forts mode"));
-	GBoxOptionsLayout->addWidget(CB_mode_Forts, 0, 0, 1, 2);
+	GBoxOptionsLayout->addWidget(CB_mode_Forts, 9, 0, 1, 2);
 
 	CB_teamsDivide = new QCheckBox(GBoxOptions);
 	CB_teamsDivide->setText(QCheckBox::tr("Divide teams"));
--- a/QTfrontend/hwform.h	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/hwform.h	Wed Mar 11 14:32:28 2009 +0000
@@ -115,7 +115,8 @@
 		ID_PAGE_NETSERVER       = 12,
 		ID_PAGE_INGAME          = 13,
 		ID_PAGE_ROOMSLIST       = 14,
-		ID_PAGE_CONNECTING      = 15
+		ID_PAGE_CONNECTING      = 15,
+		ID_PAGE_SCHEME          = 16
 		};
 	HWGame * game;
 	HWTeam * editedTeam;
--- a/QTfrontend/pages.cpp	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/pages.cpp	Wed Mar 11 14:32:28 2009 +0000
@@ -843,3 +843,9 @@
 {
 	QGridLayout * pageLayout = new QGridLayout(this);
 }
+
+PageScheme::PageScheme(QWidget* parent) :
+	AbstractPage(parent)
+{
+	QGridLayout * pageLayout = new QGridLayout(this);
+}
--- a/QTfrontend/pages.h	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/pages.h	Wed Mar 11 14:32:28 2009 +0000
@@ -395,4 +395,12 @@
 	PageConnecting(QWidget* parent = 0);
 };
 
+class PageScheme : public AbstractPage
+{
+	Q_OBJECT
+
+public:
+	PageScheme(QWidget* parent = 0);
+};
+
 #endif // PAGES_H
--- a/QTfrontend/ui_hwform.cpp	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/ui_hwform.cpp	Wed Mar 11 14:32:28 2009 +0000
@@ -103,4 +103,7 @@
 
 	pageConnecting = new PageConnecting();
 	Pages->addWidget(pageConnecting);
+
+	pageScheme = new PageScheme();
+	Pages->addWidget(pageScheme);
 }
--- a/QTfrontend/ui_hwform.h	Tue Mar 10 21:57:33 2009 +0000
+++ b/QTfrontend/ui_hwform.h	Wed Mar 11 14:32:28 2009 +0000
@@ -36,6 +36,7 @@
 class PageInGame;
 class PageRoomsList;
 class PageConnecting;
+class PageScheme;
 class QStackedLayout;
 class QFont;
 class QWidget;
@@ -63,6 +64,7 @@
 	PageInGame *pageInGame;
 	PageRoomsList *pageRoomsList;
 	PageConnecting *pageConnecting;
+	PageScheme *pageScheme;
 
 	QStackedLayout *Pages;
 	QFont *font14;