mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-01-10 12:14:39 -08:00
User list sorting fix
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTreeWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
@@ -237,6 +236,20 @@ void ServerMessageLog::processServerMessageEvent(Event_ServerMessage *event)
|
||||
textEdit->append(event->getMessage());
|
||||
}
|
||||
|
||||
UserListTWI::UserListTWI()
|
||||
: QTreeWidgetItem(Type)
|
||||
{
|
||||
}
|
||||
|
||||
bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
||||
{
|
||||
// Equal user level => sort by name
|
||||
if (data(0, Qt::UserRole) == other.data(0, Qt::UserRole))
|
||||
return data(2, Qt::UserRole).toString().toLower() < other.data(2, Qt::UserRole).toString().toLower();
|
||||
// Else sort by user level
|
||||
return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt();
|
||||
}
|
||||
|
||||
UserList::UserList(AbstractClient *_client, QWidget *parent)
|
||||
: QGroupBox(parent)
|
||||
{
|
||||
@@ -279,10 +292,11 @@ void UserList::processUserInfo(ServerInfo_User *user)
|
||||
}
|
||||
}
|
||||
if (!item) {
|
||||
item = new QTreeWidgetItem;
|
||||
item = new UserListTWI;
|
||||
userTree->addTopLevelItem(item);
|
||||
retranslateUi();
|
||||
}
|
||||
item->setData(0, Qt::UserRole, user->getUserLevel());
|
||||
item->setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, user->getUserLevel())));
|
||||
item->setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, user->getCountry())));
|
||||
item->setData(2, Qt::UserRole, user->getName());
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define TAB_SERVER_H
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QTreeWidget>
|
||||
#include "tab.h"
|
||||
#include "protocol_datastructures.h"
|
||||
|
||||
@@ -76,6 +77,12 @@ public:
|
||||
void retranslateUi();
|
||||
};
|
||||
|
||||
class UserListTWI : public QTreeWidgetItem {
|
||||
public:
|
||||
UserListTWI();
|
||||
bool operator<(const QTreeWidgetItem &other) const;
|
||||
};
|
||||
|
||||
class UserList : public QGroupBox {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user