room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
--- a/QTfrontend/model/roomslistmodel.cpp Wed May 02 11:43:43 2012 +0100
+++ b/QTfrontend/model/roomslistmodel.cpp Wed May 02 13:00:10 2012 +0200
@@ -93,12 +93,13 @@
// not a role we have data for
if (role != Qt::DisplayRole)
// only custom-align counters
- if ((role != Qt::TextAlignmentRole) || (column < 2) || (column > 3))
- // only decorate name column
- if ((role != Qt::DecorationRole) || (column != 1))
- // only dye map column
- if ((role != Qt::ForegroundRole) || (column != 5))
- return QVariant();
+ if ((role != Qt::TextAlignmentRole)
+ || ((column != PlayerCountColumn) && (column != TeamCountColumn)))
+ // only decorate name column
+ if ((role != Qt::DecorationRole) || (column != NameColumn))
+ // only dye map column
+ if ((role != Qt::ForegroundRole) || (column != MapColumn))
+ return QVariant();
// decorate room name based on room state
if (role == Qt::DecorationRole)
@@ -206,7 +207,7 @@
int i = 0;
// search for record with matching room name
- while(m_data[i].at(1) != name)
+ while(m_data[i].at(NameColumn) != name)
{
i++;
if(i >= size)
@@ -253,10 +254,10 @@
// for matters of less memory usage and quicker access store
// the boolean string as either "t" or empty
- if (info[0].toLower() == "true")
- result[0] = "t";
+ if (info[StateColumn].toLower() == "true")
+ result[StateColumn] = "t";
else
- result[0] = QString();
+ result[StateColumn] = QString();
return result;
}
--- a/QTfrontend/model/roomslistmodel.h Wed May 02 11:43:43 2012 +0100
+++ b/QTfrontend/model/roomslistmodel.h Wed May 02 13:00:10 2012 +0200
@@ -33,6 +33,19 @@
{
Q_OBJECT
public:
+ // if you add a column here, also incr. c_nColumns in constructor
+ // also adjust header in constructor to changes
+ enum Column {
+ StateColumn,
+ NameColumn,
+ PlayerCountColumn,
+ TeamCountColumn,
+ OwnerColumn,
+ MapColumn,
+ SchemeColumn,
+ WeaponsColumn
+ };
+
explicit RoomsListModel(QObject *parent = 0);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
--- a/QTfrontend/ui/page/pageroomslist.cpp Wed May 02 11:43:43 2012 +0100
+++ b/QTfrontend/ui/page/pageroomslist.cpp Wed May 02 13:00:10 2012 +0200
@@ -28,6 +28,8 @@
#include <QSortFilterProxyModel>
+#include "roomslistmodel.h"
+
#include "ammoSchemeModel.h"
#include "pageroomslist.h"
#include "hwconsts.h"
@@ -477,28 +479,28 @@
chatWidget->setUser(nickname);
}
-void PageRoomsList::setModel(QAbstractTableModel *model)
+void PageRoomsList::setModel(RoomsListModel *model)
{
roomsModel = new QSortFilterProxyModel(this);
roomsModel->setSourceModel(model);
roomsModel->setDynamicSortFilter(true);
roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive);
- roomsModel->sort(0, Qt::AscendingOrder);
+ roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder);
roomsList->setModel(roomsModel);
- roomsList->hideColumn(0);
+ roomsList->hideColumn(RoomsListModel::StateColumn);
QHeaderView * h = roomsList->horizontalHeader();
h->setSortIndicatorShown(true);
- h->setResizeMode(1, QHeaderView::Stretch);
- h->resizeSection(2, 32);
- h->resizeSection(3, 32);
- h->resizeSection(4, 100);
- h->resizeSection(5, 100);
- h->resizeSection(6, 100);
- h->resizeSection(7, 100);
+ h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
+ h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
+ h->resizeSection(RoomsListModel::TeamCountColumn, 32);
+ h->resizeSection(RoomsListModel::OwnerColumn, 100);
+ h->resizeSection(RoomsListModel::MapColumn, 100);
+ h->resizeSection(RoomsListModel::SchemeColumn, 100);
+ h->resizeSection(RoomsListModel::WeaponsColumn, 100);
connect(h, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
@@ -509,7 +511,8 @@
{
// three state sorting: asc -> dsc -> default (by room state)
if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
- roomsList->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
+ roomsList->horizontalHeader()->setSortIndicator(
+ RoomsListModel::StateColumn, Qt::AscendingOrder);
else
roomsModel->sort(logicalIndex, order);
}
--- a/QTfrontend/ui/page/pageroomslist.h Wed May 02 11:43:43 2012 +0100
+++ b/QTfrontend/ui/page/pageroomslist.h Wed May 02 13:00:10 2012 +0200
@@ -24,7 +24,7 @@
class HWChatWidget;
class AmmoSchemeModel;
class QTableView;
-
+class RoomsListModel;
class QSortFilterProxyModel;
class PageRoomsList : public AbstractPage
@@ -51,7 +51,7 @@
HWChatWidget * chatWidget;
QLabel * lblCount;
- void setModel(QAbstractTableModel * model);
+ void setModel(RoomsListModel * model);
public slots:
void setAdmin(bool);