Change button to filter to games created by buddies, set default filter settings to be very permissive.

Took 45 minutes
This commit is contained in:
Lukas Brübach 2025-11-15 22:30:16 +01:00
parent 8022135d8c
commit 1cb45433a2
9 changed files with 76 additions and 52 deletions

View file

@ -56,7 +56,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_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<int> DlgFilterGames::getGameTypeFilter() const

View file

@ -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<int> getGameTypeFilter() const;
void setGameTypeFilter(const QSet<int> &_gameTypeFilter);

View file

@ -76,7 +76,7 @@ GameSelector::GameSelector(AbstractClient *_client,
gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
quickFilterToolBar = new GameSelectorQuickFilterToolBar(this, gameListProxyModel, gameTypeMap);
quickFilterToolBar = new GameSelectorQuickFilterToolBar(this, tabSupervisor, gameListProxyModel, gameTypeMap);
filterButton = new QPushButton;
filterButton->setIcon(QPixmap("theme:icons/search"));
@ -169,7 +169,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());

View file

@ -1,6 +1,7 @@
#include "game_selector_quick_filter_toolbar.h"
#include "games_model.h"
#include "user/user_list_manager.h"
#include <QCheckBox>
#include <QComboBox>
@ -9,23 +10,32 @@
#include <QLineEdit>
GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
TabSupervisor *_tabSupervisor,
GamesProxyModel *_model,
const QMap<int, QString> &allGameTypes)
: QWidget(parent), model(_model)
: QWidget(parent), tabSupervisor(_tabSupervisor), model(_model)
{
mainLayout = new QHBoxLayout(this);
searchBar = new QLineEdit(this);
searchBar->setText(model->getCreatorNameFilter());
connect(searchBar, &QLineEdit::textChanged, this,
[this](const QString &text) { model->setCreatorNameFilter(text); });
searchBar->setText(model->getCreatorNameFilters().join(", "));
connect(searchBar, &QLineEdit::textChanged, this, [this](const QString &text) { model->setGameNameFilter(text); });
hideGamesWithoutBuddiesCheckBox = new QCheckBox(this);
hideGamesWithoutBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames());
hideGamesWithoutBuddiesLabel = new QLabel(this);
hideGamesWithoutBuddiesLabel->setBuddy(hideGamesWithoutBuddiesCheckBox);
connect(hideGamesWithoutBuddiesCheckBox, &QCheckBox::toggled, this,
[this](bool checked) { model->setHideBuddiesOnlyGames(checked); });
hideGamesNotCreatedByBuddiesCheckBox = new QCheckBox(this);
hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames());
hideGamesNotCreatedByBuddiesLabel = new QLabel(this);
hideGamesNotCreatedByBuddiesLabel->setBuddy(hideGamesNotCreatedByBuddiesCheckBox);
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());
@ -76,8 +86,8 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
});
mainLayout->addWidget(searchBar);
mainLayout->addWidget(hideGamesWithoutBuddiesLabel);
mainLayout->addWidget(hideGamesWithoutBuddiesCheckBox);
mainLayout->addWidget(hideGamesNotCreatedByBuddiesLabel);
mainLayout->addWidget(hideGamesNotCreatedByBuddiesCheckBox);
mainLayout->addWidget(hideFullGamesLabel);
mainLayout->addWidget(hideFullGamesCheckBox);
mainLayout->addWidget(hideStartedGamesLabel);
@ -92,8 +102,8 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
void GameSelectorQuickFilterToolBar::retranslateUi()
{
searchBar->setPlaceholderText(tr("Filter by creator name..."));
hideGamesWithoutBuddiesLabel->setText(tr("Hide buddies only games"));
searchBar->setPlaceholderText(tr("Filter by game name..."));
hideGamesNotCreatedByBuddiesLabel->setText(tr("Hide games not created by buddies"));
hideFullGamesLabel->setText(tr("Hide full games"));
hideStartedGamesLabel->setText(tr("Hide started games"));
filterToFormatLabel->setText(tr("Filter to format"));

View file

@ -1,5 +1,7 @@
#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 <QCheckBox>
@ -16,18 +18,20 @@ class GameSelectorQuickFilterToolBar : public QWidget
public:
explicit GameSelectorQuickFilterToolBar(QWidget *parent,
TabSupervisor *tabSupervisor,
GamesProxyModel *model,
const QMap<int, QString> &allGameTypes);
void retranslateUi();
private:
TabSupervisor *tabSupervisor;
GamesProxyModel *model;
QHBoxLayout *mainLayout;
QLineEdit *searchBar;
QCheckBox *hideGamesWithoutBuddiesCheckBox;
QLabel *hideGamesWithoutBuddiesLabel;
QCheckBox *hideGamesNotCreatedByBuddiesCheckBox;
QLabel *hideGamesNotCreatedByBuddiesLabel;
QCheckBox *hideFullGamesCheckBox;
QLabel *hideFullGamesLabel;
QCheckBox *hideStartedGamesCheckBox;

View file

@ -294,7 +294,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames,
bool _hideNotBuddyCreatedGames,
bool _hideOpenDecklistGames,
const QString &_gameNameFilter,
const QString &_creatorNameFilter,
const QStringList &_creatorNameFilters,
const QSet<int> &_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<int, QString> &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<int, QString> &allGameType
gameFilters.setHideNotBuddyCreatedGames(hideNotBuddyCreatedGames);
gameFilters.setHideOpenDecklistGames(hideOpenDecklistGames);
gameFilters.setGameNameFilter(gameNameFilter);
gameFilters.setCreatorNameFilter(creatorNameFilter);
gameFilters.setCreatorNameFilters(creatorNameFilters);
QMapIterator<int, QString> gameTypeIterator(allGameTypes);
while (gameTypeIterator.hasNext()) {
@ -459,9 +459,18 @@ 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()) {
qInfo() << "Creator Name filters: " << creatorNameFilters;
bool found = false;
for (auto createNameFilter : creatorNameFilters) {
if (QString::fromStdString(game.creator_info().name()).contains(createNameFilter, Qt::CaseInsensitive)) {
found = true;
}
}
if (!found) {
return false;
}
}
QSet<int> gameTypes;
for (int i = 0; i < game.game_types_size(); ++i)

View file

@ -129,7 +129,8 @@ private:
bool hidePasswordProtectedGames;
bool hideNotBuddyCreatedGames;
bool hideOpenDecklistGames;
QString gameNameFilter, creatorNameFilter;
QString gameNameFilter;
QStringList creatorNameFilters;
QSet<int> gameTypeFilter;
quint32 maxPlayersFilterMin, maxPlayersFilterMax;
QTime maxGameAge;
@ -179,9 +180,9 @@ public:
{
return gameNameFilter;
}
QString getCreatorNameFilter() const
QStringList getCreatorNameFilters() const
{
return creatorNameFilter;
return creatorNameFilters;
}
QSet<int> getGameTypeFilter() const
{
@ -227,7 +228,7 @@ public:
bool _hideNotBuddyCreatedGames,
bool _hideOpenDecklistGames,
const QString &_gameNameFilter,
const QString &_creatorNameFilter,
const QStringList &_creatorNameFilter,
const QSet<int> &_gameTypeFilter,
int _maxPlayersFilterMin,
int _maxPlayersFilterMax,
@ -278,9 +279,9 @@ public:
gameNameFilter = value;
refresh();
}
void setCreatorNameFilter(const QString &value)
void setCreatorNameFilters(const QStringList &values)
{
creatorNameFilter = value;
creatorNameFilters = values;
refresh();
}
void setGameTypeFilter(const QSet<int> &value)

View file

@ -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();
}

View file

@ -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);