Start switching to rooms list model. To be continued.
authorunc0rr
Thu, 23 Feb 2012 00:46:03 +0400
changeset 6732 c906dc78091f
parent 6731 ddd391083f50
child 6733 5abbc345a82f
Start switching to rooms list model. To be continued.
QTfrontend/hwform.cpp
QTfrontend/model/roomslistmodel.cpp
QTfrontend/model/roomslistmodel.h
QTfrontend/net/newnetclient.cpp
QTfrontend/net/newnetclient.h
QTfrontend/ui/page/pageroomslist.cpp
QTfrontend/ui/page/pageroomslist.h
project_files/hedgewars.pro
--- a/QTfrontend/hwform.cpp	Wed Feb 22 18:13:14 2012 +0100
+++ b/QTfrontend/hwform.cpp	Thu Feb 23 00:46:03 2012 +0400
@@ -88,6 +88,7 @@
 #include "xfire.h"
 #include "drawmapwidget.h"
 #include "mouseoverfilter.h"
+#include "roomslistmodel.h"
 
 #include "HWDataManager.h"
 
@@ -1040,6 +1041,7 @@
     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
 
 // rooms list page stuff
+    ui.pageRoomsList->roomsList->setModel(hwnet->roomsListModel());
     connect(hwnet, SIGNAL(roomsList(const QStringList&)),
             ui.pageRoomsList, SLOT(setRoomsList(const QStringList&)), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(adminAccess(bool)),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/model/roomslistmodel.cpp	Thu Feb 23 00:46:03 2012 +0400
@@ -0,0 +1,51 @@
+#include "roomslistmodel.h"
+
+RoomsListModel::RoomsListModel(QObject *parent) :
+    QAbstractTableModel(parent)
+{
+    m_headerData =
+    QStringList()
+     << tr("Room Name")
+     << tr("C")
+     << tr("T")
+     << tr("Owner")
+     << tr("Map")
+     << tr("Rules")
+     << tr("Weapons");
+}
+
+QVariant RoomsListModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+    if(orientation == Qt::Vertical || role != Qt::DisplayRole)
+        return QVariant();
+    else
+        return QVariant(m_headerData.at(section));
+}
+
+int RoomsListModel::rowCount(const QModelIndex & parent) const
+{
+    if(parent.isValid())
+        return 0;
+    else
+        return m_data.size();
+}
+
+int RoomsListModel::columnCount(const QModelIndex & parent) const
+{
+    if(parent.isValid())
+        return 0;
+    else
+        return 7;
+}
+
+QVariant RoomsListModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid() || index.row() < 0
+            || index.row() >= m_data.size()
+            || index.column() >= 7
+            || (role != Qt::EditRole && role != Qt::DisplayRole)
+       )
+        return QVariant();
+
+    return m_data.at(index.row()).at(index.column());
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/model/roomslistmodel.h	Thu Feb 23 00:46:03 2012 +0400
@@ -0,0 +1,23 @@
+#ifndef ROOMSLISTMODEL_H
+#define ROOMSLISTMODEL_H
+
+#include <QAbstractTableModel>
+#include <QStringList>
+
+class RoomsListModel : public QAbstractTableModel
+{
+    Q_OBJECT
+public:
+    explicit RoomsListModel(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;
+    QVariant data(const QModelIndex &index, int role) const;
+
+private:
+    QList<QStringList> m_data;
+    QStringList m_headerData;
+};
+
+#endif // ROOMSLISTMODEL_H
--- a/QTfrontend/net/newnetclient.cpp	Wed Feb 22 18:13:14 2012 +0100
+++ b/QTfrontend/net/newnetclient.cpp	Thu Feb 23 00:46:03 2012 +0400
@@ -25,6 +25,7 @@
 #include "newnetclient.h"
 #include "proto.h"
 #include "game.h"
+#include "roomslistmodel.h"
 
 char delimeter='\n';
 
@@ -34,6 +35,7 @@
     loginStep(0),
     netClientState(Disconnected)
 {
+    m_roomsListModel = new RoomsListModel(this);
 // socket stuff
     connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
     connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
@@ -831,3 +833,8 @@
         }
     }
 }
+
+RoomsListModel * HWNewNet::roomsListModel()
+{
+    return m_roomsListModel;
+}
--- a/QTfrontend/net/newnetclient.h	Wed Feb 22 18:13:14 2012 +0100
+++ b/QTfrontend/net/newnetclient.h	Thu Feb 23 00:46:03 2012 +0400
@@ -31,6 +31,7 @@
 class GameUIConfig;
 class GameCFGWidget;
 class TeamSelWidget;
+class RoomsListModel;
 
 extern char delimeter;
 
@@ -53,6 +54,7 @@
         QString getNick();
         QString getRoom();
         QString getHost();
