forked from teamnwah/openmw-tes3coop
[Browser] Mark unreachable servers as "Unreachable" instead 999
This commit is contained in:
parent
fe9a3088bd
commit
57353cdfff
3 changed files with 23 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "ServerModel.hpp"
|
#include "ServerModel.hpp"
|
||||||
|
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <apps/browser/netutils/Utils.hpp>
|
||||||
|
|
||||||
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
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);
|
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)
|
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
filterEmpty = false;
|
filterEmpty = false;
|
||||||
|
|
|
@ -13,6 +13,7 @@ class MySortFilterProxyModel : public QSortFilterProxyModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
|
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:
|
public:
|
||||||
explicit MySortFilterProxyModel(QObject *parent);
|
explicit MySortFilterProxyModel(QObject *parent);
|
||||||
void filterFullServer(bool state);
|
void filterFullServer(bool state);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
#include "ServerModel.hpp"
|
#include "ServerModel.hpp"
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <apps/browser/netutils/Utils.hpp>
|
||||||
|
|
||||||
ServerModel::ServerModel(QObject *parent) : QAbstractTableModel(parent)
|
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());
|
var = QString(sd.rules.at("name").str.c_str());
|
||||||
break;
|
break;
|
||||||
case ServerData::PING:
|
case ServerData::PING:
|
||||||
var = sd.ping;
|
var = sd.ping == PING_UNREACHABLE ? QVariant("Unreachable") : sd.ping;
|
||||||
break;
|
break;
|
||||||
case ServerData::MODNAME:
|
case ServerData::MODNAME:
|
||||||
if (sd.rules.at("gamemode").str == "")
|
if (sd.rules.at("gamemode").str == "")
|
||||||
|
|
Loading…
Reference in a new issue