diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 995b55258..d77d70d36 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -180,6 +180,7 @@ set(cockatrice_SOURCES src/interface/widgets/replay/replay_timeline_widget.cpp src/interface/widgets/server/chat_view/chat_view.cpp src/interface/widgets/server/game_selector.cpp + src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp src/interface/widgets/server/games_model.cpp src/interface/widgets/server/handle_public_servers.cpp src/interface/widgets/server/remote/remote_decklist_tree_widget.cpp diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp index 0c5191f99..40dea9cb8 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.cpp @@ -56,7 +56,7 @@ DlgFilterGames::DlgFilterGames(const QMap &_allGameTypes, auto *gameNameFilterLabel = new QLabel(tr("Game &description:")); gameNameFilterLabel->setBuddy(gameNameFilterEdit); creatorNameFilterEdit = new QLineEdit; - creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilter()); + creatorNameFilterEdit->setText(gamesProxyModel->getCreatorNameFilters().join(", ")); auto *creatorNameFilterLabel = new QLabel(tr("&Creator name:")); creatorNameFilterLabel->setBuddy(creatorNameFilterEdit); @@ -232,9 +232,9 @@ QString DlgFilterGames::getGameNameFilter() const return gameNameFilterEdit->text(); } -QString DlgFilterGames::getCreatorNameFilter() const +QStringList DlgFilterGames::getCreatorNameFilters() const { - return creatorNameFilterEdit->text(); + return creatorNameFilterEdit->text().split(",", Qt::SkipEmptyParts); } QSet DlgFilterGames::getGameTypeFilter() const diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h index ab07a02d4..37b208749 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h +++ b/cockatrice/src/interface/widgets/dialogs/dlg_filter_games.h @@ -71,7 +71,7 @@ public: bool getHideNotBuddyCreatedGames() const; QString getGameNameFilter() const; void setGameNameFilter(const QString &_gameNameFilter); - QString getCreatorNameFilter() const; + QStringList getCreatorNameFilters() const; void setCreatorNameFilter(const QString &_creatorNameFilter); QSet getGameTypeFilter() const; void setGameTypeFilter(const QSet &_gameTypeFilter); diff --git a/cockatrice/src/interface/widgets/server/game_selector.cpp b/cockatrice/src/interface/widgets/server/game_selector.cpp index 8aa3211bd..9755d67ab 100644 --- a/cockatrice/src/interface/widgets/server/game_selector.cpp +++ b/cockatrice/src/interface/widgets/server/game_selector.cpp @@ -76,6 +76,8 @@ GameSelector::GameSelector(AbstractClient *_client, gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + quickFilterToolBar = new GameSelectorQuickFilterToolBar(this, tabSupervisor, gameListProxyModel, gameTypeMap); + filterButton = new QPushButton; filterButton->setIcon(QPixmap("theme:icons/search")); connect(filterButton, &QPushButton::clicked, this, &GameSelector::actSetFilter); @@ -107,6 +109,7 @@ GameSelector::GameSelector(AbstractClient *_client, buttonLayout->setAlignment(Qt::AlignTop); QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(quickFilterToolBar); mainLayout->addWidget(gameListView); mainLayout->addLayout(buttonLayout); @@ -158,7 +161,7 @@ void GameSelector::actSetFilter() gameListProxyModel->setGameFilters( dlg.getHideBuddiesOnlyGames(), dlg.getHideIgnoredUserGames(), dlg.getHideFullGames(), dlg.getHideGamesThatStarted(), dlg.getHidePasswordProtectedGames(), dlg.getHideNotBuddyCreatedGames(), - dlg.getHideOpenDecklistGames(), dlg.getGameNameFilter(), dlg.getCreatorNameFilter(), dlg.getGameTypeFilter(), + dlg.getHideOpenDecklistGames(), dlg.getGameNameFilter(), dlg.getCreatorNameFilters(), dlg.getGameTypeFilter(), dlg.getMaxPlayersFilterMin(), dlg.getMaxPlayersFilterMax(), dlg.getMaxGameAge(), dlg.getShowOnlyIfSpectatorsCanWatch(), dlg.getShowSpectatorPasswordProtected(), dlg.getShowOnlyIfSpectatorsCanChat(), dlg.getShowOnlyIfSpectatorsCanSeeHands()); diff --git a/cockatrice/src/interface/widgets/server/game_selector.h b/cockatrice/src/interface/widgets/server/game_selector.h index 0ca477fa9..ba87d81ea 100644 --- a/cockatrice/src/interface/widgets/server/game_selector.h +++ b/cockatrice/src/interface/widgets/server/game_selector.h @@ -7,6 +7,7 @@ #ifndef GAMESELECTOR_H #define GAMESELECTOR_H +#include "game_selector_quick_filter_toolbar.h" #include "game_type_map.h" #include @@ -52,6 +53,8 @@ private: TabSupervisor *tabSupervisor; TabRoom *room; + GameSelectorQuickFilterToolBar *quickFilterToolBar; + QTreeView *gameListView; GamesModel *gameListModel; GamesProxyModel *gameListProxyModel; diff --git a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp new file mode 100644 index 000000000..c63b52450 --- /dev/null +++ b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.cpp @@ -0,0 +1,110 @@ +#include "game_selector_quick_filter_toolbar.h" + +#include "games_model.h" +#include "user/user_list_manager.h" + +#include +#include +#include +#include +#include + +GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent, + TabSupervisor *_tabSupervisor, + GamesProxyModel *_model, + const QMap &allGameTypes) + : QWidget(parent), tabSupervisor(_tabSupervisor), model(_model) +{ + mainLayout = new QHBoxLayout(this); + mainLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->setSpacing(5); + + searchBar = new QLineEdit(this); + searchBar->setText(model->getCreatorNameFilters().join(", ")); + connect(searchBar, &QLineEdit::textChanged, this, [this](const QString &text) { model->setGameNameFilter(text); }); + + hideGamesNotCreatedByBuddiesCheckBox = new QCheckBox(this); + hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames()); + connect(hideGamesNotCreatedByBuddiesCheckBox, &QCheckBox::toggled, this, [this](bool checked) { + if (checked) { + QStringList buddyNames; + for (auto buddy : tabSupervisor->getUserListManager()->getBuddyList().values()) { + buddyNames << QString::fromStdString(buddy.name()); + } + model->setCreatorNameFilters(buddyNames); + } else { + model->setCreatorNameFilters({}); + } + }); + + hideFullGamesCheckBox = new QCheckBox(this); + hideFullGamesCheckBox->setChecked(model->getHideFullGames()); + connect(hideFullGamesCheckBox, &QCheckBox::toggled, this, + [this](bool checked) { model->setHideFullGames(checked); }); + + hideStartedGamesCheckBox = new QCheckBox(this); + hideStartedGamesCheckBox->setChecked(model->getHideGamesThatStarted()); + connect(hideStartedGamesCheckBox, &QCheckBox::toggled, this, + [this](bool checked) { model->setHideGamesThatStarted(checked); }); + + filterToFormatComboBox = new QComboBox(this); + + // Add a "No filter" / "All types" option first + filterToFormatComboBox->addItem(tr("All types"), QVariant()); // empty QVariant = no filter + + QMapIterator i(allGameTypes); + while (i.hasNext()) { + i.next(); + filterToFormatComboBox->addItem(i.value(), i.key()); // text = name, data = type ID + } + + QSet currentTypes = model->getGameTypeFilter(); + if (currentTypes.size() == 1) { + int typeId = *currentTypes.begin(); + int index = filterToFormatComboBox->findData(typeId); + if (index >= 0) + filterToFormatComboBox->setCurrentIndex(index); + } else { + filterToFormatComboBox->setCurrentIndex(0); // "All types" by default + } + + // Update proxy model on selection change + connect(filterToFormatComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) { + QVariant data = filterToFormatComboBox->itemData(index); + if (!data.isValid()) { + model->setGameTypeFilter({}); // empty = no filter + } else { + int typeId = data.toInt(); + model->setGameTypeFilter({typeId}); + } + }); + + hideGamesNotCreatedByBuddiesCheckBox->setMinimumSize(20, 20); + hideFullGamesCheckBox->setMinimumSize(20, 20); + hideStartedGamesCheckBox->setMinimumSize(20, 20); + +#if defined(Q_OS_MAC) + mainLayout->setSpacing(6); +#endif + + mainLayout->addWidget(searchBar); + mainLayout->addWidget(filterToFormatComboBox); + mainLayout->addWidget(hideGamesNotCreatedByBuddiesCheckBox); + mainLayout->addSpacing(5); + mainLayout->addWidget(hideFullGamesCheckBox); + mainLayout->addSpacing(5); + mainLayout->addWidget(hideStartedGamesCheckBox); + + setLayout(mainLayout); + + retranslateUi(); +} + +void GameSelectorQuickFilterToolBar::retranslateUi() +{ + searchBar->setPlaceholderText(tr("Filter by game name...")); + filterToFormatComboBox->setToolTip(tr("Filter by game type/format")); + hideGamesNotCreatedByBuddiesCheckBox->setText(tr("Hide games not created by buddies")); + hideFullGamesCheckBox->setText(tr("Hide full games")); + hideStartedGamesCheckBox->setText(tr("Hide started games")); +} diff --git a/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h new file mode 100644 index 000000000..f7e0c6fb1 --- /dev/null +++ b/cockatrice/src/interface/widgets/server/game_selector_quick_filter_toolbar.h @@ -0,0 +1,39 @@ +#ifndef COCKATRICE_GAME_SELECTOR_QUICK_FILTER_TOOLBAR_H +#define COCKATRICE_GAME_SELECTOR_QUICK_FILTER_TOOLBAR_H + +#include "../tabs/tab_supervisor.h" +#include "games_model.h" + +#include +#include +#include +#include +#include +#include + +class GameSelectorQuickFilterToolBar : public QWidget +{ + + Q_OBJECT + +public: + explicit GameSelectorQuickFilterToolBar(QWidget *parent, + TabSupervisor *tabSupervisor, + GamesProxyModel *model, + const QMap &allGameTypes); + void retranslateUi(); + +private: + TabSupervisor *tabSupervisor; + GamesProxyModel *model; + + QHBoxLayout *mainLayout; + + QLineEdit *searchBar; + QCheckBox *hideGamesNotCreatedByBuddiesCheckBox; + QCheckBox *hideFullGamesCheckBox; + QCheckBox *hideStartedGamesCheckBox; + QComboBox *filterToFormatComboBox; +}; + +#endif // COCKATRICE_GAME_SELECTOR_QUICK_FILTER_TOOLBAR_H diff --git a/cockatrice/src/interface/widgets/server/games_model.cpp b/cockatrice/src/interface/widgets/server/games_model.cpp index 4c68390c9..dfb41fd29 100644 --- a/cockatrice/src/interface/widgets/server/games_model.cpp +++ b/cockatrice/src/interface/widgets/server/games_model.cpp @@ -294,7 +294,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames, bool _hideNotBuddyCreatedGames, bool _hideOpenDecklistGames, const QString &_gameNameFilter, - const QString &_creatorNameFilter, + const QStringList &_creatorNameFilters, const QSet &_gameTypeFilter, int _maxPlayersFilterMin, int _maxPlayersFilterMax, @@ -315,7 +315,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames, hideNotBuddyCreatedGames = _hideNotBuddyCreatedGames; hideOpenDecklistGames = _hideOpenDecklistGames; gameNameFilter = _gameNameFilter; - creatorNameFilter = _creatorNameFilter; + creatorNameFilters = _creatorNameFilters; gameTypeFilter = _gameTypeFilter; maxPlayersFilterMin = _maxPlayersFilterMin; maxPlayersFilterMax = _maxPlayersFilterMax; @@ -348,15 +348,15 @@ int GamesProxyModel::getNumFilteredGames() const void GamesProxyModel::resetFilterParameters() { - setGameFilters(false, false, false, false, false, false, false, QString(), QString(), {}, DEFAULT_MAX_PLAYERS_MIN, - DEFAULT_MAX_PLAYERS_MAX, DEFAULT_MAX_GAME_AGE, false, false, false, false); + setGameFilters(false, false, false, false, false, false, false, QString(), QStringList(), {}, + DEFAULT_MAX_PLAYERS_MIN, DEFAULT_MAX_PLAYERS_MAX, DEFAULT_MAX_GAME_AGE, false, false, false, false); } bool GamesProxyModel::areFilterParametersSetToDefaults() const { return !hideFullGames && !hideGamesThatStarted && !hidePasswordProtectedGames && !hideBuddiesOnlyGames && !hideOpenDecklistGames && !hideIgnoredUserGames && !hideNotBuddyCreatedGames && gameNameFilter.isEmpty() && - creatorNameFilter.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN && + creatorNameFilters.isEmpty() && gameTypeFilter.isEmpty() && maxPlayersFilterMin == DEFAULT_MAX_PLAYERS_MIN && maxPlayersFilterMax == DEFAULT_MAX_PLAYERS_MAX && maxGameAge == DEFAULT_MAX_GAME_AGE && !showOnlyIfSpectatorsCanWatch && !showSpectatorPasswordProtected && !showOnlyIfSpectatorsCanChat && !showOnlyIfSpectatorsCanSeeHands; @@ -379,7 +379,7 @@ void GamesProxyModel::loadFilterParameters(const QMap &allGameType gameFilters.isHideFullGames(), gameFilters.isHideGamesThatStarted(), gameFilters.isHidePasswordProtectedGames(), gameFilters.isHideNotBuddyCreatedGames(), gameFilters.isHideOpenDecklistGames(), gameFilters.getGameNameFilter(), - gameFilters.getCreatorNameFilter(), newGameTypeFilter, gameFilters.getMinPlayers(), + gameFilters.getCreatorNameFilters(), newGameTypeFilter, gameFilters.getMinPlayers(), gameFilters.getMaxPlayers(), gameFilters.getMaxGameAge(), gameFilters.isShowOnlyIfSpectatorsCanWatch(), gameFilters.isShowSpectatorPasswordProtected(), gameFilters.isShowOnlyIfSpectatorsCanChat(), gameFilters.isShowOnlyIfSpectatorsCanSeeHands()); @@ -396,7 +396,7 @@ void GamesProxyModel::saveFilterParameters(const QMap &allGameType gameFilters.setHideNotBuddyCreatedGames(hideNotBuddyCreatedGames); gameFilters.setHideOpenDecklistGames(hideOpenDecklistGames); gameFilters.setGameNameFilter(gameNameFilter); - gameFilters.setCreatorNameFilter(creatorNameFilter); + gameFilters.setCreatorNameFilters(creatorNameFilters); QMapIterator gameTypeIterator(allGameTypes); while (gameTypeIterator.hasNext()) { @@ -459,9 +459,17 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const 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)) + if (!creatorNameFilters.isEmpty()) { + bool found = false; + for (const auto &createNameFilter : creatorNameFilters) { + if (QString::fromStdString(game.creator_info().name()).contains(createNameFilter, Qt::CaseInsensitive)) { + found = true; + } + } + if (!found) { return false; + } + } QSet gameTypes; for (int i = 0; i < game.game_types_size(); ++i) diff --git a/cockatrice/src/interface/widgets/server/games_model.h b/cockatrice/src/interface/widgets/server/games_model.h index d29800f66..c704befcc 100644 --- a/cockatrice/src/interface/widgets/server/games_model.h +++ b/cockatrice/src/interface/widgets/server/games_model.h @@ -1,9 +1,3 @@ -/** - * @file games_model.h - * @ingroup Lobby - * @brief TODO: Document this. - */ - #ifndef GAMESMODEL_H #define GAMESMODEL_H @@ -19,60 +13,107 @@ class UserListProxy; +/** + * @class GamesModel + * @ingroup Lobby + * @brief Model storing all available games for display in a QTreeView or QTableView. + * + * Provides access to game information, supports sorting by different columns, + * and updates when new game data is received from the server. + */ class GamesModel : public QAbstractTableModel { Q_OBJECT private: - QList gameList; - QMap rooms; - QMap gameTypes; + QList gameList; /**< List of games currently displayed. */ + QMap rooms; /**< Map of room IDs to room names. */ + QMap gameTypes; /**< Map of room IDs to available game types. */ - static const int NUM_COLS = 8; + static const int NUM_COLS = 8; /**< Number of columns in the table. */ public: - static const int SORT_ROLE = Qt::UserRole + 1; + static const int SORT_ROLE = Qt::UserRole + 1; /**< Role used for sorting. */ + /** + * @brief Constructs a GamesModel. + * @param _rooms Mapping of room IDs to room names. + * @param _gameTypes Mapping of room IDs to their available game types. + * @param parent Parent QObject. + */ 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; + + /** + * @brief Formats the game creation time into a human-readable string. + * @param secs Number of seconds since the game started. + * @return Short string representing game age (e.g., "new", ">5 min", ">2 hr"). + */ static const QString getGameCreatedString(const int secs); + + /** + * @brief Returns a reference to a specific game by row index. + * @param row Row index in the table. + * @return Reference to the ServerInfo_Game at the given row. + */ const ServerInfo_Game &getGame(int row); /** - * Update game list with a (possibly new) game. + * @brief Updates the game list with a new or updated game. + * @param game The ServerInfo_Game object to add or update. */ void updateGameList(const ServerInfo_Game &game); + /** + * @brief Returns the index of the room column. + */ int roomColIndex() { return 0; } + + /** + * @brief Returns the index of the start time column. + */ int startTimeColIndex() { return 1; } + /** + * @brief Returns the map of game types per room. + */ const QMap &getGameTypes() { return gameTypes; } }; -class ServerInfo_User; - +/** + * @class GamesProxyModel + * @ingroup Lobby + * @brief Proxy model for filtering and sorting the GamesModel based on user preferences. + * + * Supports filtering games based on buddies-only, ignored users, password protection, + * game types, creator, age, player count, and spectator permissions. + */ class GamesProxyModel : public QSortFilterProxyModel { Q_OBJECT private: - const UserListProxy *userListProxy; + const UserListProxy *userListProxy; /**< Proxy for checking user ignore/buddy lists. */ // If adding any additional filters, make sure to update: // - GamesProxyModel() @@ -88,16 +129,25 @@ private: bool hidePasswordProtectedGames; bool hideNotBuddyCreatedGames; bool hideOpenDecklistGames; - QString gameNameFilter, creatorNameFilter; + QString gameNameFilter; + QStringList creatorNameFilters; QSet gameTypeFilter; quint32 maxPlayersFilterMin, maxPlayersFilterMax; QTime maxGameAge; - bool showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat, - showOnlyIfSpectatorsCanSeeHands; + bool showOnlyIfSpectatorsCanWatch; + bool showSpectatorPasswordProtected; + bool showOnlyIfSpectatorsCanChat; + bool showOnlyIfSpectatorsCanSeeHands; public: + /** + * @brief Constructs a GamesProxyModel. + * @param parent Parent QObject. + * @param _userListProxy Proxy for accessing ignore/buddy lists. + */ explicit GamesProxyModel(QObject *parent = nullptr, const UserListProxy *_userListProxy = nullptr); + // Getters for filter parameters bool getHideBuddiesOnlyGames() const { return hideBuddiesOnlyGames; @@ -130,9 +180,9 @@ public: { return gameNameFilter; } - QString getCreatorNameFilter() const + QStringList getCreatorNameFilters() const { - return creatorNameFilter; + return creatorNameFilters; } QSet getGameTypeFilter() const { @@ -166,6 +216,10 @@ public: { return showOnlyIfSpectatorsCanSeeHands; } + + /** + * @brief Sets all game filters at once. + */ void setGameFilters(bool _hideBuddiesOnlyGames, bool _hideIgnoredUserGames, bool _hideFullGames, @@ -174,7 +228,7 @@ public: bool _hideNotBuddyCreatedGames, bool _hideOpenDecklistGames, const QString &_gameNameFilter, - const QString &_creatorNameFilter, + const QStringList &_creatorNameFilter, const QSet &_gameTypeFilter, int _maxPlayersFilterMin, int _maxPlayersFilterMax, @@ -184,11 +238,123 @@ public: bool _showOnlyIfSpectatorsCanChat, bool _showOnlyIfSpectatorsCanSeeHands); + // Individual setters + void setHideBuddiesOnlyGames(bool value) + { + hideBuddiesOnlyGames = value; + refresh(); + } + void setHideIgnoredUserGames(bool value) + { + hideIgnoredUserGames = value; + refresh(); + } + void setHideFullGames(bool value) + { + hideFullGames = value; + refresh(); + } + void setHideGamesThatStarted(bool value) + { + hideGamesThatStarted = value; + refresh(); + } + void setHidePasswordProtectedGames(bool value) + { + hidePasswordProtectedGames = value; + refresh(); + } + void setHideNotBuddyCreatedGames(bool value) + { + hideNotBuddyCreatedGames = value; + refresh(); + } + void setHideOpenDecklistGames(bool value) + { + hideOpenDecklistGames = value; + refresh(); + } + void setGameNameFilter(const QString &value) + { + gameNameFilter = value; + refresh(); + } + void setCreatorNameFilters(const QStringList &values) + { + creatorNameFilters = values; + refresh(); + } + void setGameTypeFilter(const QSet &value) + { + gameTypeFilter = value; + refresh(); + } + void setMaxPlayersFilterMin(int value) + { + maxPlayersFilterMin = value; + refresh(); + } + void setMaxPlayersFilterMax(int value) + { + maxPlayersFilterMax = value; + refresh(); + } + void setMaxGameAge(const QTime &value) + { + maxGameAge = value; + refresh(); + } + void setShowOnlyIfSpectatorsCanWatch(bool value) + { + showOnlyIfSpectatorsCanWatch = value; + refresh(); + } + void setShowSpectatorPasswordProtected(bool value) + { + showSpectatorPasswordProtected = value; + refresh(); + } + void setShowOnlyIfSpectatorsCanChat(bool value) + { + showOnlyIfSpectatorsCanChat = value; + refresh(); + } + void setShowOnlyIfSpectatorsCanSeeHands(bool value) + { + showOnlyIfSpectatorsCanSeeHands = value; + refresh(); + } + + /** + * @brief Returns the number of games filtered out by the current filter. + */ int getNumFilteredGames() const; + + /** + * @brief Resets all filter parameters to default values. + */ void resetFilterParameters(); + + /** + * @brief Returns true if all filter parameters are set to their defaults. + */ bool areFilterParametersSetToDefaults() const; + + /** + * @brief Loads filter parameters from persistent settings. + * @param allGameTypes Mapping of all game types by room ID. + */ void loadFilterParameters(const QMap &allGameTypes); + + /** + * @brief Saves filter parameters to persistent settings. + * @param allGameTypes Mapping of all game types by room ID. + */ void saveFilterParameters(const QMap &allGameTypes); + + /** + * @brief Refreshes the proxy model (re-applies filters). + */ void refresh(); protected: diff --git a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp index 2da9b9bc3..e5db3010d 100644 --- a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp +++ b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.cpp @@ -25,7 +25,7 @@ void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide) bool GameFiltersSettings::isHideBuddiesOnlyGames() { QVariant previous = getValue("hide_buddies_only_games"); - return previous == QVariant() || previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideFullGames(bool hide) @@ -36,7 +36,7 @@ void GameFiltersSettings::setHideFullGames(bool hide) bool GameFiltersSettings::isHideFullGames() { QVariant previous = getValue("hide_full_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideGamesThatStarted(bool hide) @@ -47,7 +47,7 @@ void GameFiltersSettings::setHideGamesThatStarted(bool hide) bool GameFiltersSettings::isHideGamesThatStarted() { QVariant previous = getValue("hide_games_that_started"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHidePasswordProtectedGames(bool hide) @@ -58,7 +58,7 @@ void GameFiltersSettings::setHidePasswordProtectedGames(bool hide) bool GameFiltersSettings::isHidePasswordProtectedGames() { QVariant previous = getValue("hide_password_protected_games"); - return previous == QVariant() || previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideIgnoredUserGames(bool hide) @@ -69,7 +69,7 @@ void GameFiltersSettings::setHideIgnoredUserGames(bool hide) bool GameFiltersSettings::isHideIgnoredUserGames() { QVariant previous = getValue("hide_ignored_user_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? true : previous.toBool(); } void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide) @@ -80,7 +80,7 @@ void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide) bool GameFiltersSettings::isHideNotBuddyCreatedGames() { QVariant previous = getValue("hide_not_buddy_created_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setHideOpenDecklistGames(bool hide) @@ -91,7 +91,7 @@ void GameFiltersSettings::setHideOpenDecklistGames(bool hide) bool GameFiltersSettings::isHideOpenDecklistGames() { QVariant previous = getValue("hide_open_decklist_games"); - return !(previous == QVariant()) && previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setGameNameFilter(QString gameName) @@ -104,14 +104,14 @@ QString GameFiltersSettings::getGameNameFilter() return getValue("game_name_filter").toString(); } -void GameFiltersSettings::setCreatorNameFilter(QString creatorName) +void GameFiltersSettings::setCreatorNameFilters(QStringList creatorName) { setValue(creatorName, "creator_name_filter"); } -QString GameFiltersSettings::getCreatorNameFilter() +QStringList GameFiltersSettings::getCreatorNameFilters() { - return getValue("creator_name_filter").toString(); + return getValue("creator_name_filter").toStringList(); } void GameFiltersSettings::setMinPlayers(int min) @@ -182,7 +182,7 @@ void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show) bool GameFiltersSettings::isShowSpectatorPasswordProtected() { QVariant previous = getValue("show_spectator_password_protected"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show) @@ -193,7 +193,7 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show) bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat() { QVariant previous = getValue("show_only_if_spectators_can_chat"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show) @@ -204,5 +204,5 @@ void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show) bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands() { QVariant previous = getValue("show_only_if_spectators_can_see_hands"); - return previous == QVariant() ? true : previous.toBool(); + return previous == QVariant() ? false : previous.toBool(); } \ No newline at end of file diff --git a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h index ef2d802fd..d62fea03d 100644 --- a/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h +++ b/libcockatrice_settings/libcockatrice/settings/game_filters_settings.h @@ -24,7 +24,7 @@ public: bool isHideNotBuddyCreatedGames(); bool isHideOpenDecklistGames(); QString getGameNameFilter(); - QString getCreatorNameFilter(); + QStringList getCreatorNameFilters(); int getMinPlayers(); int getMaxPlayers(); QTime getMaxGameAge(); @@ -42,7 +42,7 @@ public: void setHidePasswordProtectedGames(bool hide); void setHideNotBuddyCreatedGames(bool hide); void setGameNameFilter(QString gameName); - void setCreatorNameFilter(QString creatorName); + void setCreatorNameFilters(QStringList creatorName); void setMinPlayers(int min); void setMaxPlayers(int max); void setMaxGameAge(const QTime &maxGameAge);