Add search filter to card view window (#5791)

* refactor out search syntax help window

* add search bar to ZoneViewWidget

* implement filter logic
This commit is contained in:
RickyRister 2025-04-11 20:00:46 -07:00 committed by GitHub
parent ad06814ac7
commit 3b758962e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 116 additions and 40 deletions

View file

@ -148,7 +148,16 @@ void ZoneViewZone::updateCardIds(CardAction action)
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
void ZoneViewZone::reorganizeCards()
{
CardList cardsToDisplay(cards);
// filter cards
CardList cardsToDisplay = CardList(cards.getContentsKnown());
for (auto card : cards) {
if (filterString.check(card->getInfo())) {
card->show();
cardsToDisplay.append(card);
} else {
card->hide();
}
}
// sort cards
QList<CardList::SortOption> sortOptions;
@ -263,6 +272,12 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca
}
}
void ZoneViewZone::setFilterString(const QString &_filterString)
{
filterString = FilterString(_filterString);
reorganizeCards();
}
void ZoneViewZone::setGroupBy(CardList::SortOption _groupBy)
{
groupBy = _groupBy;

View file

@ -1,6 +1,7 @@
#ifndef ZONEVIEWERZONE_H
#define ZONEVIEWERZONE_H
#include "../filters/filter_string.h"
#include "select_zone.h"
#include <QGraphicsLayoutItem>
@ -35,6 +36,7 @@ private:
int minRows, numberCards;
CardZone *origZone;
bool revealZone, writeableRevealZone;
FilterString filterString = FilterString("");
CardList::SortOption groupBy, sortBy;
bool pileView;
bool isReversed;
@ -96,6 +98,7 @@ public:
}
public slots:
void close();
void setFilterString(const QString &_filterString);
void setGroupBy(CardList::SortOption _groupBy);
void setSortBy(CardList::SortOption _sortBy);
void setPileView(int _pileView);

View file

@ -1,7 +1,9 @@
#include "view_zone_widget.h"
#include "../../client/ui/pixel_map_generator.h"
#include "../../settings/cache_settings.h"
#include "../cards/card_item.h"
#include "../filters/syntax_help.h"
#include "../game_scene.h"
#include "../player/player.h"
#include "pb/command_shuffle.pb.h"
@ -41,9 +43,24 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
setFlag(ItemIgnoresTransformations);
QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical);
vbox->setSpacing(2);
// If the number is < 0, then it means that we can give the option to make the area sorted
if (numberCards < 0) {
// search edit
searchEdit.setFocusPolicy(Qt::ClickFocus);
searchEdit.setPlaceholderText(tr("Search by card name (or search expressions)"));
searchEdit.setClearButtonEnabled(true);
searchEdit.addAction(loadColorAdjustedPixmap("theme:icons/search"), QLineEdit::LeadingPosition);
auto help = searchEdit.addAction(QPixmap("theme:icons/info"), QLineEdit::TrailingPosition);
connect(help, &QAction::triggered, this, [this] { createSearchSyntaxHelpWindow(&searchEdit); });
QGraphicsProxyWidget *searchEditProxy = new QGraphicsProxyWidget;
searchEditProxy->setWidget(&searchEdit);
searchEditProxy->setZValue(2000000007);
vbox->addItem(searchEditProxy);
// top row
QGraphicsLinearLayout *hTopRow = new QGraphicsLinearLayout(Qt::Horizontal);
@ -128,6 +145,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
if (CardList::NoSort == static_cast<CardList::SortOption>(groupBySelector.currentData().toInt())) {
pileViewCheckBox.setEnabled(false);
}
connect(&searchEdit, &QLineEdit::textChanged, zone, &ZoneViewZone::setFilterString);
}
setLayout(vbox);

View file

@ -7,6 +7,7 @@
#include <QComboBox>
#include <QGraphicsProxyWidget>
#include <QGraphicsWidget>
#include <QLineEdit>
class QLabel;
class QPushButton;
@ -47,6 +48,8 @@ private:
QPushButton *closeButton;
QScrollBar *scrollBar;
ScrollableGraphicsProxyWidget *scrollBarProxy;
QLineEdit searchEdit;
QComboBox groupBySelector;
QComboBox sortBySelector;
QCheckBox shuffleCheckBox;