added more filter options to GamesProxyModel, user interface still missing (related to issue #32)
This commit is contained in:
parent
deaebddb0b
commit
facfc3cc52
2 changed files with 67 additions and 1 deletions
|
@ -99,7 +99,11 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
|
||||||
}
|
}
|
||||||
|
|
||||||
GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
|
GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
|
||||||
: QSortFilterProxyModel(parent), ownUser(_ownUser), unavailableGamesVisible(false)
|
: QSortFilterProxyModel(parent),
|
||||||
|
ownUser(_ownUser),
|
||||||
|
unavailableGamesVisible(false),
|
||||||
|
maxPlayersFilterMin(-1),
|
||||||
|
maxPlayersFilterMax(-1)
|
||||||
{
|
{
|
||||||
setDynamicSortFilter(true);
|
setDynamicSortFilter(true);
|
||||||
}
|
}
|
||||||
|
@ -110,6 +114,41 @@ void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GamesProxyModel::setGameNameFilter(const QString &_gameNameFilter)
|
||||||
|
{
|
||||||
|
gameNameFilter = _gameNameFilter;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GamesProxyModel::setCreatorNameFilter(const QString &_creatorNameFilter)
|
||||||
|
{
|
||||||
|
creatorNameFilter = _creatorNameFilter;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GamesProxyModel::setGameTypeFilter(const QSet<int> &_gameTypeFilter)
|
||||||
|
{
|
||||||
|
gameTypeFilter = _gameTypeFilter;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GamesProxyModel::setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax)
|
||||||
|
{
|
||||||
|
maxPlayersFilterMin = _maxPlayersFilterMin;
|
||||||
|
maxPlayersFilterMax = _maxPlayersFilterMax;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GamesProxyModel::resetFilterParameters()
|
||||||
|
{
|
||||||
|
unavailableGamesVisible = false;
|
||||||
|
gameNameFilter = QString();
|
||||||
|
creatorNameFilter = QString();
|
||||||
|
gameTypeFilter.clear();
|
||||||
|
maxPlayersFilterMin = -1;
|
||||||
|
maxPlayersFilterMax = -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const
|
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const
|
||||||
{
|
{
|
||||||
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
||||||
|
@ -126,6 +165,23 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
|
||||||
if (game.only_registered())
|
if (game.only_registered())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!gameNameFilter.isEmpty())
|
||||||
|
if (!QString::fromStdString(game.description()).contains(gameNameFilter, Qt::CaseInsensitive))
|
||||||
|
return false;
|
||||||
|
if (!creatorNameFilter.isEmpty())
|
||||||
|
if (!QString::fromStdString(game.creator_info().name()).contains(creatorNameFilter, Qt::CaseInsensitive))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QSet<int> gameTypes;
|
||||||
|
for (int i = 0; i < game.game_types_size(); ++i)
|
||||||
|
gameTypes.insert(game.game_types(i));
|
||||||
|
if (!gameTypeFilter.isEmpty() && gameTypes.intersect(gameTypeFilter).isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((maxPlayersFilterMin != -1) && (game.max_players() < maxPlayersFilterMin))
|
||||||
|
return false;
|
||||||
|
if ((maxPlayersFilterMax != -1) && (game.max_players() > maxPlayersFilterMax))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QSet>
|
||||||
#include "gametypemap.h"
|
#include "gametypemap.h"
|
||||||
|
|
||||||
class ServerInfo_Game;
|
class ServerInfo_Game;
|
||||||
|
@ -32,9 +33,18 @@ class GamesProxyModel : public QSortFilterProxyModel {
|
||||||
private:
|
private:
|
||||||
ServerInfo_User *ownUser;
|
ServerInfo_User *ownUser;
|
||||||
bool unavailableGamesVisible;
|
bool unavailableGamesVisible;
|
||||||
|
QString gameNameFilter, creatorNameFilter;
|
||||||
|
QSet<int> gameTypeFilter;
|
||||||
|
int maxPlayersFilterMin, maxPlayersFilterMax;
|
||||||
public:
|
public:
|
||||||
GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
|
GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
|
||||||
|
|
||||||
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
void setUnavailableGamesVisible(bool _unavailableGamesVisible);
|
||||||
|
void setGameNameFilter(const QString &_gameNameFilter);
|
||||||
|
void setCreatorNameFilter(const QString &_creatorNameFilter);
|
||||||
|
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);
|
||||||
|
void setMaxPlayersFilter(int _maxPlayersFilterMin, int _maxPlayersFilterMax);
|
||||||
|
void resetFilterParameters();
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue