Start move from custom widgets to custom models
authorunc0rr
Sat, 15 Dec 2007 19:40:50 +0000
changeset 665 5c7bfc8bac6a
parent 664 f0af2401f981
child 666 07fa9a74a074
Start move from custom widgets to custom models
QTfrontend/hwform.cpp
QTfrontend/netserverslist.cpp
QTfrontend/netserverslist.h
QTfrontend/netudpwidget.cpp
QTfrontend/netudpwidget.h
QTfrontend/netwwwwidget.cpp
QTfrontend/netwwwwidget.h
QTfrontend/pages.cpp
QTfrontend/pages.h
--- a/QTfrontend/hwform.cpp	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Dec 15 19:40:50 2007 +0000
@@ -197,7 +197,6 @@
 void HWForm::GoToNet()
 {
 	ui.pageNet->updateServersList();
-	connect(ui.pageNet->netServersWidget->serversList,	SIGNAL(doubleClicked (const QModelIndex &)),	this, SLOT(NetConnectServer()));
 
 	GoToPage(ID_PAGE_NET);
 }
--- a/QTfrontend/netserverslist.cpp	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netserverslist.cpp	Sat Dec 15 19:40:50 2007 +0000
@@ -21,15 +21,13 @@
 
 #include "netserverslist.h"
 
-HWNetServersWidget::HWNetServersWidget(QWidget* parent) :
-  QWidget(parent), mainLayout(this)
-{
-	serversList = new QTableView(this);
-	mainLayout.setMargin(0);
-	mainLayout.addWidget(serversList);
-}
-
-void HWNetServersWidget::updateList()
+HWNetServersModel::HWNetServersModel(QObject* parent) :
+  QAbstractTableModel(parent)
 {
 
 }
+
+void HWNetServersModel::updateList()
+{
+
+}
--- a/QTfrontend/netserverslist.h	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netserverslist.h	Sat Dec 15 19:40:50 2007 +0000
@@ -19,24 +19,17 @@
 #ifndef _NET_SERVERSLIST_INCLUDED
 #define _NET_SERVERSLIST_INCLUDED
 
-#include <QWidget>
-#include <QVBoxLayout>
-#include <QTableView>
+#include <QAbstractTableModel>
 
-class HWNetServersWidget : public QWidget
+class HWNetServersModel : public QAbstractTableModel
 {
 	Q_OBJECT
 
 public:
-	HWNetServersWidget (QWidget *parent = 0);
-
-	QTableView* serversList;
+	HWNetServersModel(QObject *parent = 0);
 
 public slots:
 	virtual void updateList();
-
-private:
-	QVBoxLayout mainLayout;
 };
 
 #endif // _NET_SERVERSLIST_INCLUDED
--- a/QTfrontend/netudpwidget.cpp	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netudpwidget.cpp	Sat Dec 15 19:40:50 2007 +0000
@@ -21,7 +21,7 @@
 
 #include "netudpwidget.h"
 
-HWNetUdpWidget::HWNetUdpWidget(QWidget* parent) :
+/*HWNetUdpWidget::HWNetUdpWidget(QWidget* parent) :
   HWNetServersWidget(parent)
 {
   pUdpSocket = new QUdpSocket(this);
@@ -49,3 +49,4 @@
     }
   }
 }
+*/
\ No newline at end of file
--- a/QTfrontend/netudpwidget.h	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netudpwidget.h	Sat Dec 15 19:40:50 2007 +0000
@@ -23,7 +23,7 @@
 #include <QVBoxLayout>
 
 #include "netserverslist.h"
-
+/*
 class QUdpSocket;
 class QListWidget;
 
@@ -43,5 +43,5 @@
  private:
   QUdpSocket* pUdpSocket;
 };
-
+*/
 #endif // _NET_UDPWIDGET_INCLUDED
--- a/QTfrontend/netwwwwidget.cpp	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netwwwwidget.cpp	Sat Dec 15 19:40:50 2007 +0000
@@ -17,29 +17,17 @@
  */
 
 #include <QHttp>
-#include <QListWidget>
-#include <QDebug>
 #include <QDomDocument>
 #include <QDomElement>
 #include <QDomNode>
 #include <QDomText>
+#include <QDebug>
 
 #include "netwwwwidget.h"
 #include "hwconsts.h"
 
-HWNetWwwWidget::HWNetWwwWidget(QWidget* parent) :
-  HWNetServersWidget(parent)
-{
-	serversList->setModel(new HWNetWwwModel);
-}
 
