--- a/QTfrontend/model/playerslistmodel.cpp Sun Oct 07 23:33:09 2012 +0400
+++ b/QTfrontend/model/playerslistmodel.cpp Sun Oct 07 23:59:55 2012 +0400
@@ -85,9 +85,11 @@
{
insertRow(rowCount());
- setData(index(rowCount() - 1), nickname);
+ QModelIndex mi = index(rowCount() - 1);
+ setData(mi, nickname);
- updateIcon(index(rowCount() - 1));
+ updateSortData(mi);
+ updateIcon(mi);
}
@@ -107,6 +109,11 @@
if(mil.size())
{
setData(mil[0], isSet, flagType);
+
+ if(flagType == Friend || flagType == ServerAdmin
+ || flagType == Ignore || flagType == RoomAdmin)
+ updateSortData(mil[0]);
+
updateIcon(mil[0]);
}
}
@@ -188,3 +195,16 @@
return iconsCache;
}
+
+void PlayersListModel::updateSortData(const QModelIndex & index)
+{
+ QString result = QString("%1%2%3%4%5")
+ .arg(1 - index.data(RoomAdmin).toInt())
+ .arg(1 - index.data(ServerAdmin).toInt())
+ .arg(1 - index.data(Friend).toInt())
+ .arg(index.data(Ignore).toInt())
+ .arg(index.data(Qt::DisplayRole).toString().toLower())
+ ;
+
+ setData(index, result, SortRole);
+}
--- a/QTfrontend/model/playerslistmodel.h Sun Oct 07 23:33:09 2012 +0400
+++ b/QTfrontend/model/playerslistmodel.h Sun Oct 07 23:59:55 2012 +0400
@@ -20,6 +20,10 @@
Ignore = Qt::UserRole + 5
};
+ enum SpecialRoles {
+ SortRole = Qt::UserRole + 100
+ };
+
explicit PlayersListModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
@@ -41,6 +45,7 @@
typedef QHash<int, QVariant> DataEntry;
QList<DataEntry> m_data;
void updateIcon(const QModelIndex & index);
+ void updateSortData(const QModelIndex & index);
};
#endif // PLAYERSLISTMODEL_H
--- a/QTfrontend/net/newnetclient.cpp Sun Oct 07 23:33:09 2012 +0400
+++ b/QTfrontend/net/newnetclient.cpp Sun Oct 07 23:59:55 2012 +0400
@@ -20,6 +20,7 @@
#include <QDebug>
#include <QInputDialog>
#include <QCryptographicHash>
+#include <QSortFilterProxyModel>
#include "hwconsts.h"
#include "newnetclient.h"
@@ -37,9 +38,22 @@
netClientState(Disconnected)
{
m_roomsListModel = new RoomsListModel(this);
- m_lobbyPlayersModel = new PlayersListModel(this);
- m_roomPlayersModel = new PlayersListModel(this);
-// socket stuff
+
+ m_playersModel = new PlayersListModel(this);
+
+ m_lobbyPlayersModel = new QSortFilterProxyModel(this);
+ m_lobbyPlayersModel->setSourceModel(m_playersModel);
+ m_lobbyPlayersModel->setSortRole(PlayersListModel::SortRole);
+ m_lobbyPlayersModel->setDynamicSortFilter(true);
+ m_lobbyPlayersModel->sort(0);
+
+ m_roomPlayersModel = new QSortFilterProxyModel(this);
+ m_roomPlayersModel->setSourceModel(m_playersModel);
+ m_roomPlayersModel->setSortRole(PlayersListModel::SortRole);
+ m_roomPlayersModel->setDynamicSortFilter(true);
+ m_roomPlayersModel->sort(0);
+
+ // socket stuff
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
@@ -379,7 +393,7 @@
else emit setMyReadyStatus(setFlag);
}
emit setReadyStatus(nick, setFlag);
- m_lobbyPlayersModel->setFlag(nick, PlayersListModel::Ready, setFlag);
+ m_playersModel->setFlag(nick, PlayersListModel::Ready, setFlag);
}
break;
@@ -387,7 +401,7 @@
case 'u':
emit setRegisteredStatus(nicks, setFlag);
foreach(const QString & nick, nicks)
- m_lobbyPlayersModel->setFlag(nick, PlayersListModel::Registered, setFlag);
+ m_playersModel->setFlag(nick, PlayersListModel::Registered, setFlag);
break;
// flag indicating if a player is the host/master of the room
@@ -401,7 +415,7 @@
}
emit setRoomMasterStatus(nick, setFlag);
- m_lobbyPlayersModel->setFlag(nick, PlayersListModel::RoomAdmin, setFlag);
+ m_playersModel->setFlag(nick, PlayersListModel::RoomAdmin, setFlag);
}
break;
@@ -413,7 +427,7 @@
emit adminAccess(setFlag);
emit setAdminStatus(nick, setFlag);
- m_lobbyPlayersModel->setFlag(nick, PlayersListModel::ServerAdmin, setFlag);
+ m_playersModel->setFlag(nick, PlayersListModel::ServerAdmin, setFlag);
}
break;
@@ -452,7 +466,7 @@
emit nickAddedLobby(lst[i], false);
emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|"));
- m_lobbyPlayersModel->addPlayer(lst[i]);
+ m_playersModel->addPlayer(lst[i]);
}
return;
}
@@ -502,7 +516,7 @@
else
emit chatStringLobby(lst[1], tr("%1 *** %2 has left (%3)").arg('\x03').arg("|nick|", lst[2]));
- m_lobbyPlayersModel->removePlayer(lst[1]);
+ m_playersModel->removePlayer(lst[1]);
return;
}
@@ -933,12 +947,12 @@
return m_roomsListModel;
}
-PlayersListModel * HWNewNet::lobbyPlayersModel()
+QAbstractItemModel *HWNewNet::lobbyPlayersModel()
{
return m_lobbyPlayersModel;
}
-PlayersListModel * HWNewNet::roomPlayersModel()
+QAbstractItemModel *HWNewNet::roomPlayersModel()
{
return m_roomPlayersModel;
}
--- a/QTfrontend/net/newnetclient.h Sun Oct 07 23:33:09 2012 +0400
+++ b/QTfrontend/net/newnetclient.h Sun Oct 07 23:59:55 2012 +0400
@@ -33,7 +33,8 @@
class TeamSelWidget;
class RoomsListModel;
class PlayersListModel;
-class QSortFilterModel;
+class QSortFilterProxyModel;
+class QAbstractItemModel;
extern char delimeter;
@@ -57,8 +58,8 @@
QString getRoom();
QString getHost();
RoomsListModel * roomsListModel();
- PlayersListModel * lobbyPlayersModel();
- PlayersListModel * roomPlayersModel();
+ QAbstractItemModel * lobbyPlayersModel();
+ QAbstractItemModel * roomPlayersModel();
private:
bool isChief;
@@ -69,8 +70,9 @@
QString seed;
bool m_game_connected;
RoomsListModel * m_roomsListModel;
- PlayersListModel * m_lobbyPlayersModel;
- PlayersListModel * m_roomPlayersModel;
+ PlayersListModel * m_playersModel;
+ QSortFilterProxyModel * m_lobbyPlayersModel;
+ QSortFilterProxyModel * m_roomPlayersModel;
template <typename T>
void SendCfgStrNet(T a)