- Share much code between models
authorunc0rr
Sat, 15 Dec 2007 20:28:58 +0000
changeset 668 0d7683a66d61
parent 667 194dc62d1519
child 669 741e7490d32b
- Share much code between models - Update some labels
QTfrontend/hwform.cpp
QTfrontend/netserverslist.cpp
QTfrontend/netserverslist.h
QTfrontend/netudpwidget.cpp
QTfrontend/netudpwidget.h
QTfrontend/netwwwwidget.cpp
QTfrontend/netwwwwidget.h
QTfrontend/pages.cpp
--- a/QTfrontend/hwform.cpp	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Dec 15 20:28:58 2007 +0000
@@ -91,7 +91,6 @@
 	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
 
 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
-	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnectServer()));
 	connect(ui.pageNet->BtnSpecifyServer,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
 	connect(ui.pageNet->BtnNetSvrStart,	SIGNAL(clicked()),	this, SLOT(GoToNetServer()));
 	connect(ui.pageNet,	SIGNAL(connectClicked(const QString &, quint16)),	this, SLOT(NetConnectServer(const QString &, quint16)));
--- a/QTfrontend/netserverslist.cpp	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netserverslist.cpp	Sat Dec 15 20:28:58 2007 +0000
@@ -31,3 +31,38 @@
 {
 
 }
+
+QVariant HWNetServersModel::headerData(int section,
+            Qt::Orientation orientation, int role) const
+{
+	if (role != Qt::DisplayRole)
+		return QVariant();
+
+	if (orientation == Qt::Horizontal)
+	{
+		switch (section)
+		{
+			case 0: return tr("Title");
+			case 1: return tr("IP");
+			case 2: return tr("Port");
+			default: return QVariant();
+		}
+	} else
+		return QString("%1").arg(section + 1);
+}
+
+int HWNetServersModel::rowCount(const QModelIndex &parent) const
+{
+	if (parent.isValid())
+		return 0;
+	else
+		return games.size();
+}
+
+int HWNetServersModel::columnCount(const QModelIndex & parent) const
+{
+	if (parent.isValid())
+		return 0;
+	else
+		return 3;
+}
--- a/QTfrontend/netserverslist.h	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netserverslist.h	Sat Dec 15 20:28:58 2007 +0000
@@ -20,6 +20,7 @@
 #define _NET_SERVERSLIST_INCLUDED
 
 #include <QAbstractTableModel>
+#include <QStringList>
 
 class HWNetServersModel : public QAbstractTableModel
 {
@@ -28,8 +29,15 @@
 public:
 	HWNetServersModel(QObject *parent = 0);
 
+	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+	int rowCount(const QModelIndex & parent) const;
+	int columnCount(const QModelIndex & parent) const;
+
 public slots:
 	virtual void updateList();
+
+protected:
+	QList<QStringList> games;
 };
 
 #endif // _NET_SERVERSLIST_INCLUDED
--- a/QTfrontend/netudpwidget.cpp	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netudpwidget.cpp	Sat Dec 15 20:28:58 2007 +0000
@@ -69,38 +69,3 @@
 
 	return games[index.row()][index.column()];
 }
-
-QVariant HWNetUdpModel::headerData(int section,
-            Qt::Orientation orientation, int role) const
-{
-	if (role != Qt::DisplayRole)
-		return QVariant();
-
-	if (orientation == Qt::Horizontal)
-	{
-		switch (section)
-		{
-			case 0: return tr("Title");
-			case 1: return tr("IP");
-			case 2: return tr("Port");
-			default: return QVariant();
-		}
-	} else
-		return QString("%1").arg(section + 1);
-}
-
-int HWNetUdpModel::rowCount(const QModelIndex &parent) const
-{
-	if (parent.isValid())
-		return 0;
-	else
-		return games.size();
-}
-
-int HWNetUdpModel::columnCount(const QModelIndex & parent) const
-{
-	if (parent.isValid())
-		return 0;
-	else
-		return 3;
-}
--- a/QTfrontend/netudpwidget.h	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netudpwidget.h	Sat Dec 15 20:28:58 2007 +0000
@@ -20,7 +20,6 @@
 #ifndef _NET_UDPWIDGET_INCLUDED
 #define _NET_UDPWIDGET_INCLUDED
 