+        RoomsListModel * roomsListModel();
 
     private:
         bool isChief;
@@ -62,6 +64,7 @@
         QTcpSocket NetSocket;
         QString seed;
         bool m_game_connected;
+        RoomsListModel * m_roomsListModel;
 
         template <typename T>
         void SendCfgStrNet(T a)
--- a/QTfrontend/ui/page/pageroomslist.cpp	Wed Feb 22 18:13:14 2012 +0100
+++ b/QTfrontend/ui/page/pageroomslist.cpp	Thu Feb 23 00:46:03 2012 +0400
@@ -24,7 +24,7 @@
 #include <QLineEdit>
 #include <QMessageBox>
 #include <QHeaderView>
-#include <QTableWidget>
+#include <QTableView>
 
 #include "ammoSchemeModel.h"
 #include "pageroomslist.h"
@@ -44,7 +44,7 @@
     newRoomLayout->addWidget(roomName);
     pageLayout->addLayout(newRoomLayout, 0, 0, 1, 2);
 
-    roomsList = new QTableWidget(this);
+    roomsList = new QTableView(this);
     roomsList->setSelectionBehavior(QAbstractItemView::SelectRows);
     roomsList->verticalHeader()->setVisible(false);
     roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
@@ -192,6 +192,7 @@
     BtnAdmin->setVisible(flag);
 }
 
+/*
 void PageRoomsList::setRoomsList(const QStringList & list)
 {
     QBrush red(QColor(255, 0, 0));
@@ -209,14 +210,7 @@
     roomsList->clear();
     roomsList->setColumnCount(7);
     roomsList->setHorizontalHeaderLabels(
-        QStringList() <<
-        QTableWidget::tr("Room Name") <<
-        QTableWidget::tr("C") <<
-        QTableWidget::tr("T") <<
-        QTableWidget::tr("Owner") <<
-        QTableWidget::tr("Map") <<
-        QTableWidget::tr("Rules") <<
-        QTableWidget::tr("Weapons")
+
     );
 
     // set minimum sizes
@@ -411,6 +405,7 @@
 
 //  roomsList->resizeColumnsToContents();
 }
+*/
 
 void PageRoomsList::onCreateClick()
 {
@@ -425,6 +420,7 @@
 
 void PageRoomsList::onJoinClick()
 {
+    /*
     QTableWidgetItem * curritem = roomsList->item(roomsList->currentRow(), 0);
     if (!curritem)
     {
@@ -453,6 +449,7 @@
     {
         emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString());
     }
+*/
 }
 
 void PageRoomsList::onRefreshClick()
--- a/QTfrontend/ui/page/pageroomslist.h	Wed Feb 22 18:13:14 2012 +0100
+++ b/QTfrontend/ui/page/pageroomslist.h	Thu Feb 23 00:46:03 2012 +0400
@@ -23,6 +23,7 @@
 
 class HWChatWidget;
 class AmmoSchemeModel;
+class QTableView;
 
 class PageRoomsList : public AbstractPage
 {
@@ -36,7 +37,7 @@
 
         QLineEdit * roomName;
         QLineEdit * searchText;
-        QTableWidget * roomsList;
+        QTableView * roomsList;
         QPushButton * BtnCreate;
         QPushButton * BtnJoin;
         QPushButton * BtnRefresh;
@@ -50,7 +51,6 @@
 
     public slots:
         void setAdmin(bool);
-        void setRoomsList(const QStringList & list);
         void setUser(const QString & nickname);
         void updateNickCounter(int cnt);
 
--- a/project_files/hedgewars.pro	Wed Feb 22 18:13:14 2012 +0100
+++ b/project_files/hedgewars.pro	Thu Feb 23 00:46:03 2012 +0400
@@ -99,7 +99,8 @@
     ../QTfrontend/ui/mouseoverfilter.h \
     ../QTfrontend/ui/qpushbuttonwithsound.h \
     ../QTfrontend/ui/widget/qpushbuttonwithsound.h \
-    ../QTfrontend/ui/page/pagefeedback.h
+    ../QTfrontend/ui/page/pagefeedback.h \
+    ../QTfrontend/model/roomslistmodel.h
 
 SOURCES += ../QTfrontend/model/ammoSchemeModel.cpp \
     ../QTfrontend/model/themesmodel.cpp \
@@ -176,7 +177,8 @@
     ../QTfrontend/hwconsts.cpp \
     ../QTfrontend/ui/mouseoverfilter.cpp \
     ../QTfrontend/ui/widget/qpushbuttonwithsound.cpp \
-    ../QTfrontend/ui/page/pagefeedback.cpp
+    ../QTfrontend/ui/page/pagefeedback.cpp \
+    ../QTfrontend/model/roomslistmodel.cpp
 
 win32 {
     SOURCES += ../QTfrontend/xfire.cpp