mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 12:33:55 -07:00
include folder name in VDS search when folders are enabled (#5637)
This commit is contained in:
parent
06b25f1cfc
commit
9ac13018c6
3 changed files with 30 additions and 7 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
#include "visual_deck_storage_search_widget.h"
|
#include "visual_deck_storage_search_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../settings/cache_settings.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a PrintingSelectorCardSearchWidget for searching cards by set name or set code.
|
* @brief Constructs a PrintingSelectorCardSearchWidget for searching cards by set name or set code.
|
||||||
*
|
*
|
||||||
|
|
@ -38,7 +40,29 @@ QString VisualDeckStorageSearchWidget::getSearchText()
|
||||||
return searchBar->text();
|
return searchBar->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageSearchWidget::filterWidgets(QList<DeckPreviewWidget *> widgets, const QString &searchText)
|
/**
|
||||||
|
* Gets the filename used for the search.
|
||||||
|
*
|
||||||
|
* if includeFolderName is true, then this returns the relative filepath starting from the deck folder.
|
||||||
|
* If the file isn't in the deck folder, or includeFolderName is false, then this will just return the filename.
|
||||||
|
*
|
||||||
|
* @param filePath The filePath to convert into a search name
|
||||||
|
*/
|
||||||
|
static QString getFileSearchName(const QString &filePath, bool includeFolderName)
|
||||||
|
{
|
||||||
|
QString deckPath = SettingsCache::instance().getDeckPath();
|
||||||
|
if (includeFolderName && filePath.startsWith(deckPath)) {
|
||||||
|
return filePath.mid(deckPath.length()).toLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo fileInfo(filePath);
|
||||||
|
QString fileName = fileInfo.fileName().toLower();
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckStorageSearchWidget::filterWidgets(QList<DeckPreviewWidget *> widgets,
|
||||||
|
const QString &searchText,
|
||||||
|
bool includeFolderName)
|
||||||
{
|
{
|
||||||
if (searchText.isEmpty() || searchText.isNull()) {
|
if (searchText.isEmpty() || searchText.isNull()) {
|
||||||
for (auto widget : widgets) {
|
for (auto widget : widgets) {
|
||||||
|
|
@ -47,9 +71,7 @@ void VisualDeckStorageSearchWidget::filterWidgets(QList<DeckPreviewWidget *> wid
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto file : widgets) {
|
for (auto file : widgets) {
|
||||||
QFileInfo fileInfo(file->filePath);
|
QString fileSearchName = getFileSearchName(file->filePath, includeFolderName);
|
||||||
QString fileName = fileInfo.fileName().toLower();
|
file->filteredBySearch = !fileSearchName.contains(searchText.toLower());
|
||||||
|
|
||||||
file->filteredBySearch = !fileName.contains(searchText.toLower());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class VisualDeckStorageSearchWidget : public QWidget
|
||||||
public:
|
public:
|
||||||
explicit VisualDeckStorageSearchWidget(VisualDeckStorageWidget *parent);
|
explicit VisualDeckStorageSearchWidget(VisualDeckStorageWidget *parent);
|
||||||
QString getSearchText();
|
QString getSearchText();
|
||||||
void filterWidgets(QList<DeckPreviewWidget *> widgets, const QString &searchText);
|
void filterWidgets(QList<DeckPreviewWidget *> widgets, const QString &searchText, bool includeFolderName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout *layout;
|
QHBoxLayout *layout;
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,8 @@ void VisualDeckStorageWidget::updateColorFilter()
|
||||||
void VisualDeckStorageWidget::updateSearchFilter()
|
void VisualDeckStorageWidget::updateSearchFilter()
|
||||||
{
|
{
|
||||||
if (folderWidget) {
|
if (folderWidget) {
|
||||||
searchWidget->filterWidgets(folderWidget->findChildren<DeckPreviewWidget *>(), searchWidget->getSearchText());
|
searchWidget->filterWidgets(folderWidget->findChildren<DeckPreviewWidget *>(), searchWidget->getSearchText(),
|
||||||
|
showFoldersCheckBox->isChecked());
|
||||||
}
|
}
|
||||||
emit searchFilterUpdated();
|
emit searchFilterUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue