/** * @file games_model.h * @ingroup Lobby * @brief TODO: Document this. */ #ifndef GAMESMODEL_H #define GAMESMODEL_H #include "game_type_map.h" #include #include #include #include #include #include #include class UserListProxy; class GamesModel : public QAbstractTableModel { Q_OBJECT private: QList gameList; QMap rooms; QMap gameTypes; static const int NUM_COLS = 8; public: static const int SORT_ROLE = Qt::UserRole + 1; GamesModel(const QMap &_rooms, const QMap &_gameTypes, QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override { return parent.isValid() ? 0 : gameList.size(); } int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override { return NUM_COLS; } QVariant data(const QModelIndex &index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; static const QString getGameCreatedString(const int secs); const ServerInfo_Game &getGame(int row); /** * Update game list with a (possibly new) game. */ void updateGameList(const ServerInfo_Game &game); int roomColIndex() { return 0; } int startTimeColIndex() { return 1; } const QMap &getGameTypes() { return gameTypes; } }; class ServerInfo_User; class GamesProxyModel : public QSortFilterProxyModel { Q_OBJECT private: const UserListProxy *userListProxy; // If adding any additional filters, make sure to update: // - GamesProxyModel() // - resetFilterParameters() // - areFilterParametersSetToDefaults() // - loadFilterParameters() // - saveFilterParameters() // - filterAcceptsRow() bool hideBuddiesOnlyGames; bool hideIgnoredUserGames; bool hideFullGames; bool hideGamesThatStarted; bool hidePasswordProtectedGames; bool hideNotBuddyCreatedGames; bool hideOpenDecklistGames; QString gameNameFilter, creatorNameFilter; QSet gameTypeFilter; quint32 maxPlayersFilterMin, maxPlayersFilterMax; QTime maxGameAge; bool showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat, showOnlyIfSpectatorsCanSeeHands; public: explicit GamesProxyModel(QObject *parent = nullptr, const UserListProxy *_userListProxy = nullptr); bool getHideBuddiesOnlyGames() const { return hideBuddiesOnlyGames; } bool getHideIgnoredUserGames() const { return hideIgnoredUserGames; } bool getHideFullGames() const { return hideFullGames; } bool getHideGamesThatStarted() const { return hideGamesThatStarted; } bool getHidePasswordProtectedGames() const { return hidePasswordProtectedGames; } bool getHideNotBuddyCreatedGames() const { return hideNotBuddyCreatedGames; } bool getHideOpenDecklistGames() const { return hideOpenDecklistGames; } QString getGameNameFilter() const { return gameNameFilter; } QString getCreatorNameFilter() const { return creatorNameFilter; } QSet getGameTypeFilter() const { return gameTypeFilter; } int getMaxPlayersFilterMin() const { return maxPlayersFilterMin; } int getMaxPlayersFilterMax() const { return maxPlayersFilterMax; } const QTime &getMaxGameAge() const { return maxGameAge; } bool getShowOnlyIfSpectatorsCanWatch() const { return showOnlyIfSpectatorsCanWatch; } bool getShowSpectatorPasswordProtected() const { return showSpectatorPasswordProtected; } bool getShowOnlyIfSpectatorsCanChat() const { return showOnlyIfSpectatorsCanChat; } bool getShowOnlyIfSpectatorsCanSeeHands() const { return showOnlyIfSpectatorsCanSeeHands; } void setGameFilters(bool _hideBuddiesOnlyGames, bool _hideIgnoredUserGames, bool _hideFullGames, bool _hideGamesThatStarted, bool _hidePasswordProtectedGames, bool _hideNotBuddyCreatedGames, bool _hideOpenDecklistGames, const QString &_gameNameFilter, const QString &_creatorNameFilter, const QSet &_gameTypeFilter, int _maxPlayersFilterMin, int _maxPlayersFilterMax, const QTime &_maxGameAge, bool _showOnlyIfSpectatorsCanWatch, bool _showSpectatorPasswordProtected, bool _showOnlyIfSpectatorsCanChat, bool _showOnlyIfSpectatorsCanSeeHands); int getNumFilteredGames() const; void resetFilterParameters(); bool areFilterParametersSetToDefaults() const; void loadFilterParameters(const QMap &allGameTypes); void saveFilterParameters(const QMap &allGameTypes); void refresh(); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow) const; }; #endif