-void HWNetWwwWidget::updateList()
-{
-	static_cast<HWNetWwwModel *>(serversList->model())->updateList();
-}
-
-
-HWNetWwwModel::HWNetWwwModel(QObject *parent) : QAbstractTableModel(parent)
+HWNetWwwModel::HWNetWwwModel(QObject *parent) : HWNetServersModel(parent)
 {
 	http = new QHttp(this);
 	http->setHost("www.hedgewars.org", 80);
--- a/QTfrontend/netwwwwidget.h	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/netwwwwidget.h	Sat Dec 15 19:40:50 2007 +0000
@@ -20,26 +20,12 @@
 #define _NET_WWWWIDGET_INCLUDED
 
 #include <QAbstractTableModel>
-#include <QFile>
-#include <QDateTime>
-#include <QVector>
+#include <QStringList>
 #include "netserverslist.h"
 
-class QListWidget;
 class QHttp;
 
-class HWNetWwwWidget : public HWNetServersWidget
-{
- 	Q_OBJECT
-
-public:
-	HWNetWwwWidget(QWidget *parent = 0);
-
-public slots:
-	void updateList();
-};
-
-class HWNetWwwModel : public QAbstractTableModel
+class HWNetWwwModel : public HWNetServersModel
 {
 	Q_OBJECT
 
--- a/QTfrontend/pages.cpp	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/pages.cpp	Sat Dec 15 19:40:50 2007 +0000
@@ -29,6 +29,7 @@
 #include <QSpinBox>
 #include <QTextEdit>
 #include <QRadioButton>
+#include <QTableView>
 
 #include "pages.h"
 #include "sdlkeys.h"
@@ -461,7 +462,8 @@
 	BtnNetConnect->setText(QPushButton::tr("Connect"));
 	GBClayout->addWidget(BtnNetConnect, 2, 2);
 
-	netServersWidget = 0;
+	tvServersList = new QTableView(ConnGroupBox);
+	GBClayout->addWidget(tvServersList, 1, 0, 1, 3);
 
 	BtnUpdateSList = new QPushButton(ConnGroupBox);
 	BtnUpdateSList->setFont(*font14);
@@ -483,23 +485,22 @@
 
 void PageNet::updateServersList()
 {
-	if (netServersWidget) delete netServersWidget;
+//	if (tvServersList->model()) delete tvServersList->model();
 
 	if (rbLocalGame->isChecked())
-		netServersWidget = new HWNetUdpWidget(ConnGroupBox);
-	else
-		netServersWidget = new HWNetWwwWidget(ConnGroupBox);
+//;		netServersWidget = new HWNetUdpWidget(ConnGroupBox);
+//	else
+		tvServersList->setModel(new HWNetWwwModel());
 
-	netServersWidget->updateList();
-	GBClayout->addWidget(netServersWidget, 1, 0, 1, 3);
+	static_cast<HWNetServersModel *>(tvServersList->model())->updateList();
 
-	connect(BtnUpdateSList, SIGNAL(clicked()), netServersWidget, SLOT(updateList()));
-	connect(netServersWidget->serversList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotConnect()));
+	connect(BtnUpdateSList, SIGNAL(clicked()), static_cast<HWNetServersModel *>(tvServersList->model()), SLOT(updateList()));
+//	connect(netServersWidget->serversList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotConnect()));
 }
 
 void PageNet::slotConnect()
 {
-	emit connectClicked();
+	emit connectClicked("localhost", 46631);
 }
 
 PageNetServer::PageNetServer(QWidget* parent) : QWidget(parent)
--- a/QTfrontend/pages.h	Sat Dec 15 18:58:55 2007 +0000
+++ b/QTfrontend/pages.h	Sat Dec 15 19:40:50 2007 +0000
@@ -24,27 +24,27 @@
 #include "binds.h"
 #include "mapContainer.h"
 
-class GameCFGWidget;
 class QPushButton;
 class QGroupBox;
 class QComboBox;
 class QLabel;
 class QToolBox;
 class QLineEdit;
+class QListWidget;
+class QCheckBox;
+class QSpinBox;
+class QTextEdit;
+class QRadioButton;
+class QTableView;
+
+class GameCFGWidget;
 class TeamSelWidget;
 class DemosList;
-class QListWidget;
-class QCheckBox;
 class SquareLabel;
 class About;
-class QSpinBox;
 class FPSEdit;
-class HWNetUdpWidget;
-class QTextEdit;
 class HWChatWidget;
 class SelWeaponWidget;
-class HWNetServersWidget;
-class QRadioButton;
 
 class PageMain : public QWidget
 {
@@ -160,7 +160,7 @@
 	PageNet(QWidget* parent = 0);
 
 	QPushButton* BtnUpdateSList;
-	HWNetServersWidget* netServersWidget;
+	QTableView * tvServersList;
 	QPushButton * BtnBack;
 	QPushButton * BtnNetConnect;
 	QPushButton * BtnNetSvrStart;
@@ -179,7 +179,7 @@
 	void updateServersList();
 
 signals:
-	void connectClicked();
+	void connectClicked(const QString & host, quint16 port);
 };
 
 class PageNetServer : public QWidget