From c5aa75d4d1d4f40ca609788791306b462528fc92 Mon Sep 17 00:00:00 2001 From: Gavin Bisesi Date: Fri, 17 Mar 2017 23:29:42 -0400 Subject: [PATCH] Reduce data dependency for GamesProxyModel --- cockatrice/src/gameselector.cpp | 3 ++- cockatrice/src/gamesmodel.cpp | 6 +++--- cockatrice/src/gamesmodel.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 13989a61..b5f8ffc2 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -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); diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 32dd64f0..1f3d222c 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -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; } diff --git a/cockatrice/src/gamesmodel.h b/cockatrice/src/gamesmodel.h index f84857e7..ef01e9ed 100644 --- a/cockatrice/src/gamesmodel.h +++ b/cockatrice/src/gamesmodel.h @@ -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);