Merge branch 'master' of https://github.com/TES3MP/openmw-tes3mp
commit
bcee35ca1d
@ -0,0 +1,52 @@
|
||||
//
|
||||
// Created by koncord on 30.01.17.
|
||||
//
|
||||
|
||||
#include "MySortFilterProxyModel.hpp"
|
||||
#include "ServerModel.hpp"
|
||||
|
||||
#include <qdebug.h>
|
||||
|
||||
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
|
||||
QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent);
|
||||
QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent);
|
||||
QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent);
|
||||
|
||||
int ping = sourceModel()->data(pingIndex).toInt();
|
||||
int players = sourceModel()->data(plIndex).toInt();
|
||||
int maxPlayers = sourceModel()->data(maxPlIndex).toInt();
|
||||
|
||||
if(maxPing > 0 && (ping == -1 || ping > maxPing))
|
||||
return false;
|
||||
if(filterEmpty && players == 0)
|
||||
return false;
|
||||
if(filterFull && players >= maxPlayers)
|
||||
return false;
|
||||
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
|
||||
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::filterEmptyServers(bool state)
|
||||
{
|
||||
filterEmpty = state;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::filterFullServer(bool state)
|
||||
{
|
||||
filterFull = state;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::pingLessThan(int maxPing)
|
||||
{
|
||||
this->maxPing = maxPing;
|
||||
invalidateFilter();
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by koncord on 30.01.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
||||
#define OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
||||
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class MySortFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
|
||||
public:
|
||||
MySortFilterProxyModel(QObject *parent);
|
||||
void filterFullServer(bool state);
|
||||
void filterEmptyServers(bool state);
|
||||
void pingLessThan(int maxPing);
|
||||
private:
|
||||
bool filterEmpty, filterFull;
|
||||
int maxPing;
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
Loading…
Reference in New Issue