-#include <QStringList>
 #include "netserverslist.h"
 
 class QUdpSocket;
@@ -33,9 +32,6 @@
 	HWNetUdpModel(QObject *parent = 0);
 
 	QVariant data(const QModelIndex &index, int role) const;
-	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
-	int rowCount(const QModelIndex & parent) const;
-	int columnCount(const QModelIndex & parent) const;
 
 public slots:
 	void updateList();
@@ -45,7 +41,6 @@
 
 private:
 	QUdpSocket* pUdpSocket;
-	QList<QStringList> games;
 };
 
 #endif // _NET_UDPWIDGET_INCLUDED
--- a/QTfrontend/netwwwwidget.cpp	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netwwwwidget.cpp	Sat Dec 15 20:28:58 2007 +0000
@@ -45,41 +45,6 @@
 	return games[index.row()][index.column()];
 }
 
-QVariant HWNetWwwModel::headerData(int section,
-            Qt::Orientation orientation, int role) const
-{
-	if (role != Qt::DisplayRole)
-		return QVariant();
-
-	if (orientation == Qt::Horizontal)
-	{
-		switch (section)
-		{
-			case 0: return tr("Title");
-			case 1: return tr("IP");
-			case 2: return tr("Port");
-			default: return QVariant();
-		}
-	} else
-		return QString("%1").arg(section + 1);
-}
-
-int HWNetWwwModel::rowCount(const QModelIndex &parent) const
-{
-	if (parent.isValid())
-		return 0;
-	else
-		return games.size();
-}
-
-int HWNetWwwModel::columnCount(const QModelIndex & parent) const
-{
-	if (parent.isValid())
-		return 0;
-	else
-		return 3;
-}
-
 void HWNetWwwModel::updateList()
 {
 	QString request = QString("protocol_version=%1")
--- a/QTfrontend/netwwwwidget.h	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/netwwwwidget.h	Sat Dec 15 20:28:58 2007 +0000
@@ -19,7 +19,6 @@
 #ifndef _NET_WWWWIDGET_INCLUDED
 #define _NET_WWWWIDGET_INCLUDED
 
-#include <QStringList>
 #include "netserverslist.h"
 
 class QHttp;
@@ -32,13 +31,9 @@
 	HWNetWwwModel(QObject *parent = 0);
 
 	QVariant data(const QModelIndex &index, int role) const;
-	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
-	int rowCount(const QModelIndex & parent) const;
-	int columnCount(const QModelIndex & parent) const;
 
 private:
 	QHttp * http;
-	QList<QStringList> games;
 
 private slots:
 	void onClientRead(int id, bool error);
--- a/QTfrontend/pages.cpp	Sat Dec 15 20:08:08 2007 +0000
+++ b/QTfrontend/pages.cpp	Sat Dec 15 20:28:58 2007 +0000
@@ -437,16 +437,16 @@
 
 	QGroupBox * NetTypeGroupBox = new QGroupBox(this);
 	NetTypeGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
-	NetTypeGroupBox->setTitle(QGroupBox::tr("Connection type"));
+	NetTypeGroupBox->setTitle(QGroupBox::tr("Servers list"));
 	pageLayout->addWidget(NetTypeGroupBox, 0, 1);
 
 	QVBoxLayout * GBTlayout = new QVBoxLayout(NetTypeGroupBox);
 	rbLocalGame = new QRadioButton(NetTypeGroupBox);
-	rbLocalGame->setText(tr("Local game"));
+	rbLocalGame->setText(tr("Local"));
 	rbLocalGame->setChecked(true);
 	GBTlayout->addWidget(rbLocalGame);
 	rbInternetGame = new QRadioButton(NetTypeGroupBox);
-	rbInternetGame->setText(tr("Internet game"));
+	rbInternetGame->setText(tr("Internet"));
 	GBTlayout->addWidget(rbInternetGame);
 
 	ConnGroupBox = new QGroupBox(this);
@@ -481,6 +481,7 @@
 	pageLayout->addWidget(BtnBack, 3, 0);
 
 	connect(rbLocalGame, SIGNAL(toggled(bool)), this, SLOT(updateServersList()));
+	connect(BtnNetConnect, SIGNAL(clicked()), this, SLOT(slotConnect()));
 }
 
 void PageNet::updateServersList()