From 57353cdffff3580566415039544fae15052e8d73 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 10 Oct 2017 13:09:42 +0800 Subject: [PATCH] [Browser] Mark unreachable servers as "Unreachable" instead 999 --- apps/browser/MySortFilterProxyModel.cpp | 20 ++++++++++++++++++++ apps/browser/MySortFilterProxyModel.hpp | 1 + apps/browser/ServerModel.cpp | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/browser/MySortFilterProxyModel.cpp b/apps/browser/MySortFilterProxyModel.cpp index f8026c0fd..5bb2b1518 100644 --- a/apps/browser/MySortFilterProxyModel.cpp +++ b/apps/browser/MySortFilterProxyModel.cpp @@ -6,6 +6,7 @@ #include "ServerModel.hpp" #include +#include bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { @@ -28,6 +29,25 @@ bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } +bool MySortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const +{ + if(sortColumn() == ServerData::PING) + { + bool valid; + QModelIndex cLeft = source_left; + QModelIndex cRight = source_right; + + int pingright = sourceModel()->data(source_right).toInt(&valid); + pingright = valid ? pingright : PING_UNREACHABLE; + + int pingleft = sourceModel()->data(source_left).toInt(&valid); + pingleft = valid ? pingleft : PING_UNREACHABLE; + return pingleft < pingright; + } + else + return QSortFilterProxyModel::lessThan(source_left, source_right); +} + MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { filterEmpty = false; diff --git a/apps/browser/MySortFilterProxyModel.hpp b/apps/browser/MySortFilterProxyModel.hpp index 169b68945..a36a37d38 100644 --- a/apps/browser/MySortFilterProxyModel.hpp +++ b/apps/browser/MySortFilterProxyModel.hpp @@ -13,6 +13,7 @@ class MySortFilterProxyModel : public QSortFilterProxyModel Q_OBJECT protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL; + bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const Q_DECL_FINAL; public: explicit MySortFilterProxyModel(QObject *parent); void filterFullServer(bool state); diff --git a/apps/browser/ServerModel.cpp b/apps/browser/ServerModel.cpp index 9f728f7b3..3ffd6f7f7 100644 --- a/apps/browser/ServerModel.cpp +++ b/apps/browser/ServerModel.cpp @@ -1,6 +1,7 @@ #include #include "ServerModel.hpp" #include +#include ServerModel::ServerModel(QObject *parent) : QAbstractTableModel(parent) { @@ -43,7 +44,7 @@ QVariant ServerModel::data(const QModelIndex &index, int role) const var = QString(sd.rules.at("name").str.c_str()); break; case ServerData::PING: - var = sd.ping; + var = sd.ping == PING_UNREACHABLE ? QVariant("Unreachable") : sd.ping; break; case ServerData::MODNAME: if (sd.rules.at("gamemode").str == "")