[GameSelector/Filters] Properly sync toolbar and dialog. (#6822)

Took 59 minutes

Took 2 minutes

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-04-20 13:19:29 +02:00 committed by GitHub
parent ccb9901b28
commit 98c4e829f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 145 additions and 26 deletions

View file

@ -91,6 +91,7 @@ GameSelector::GameSelector(AbstractClient *_client,
bool filtersSetToDefault = showFilters && gameListProxyModel->areFilterParametersSetToDefaults(); bool filtersSetToDefault = showFilters && gameListProxyModel->areFilterParametersSetToDefaults();
clearFilterButton->setEnabled(!filtersSetToDefault); clearFilterButton->setEnabled(!filtersSetToDefault);
connect(clearFilterButton, &QPushButton::clicked, this, &GameSelector::actClearFilter); connect(clearFilterButton, &QPushButton::clicked, this, &GameSelector::actClearFilter);
connect(gameListProxyModel, &GamesProxyModel::filtersChanged, this, &GameSelector::checkClearFilterButtonState);
if (room) { if (room) {
createButton = new QPushButton; createButton = new QPushButton;
@ -188,15 +189,16 @@ void GameSelector::actSetFilter()
dlg.getShowOnlyIfSpectatorsCanChat(), dlg.getShowOnlyIfSpectatorsCanSeeHands()); dlg.getShowOnlyIfSpectatorsCanChat(), dlg.getShowOnlyIfSpectatorsCanSeeHands());
gameListProxyModel->saveFilterParameters(gameTypeMap); gameListProxyModel->saveFilterParameters(gameTypeMap);
clearFilterButton->setEnabled(!gameListProxyModel->areFilterParametersSetToDefaults());
updateTitle(); updateTitle();
} }
void GameSelector::checkClearFilterButtonState()
{
clearFilterButton->setEnabled(!gameListProxyModel->areFilterParametersSetToDefaults());
}
void GameSelector::actClearFilter() void GameSelector::actClearFilter()
{ {
clearFilterButton->setEnabled(false);
gameListProxyModel->resetFilterParameters(); gameListProxyModel->resetFilterParameters();
gameListProxyModel->saveFilterParameters(gameTypeMap); gameListProxyModel->saveFilterParameters(gameTypeMap);

View file

@ -40,6 +40,7 @@ private slots:
* Updates the proxy model with selected filter parameters and refreshes the displayed game list. * Updates the proxy model with selected filter parameters and refreshes the displayed game list.
*/ */
void actSetFilter(); void actSetFilter();
void checkClearFilterButtonState();
/** /**
* @brief Clears all filters applied to the game list. * @brief Clears all filters applied to the game list.

View file

@ -19,32 +19,46 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
mainLayout->setSpacing(5); mainLayout->setSpacing(5);
searchBar = new QLineEdit(this); searchBar = new QLineEdit(this);
searchBar->setText(model->getCreatorNameFilters().join(", ")); searchBar->setText(model->getGameNameFilter());
connect(searchBar, &QLineEdit::textChanged, this, [this](const QString &text) { model->setGameNameFilter(text); }); connect(searchBar, &QLineEdit::textChanged, this, [this](const QString &text) {
applyFilters([&](auto &, auto &, auto &, auto &, auto &, auto &, auto &, QString &gameNameFilter, auto &,
auto &, auto &, auto &, auto &, auto &, auto &, auto &, auto &) { gameNameFilter = text; });
});
hideGamesNotCreatedByBuddiesCheckBox = new QCheckBox(this); hideGamesNotCreatedByBuddiesCheckBox = new QCheckBox(this);
hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideBuddiesOnlyGames()); hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideNotBuddyCreatedGames());
connect(hideGamesNotCreatedByBuddiesCheckBox, &QCheckBox::toggled, this, [this](bool checked) { connect(hideGamesNotCreatedByBuddiesCheckBox, &QCheckBox::toggled, this, [this](bool checked) {
if (checked) { applyFilters([&](auto &, auto &, auto &, auto &, auto &, bool &hideNotBuddyCreatedGames, auto &, auto &,
QStringList buddyNames; QStringList &creatorNameFilters, auto &, auto &, auto &, auto &, auto &, auto &, auto &,
for (auto buddy : tabSupervisor->getUserListManager()->getBuddyList().values()) { auto &) {
buddyNames << QString::fromStdString(buddy.name()); hideNotBuddyCreatedGames = checked;
if (checked) {
QStringList buddyNames;
for (auto buddy : tabSupervisor->getUserListManager()->getBuddyList().values()) {
buddyNames << QString::fromStdString(buddy.name());
}
creatorNameFilters = buddyNames;
} else {
creatorNameFilters.clear();
} }
model->setCreatorNameFilters(buddyNames); });
} else {
model->setCreatorNameFilters({});
}
}); });
hideFullGamesCheckBox = new QCheckBox(this); hideFullGamesCheckBox = new QCheckBox(this);
hideFullGamesCheckBox->setChecked(model->getHideFullGames()); hideFullGamesCheckBox->setChecked(model->getHideFullGames());
connect(hideFullGamesCheckBox, &QCheckBox::toggled, this, connect(hideFullGamesCheckBox, &QCheckBox::toggled, this, [this](bool checked) {
[this](bool checked) { model->setHideFullGames(checked); }); applyFilters([&](auto &, auto &, bool &hideFullGames, auto &, auto &, auto &, auto &, auto &, auto &, auto &,
auto &, auto &, auto &, auto &, auto &, auto &, auto &) { hideFullGames = checked; });
});
hideStartedGamesCheckBox = new QCheckBox(this); hideStartedGamesCheckBox = new QCheckBox(this);
hideStartedGamesCheckBox->setChecked(model->getHideGamesThatStarted()); hideStartedGamesCheckBox->setChecked(model->getHideGamesThatStarted());
connect(hideStartedGamesCheckBox, &QCheckBox::toggled, this, connect(hideStartedGamesCheckBox, &QCheckBox::toggled, this, [this](bool checked) {
[this](bool checked) { model->setHideGamesThatStarted(checked); }); applyFilters([&](auto &, auto &, auto &, bool &hideGamesThatStarted, auto &, auto &, auto &, auto &, auto &,
auto &, auto &, auto &, auto &, auto &, auto &, auto &,
auto &) { hideGamesThatStarted = checked; });
});
filterToFormatComboBox = new QComboBox(this); filterToFormatComboBox = new QComboBox(this);
@ -69,13 +83,15 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
// Update proxy model on selection change // Update proxy model on selection change
connect(filterToFormatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) { connect(filterToFormatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
QVariant data = filterToFormatComboBox->itemData(index); applyFilters([&](auto &, auto &, auto &, auto &, auto &, auto &, auto &, auto &, auto &,
if (!data.isValid()) { QSet<int> &gameTypeFilter, auto &, auto &, auto &, auto &, auto &, auto &, auto &) {
model->setGameTypeFilter({}); // empty = no filter QVariant data = filterToFormatComboBox->itemData(index);
} else { if (!data.isValid()) {
int typeId = data.toInt(); gameTypeFilter.clear();
model->setGameTypeFilter({typeId}); } else {
} gameTypeFilter = {data.toInt()};
}
});
}); });
hideGamesNotCreatedByBuddiesCheckBox->setMinimumSize(20, 20); hideGamesNotCreatedByBuddiesCheckBox->setMinimumSize(20, 20);
@ -96,9 +112,87 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
setLayout(mainLayout); setLayout(mainLayout);
syncFromModel();
connect(model, &GamesProxyModel::filtersChanged, this, &GameSelectorQuickFilterToolBar::syncFromModel);
retranslateUi(); retranslateUi();
} }
void GameSelectorQuickFilterToolBar::syncFromModel()
{
QSignalBlocker b1(searchBar);
QSignalBlocker b2(filterToFormatComboBox);
QSignalBlocker b3(hideGamesNotCreatedByBuddiesCheckBox);
QSignalBlocker b4(hideFullGamesCheckBox);
QSignalBlocker b5(hideStartedGamesCheckBox);
searchBar->setText(model->getGameNameFilter());
hideGamesNotCreatedByBuddiesCheckBox->setChecked(model->getHideNotBuddyCreatedGames());
hideFullGamesCheckBox->setChecked(model->getHideFullGames());
hideStartedGamesCheckBox->setChecked(model->getHideGamesThatStarted());
QSet<int> types = model->getGameTypeFilter();
if (types.size() == 1) {
int idx = filterToFormatComboBox->findData(*types.begin());
filterToFormatComboBox->setCurrentIndex(idx >= 0 ? idx : 0);
} else {
filterToFormatComboBox->setCurrentIndex(0);
}
}
void GameSelectorQuickFilterToolBar::applyFilters(std::function<void(bool &,
bool &,
bool &,
bool &,
bool &,
bool &,
bool &,
QString &,
QStringList &,
QSet<int> &,
int &,
int &,
QTime &,
bool &,
bool &,
bool &,
bool &)> mutator)
{
bool hideBuddiesOnlyGames = model->getHideBuddiesOnlyGames();
bool hideIgnoredUserGames = model->getHideIgnoredUserGames();
bool hideFullGames = model->getHideFullGames();
bool hideGamesThatStarted = model->getHideGamesThatStarted();
bool hidePasswordProtectedGames = model->getHidePasswordProtectedGames();
bool hideNotBuddyCreatedGames = model->getHideNotBuddyCreatedGames();
bool hideOpenDecklistGames = model->getHideOpenDecklistGames();
QString gameNameFilter = model->getGameNameFilter();
QStringList creatorNameFilters = model->getCreatorNameFilters();
QSet<int> gameTypeFilter = model->getGameTypeFilter();
int minPlayers = model->getMaxPlayersFilterMin();
int maxPlayers = model->getMaxPlayersFilterMax();
QTime maxGameAge = model->getMaxGameAge();
bool showOnlyIfSpectatorsCanWatch = model->getShowOnlyIfSpectatorsCanWatch();
bool showSpectatorPasswordProtected = model->getShowSpectatorPasswordProtected();
bool showOnlyIfSpectatorsCanChat = model->getShowOnlyIfSpectatorsCanChat();
bool showOnlyIfSpectatorsCanSeeHands = model->getShowOnlyIfSpectatorsCanSeeHands();
mutator(hideBuddiesOnlyGames, hideIgnoredUserGames, hideFullGames, hideGamesThatStarted, hidePasswordProtectedGames,
hideNotBuddyCreatedGames, hideOpenDecklistGames, gameNameFilter, creatorNameFilters, gameTypeFilter,
minPlayers, maxPlayers, maxGameAge, showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected,
showOnlyIfSpectatorsCanChat, showOnlyIfSpectatorsCanSeeHands);
model->setGameFilters(hideBuddiesOnlyGames, hideIgnoredUserGames, hideFullGames, hideGamesThatStarted,
hidePasswordProtectedGames, hideNotBuddyCreatedGames, hideOpenDecklistGames, gameNameFilter,
creatorNameFilters, gameTypeFilter, minPlayers, maxPlayers, maxGameAge,
showOnlyIfSpectatorsCanWatch, showSpectatorPasswordProtected, showOnlyIfSpectatorsCanChat,
showOnlyIfSpectatorsCanSeeHands);
}
void GameSelectorQuickFilterToolBar::retranslateUi() void GameSelectorQuickFilterToolBar::retranslateUi()
{ {
searchBar->setPlaceholderText(tr("Filter by game name...")); searchBar->setPlaceholderText(tr("Filter by game name..."));

View file

@ -18,6 +18,24 @@ public:
TabSupervisor *tabSupervisor, TabSupervisor *tabSupervisor,
GamesProxyModel *model, GamesProxyModel *model,
const QMap<int, QString> &allGameTypes); const QMap<int, QString> &allGameTypes);
void syncFromModel();
void applyFilters(std::function<void(bool &,
bool &,
bool &,
bool &,
bool &,
bool &,
bool &,
QString &,
QStringList &,
QSet<int> &,
int &,
int &,
QTime &,
bool &,
bool &,
bool &,
bool &)> mutator);
void retranslateUi(); void retranslateUi();
private: private:

View file

@ -326,6 +326,7 @@ void GamesProxyModel::setGameFilters(bool _hideBuddiesOnlyGames,
#else #else
invalidateFilter(); invalidateFilter();
#endif #endif
emit filtersChanged();
} }
int GamesProxyModel::getNumFilteredGames() const int GamesProxyModel::getNumFilteredGames() const

View file

@ -138,6 +138,9 @@ private:
bool showOnlyIfSpectatorsCanChat; bool showOnlyIfSpectatorsCanChat;
bool showOnlyIfSpectatorsCanSeeHands; bool showOnlyIfSpectatorsCanSeeHands;
signals:
void filtersChanged();
public: public:
/** /**
* @brief Constructs a GamesProxyModel. * @brief Constructs a GamesProxyModel.