Reduce data dependency for GamesProxyModel

This commit is contained in:
Gavin Bisesi 2017-03-17 23:29:42 -04:00 committed by Gavin Bisesi
parent d65a444ac5
commit c5aa75d4d1
3 changed files with 7 additions and 6 deletions

View file

@ -25,7 +25,8 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
gameListModel = new GamesModel(_rooms, _gameTypes, this);
if(showfilters)
{
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo());
bool ownUserIsRegistered = (bool)(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered);
gameListProxyModel = new GamesProxyModel(this, ownUserIsRegistered);
gameListProxyModel->setSourceModel(gameListModel);
gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
gameListView->setModel(gameListProxyModel);

View file

@ -225,9 +225,9 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
endInsertRows();
}
GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
GamesProxyModel::GamesProxyModel(QObject *parent, bool _ownUserIsRegistered)
: QSortFilterProxyModel(parent),
ownUser(_ownUser),
ownUserIsRegistered(_ownUserIsRegistered),
showBuddiesOnlyGames(false),
unavailableGamesVisible(false),
showPasswordProtectedGames(true),
@ -348,7 +348,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
return false;
if (game.started())
return false;
if (!(ownUser->user_level() & ServerInfo_User::IsRegistered))
if (!ownUserIsRegistered)
if (game.only_registered())
return false;
}

View file

@ -46,7 +46,7 @@ class ServerInfo_User;
class GamesProxyModel : public QSortFilterProxyModel {
Q_OBJECT
private:
ServerInfo_User *ownUser;
bool ownUserIsRegistered;
bool showBuddiesOnlyGames;
bool unavailableGamesVisible;
bool showPasswordProtectedGames;
@ -56,7 +56,7 @@ private:
static const int DEFAULT_MAX_PLAYERS_MAX = 99;
public:
GamesProxyModel(QObject *parent = 0, ServerInfo_User *_ownUser = 0);
GamesProxyModel(QObject *parent = 0, bool _ownUserIsRegistered = false);
bool getShowBuddiesOnlyGames() const {return showBuddiesOnlyGames; }
void setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames);