mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:45:34 +00:00
[Browser] Add custom proxy model
This commit is contained in:
parent
dba98f9261
commit
f86d17d8a6
3 changed files with 81 additions and 0 deletions
|
@ -11,6 +11,7 @@ set(BROWSER
|
|||
ServerModel.cpp
|
||||
NetController.cpp
|
||||
ServerInfoDialog.cpp
|
||||
MySortFilterProxyModel.cpp
|
||||
netutils/HTTPNetwork.cpp
|
||||
netutils/Utils.cpp
|
||||
${CMAKE_SOURCE_DIR}/files/tes3mp/browser.rc
|
||||
|
@ -20,6 +21,7 @@ set(BROWSER_HEADER_MOC
|
|||
MainWindow.hpp
|
||||
ServerModel.hpp
|
||||
ServerInfoDialog.hpp
|
||||
MySortFilterProxyModel.hpp
|
||||
)
|
||||
|
||||
set(BROWSER_HEADER
|
||||
|
|
52
apps/browser/MySortFilterProxyModel.cpp
Normal file
52
apps/browser/MySortFilterProxyModel.cpp
Normal file
|
@ -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();
|
||||
}
|
27
apps/browser/MySortFilterProxyModel.hpp
Normal file
27
apps/browser/MySortFilterProxyModel.hpp
Normal file
|
@ -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 a new issue