mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 20:43:54 -07:00
[VDD] Filter performance (#5974)
* Sort saved filters by name. * Optimize performance, allow loading name filters from clipboard. * Fix include. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
fe57efb1a8
commit
a688a5fe72
4 changed files with 41 additions and 6 deletions
|
|
@ -125,7 +125,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::refreshFilterList()
|
||||||
|
|
||||||
// Refresh the filter file list
|
// Refresh the filter file list
|
||||||
QDir dir(SettingsCache::instance().getFiltersPath());
|
QDir dir(SettingsCache::instance().getFiltersPath());
|
||||||
QStringList filterFiles = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Time);
|
QStringList filterFiles = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Name);
|
||||||
|
|
||||||
// Loop through the filter files and create widgets for them
|
// Loop through the filter files and create widgets for them
|
||||||
for (const QString &filename : filterFiles) {
|
for (const QString &filename : filterFiles) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "visual_database_display_name_filter_widget.h"
|
#include "visual_database_display_name_filter_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../dialogs/dlg_load_deck_from_clipboard.h"
|
||||||
#include "../../../tabs/abstract_tab_deck_editor.h"
|
#include "../../../tabs/abstract_tab_deck_editor.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
|
@ -35,6 +36,13 @@ VisualDatabaseDisplayNameFilterWidget::VisualDatabaseDisplayNameFilterWidget(QWi
|
||||||
layout->addWidget(loadFromDeckButton);
|
layout->addWidget(loadFromDeckButton);
|
||||||
|
|
||||||
connect(loadFromDeckButton, &QPushButton::clicked, this, &VisualDatabaseDisplayNameFilterWidget::actLoadFromDeck);
|
connect(loadFromDeckButton, &QPushButton::clicked, this, &VisualDatabaseDisplayNameFilterWidget::actLoadFromDeck);
|
||||||
|
|
||||||
|
loadFromClipboardButton = new QPushButton(this);
|
||||||
|
layout->addWidget(loadFromClipboardButton);
|
||||||
|
|
||||||
|
connect(loadFromClipboardButton, &QPushButton::clicked, this,
|
||||||
|
&VisualDatabaseDisplayNameFilterWidget::actLoadFromClipboard);
|
||||||
|
|
||||||
connect(filterModel, &FilterTreeModel::layoutChanged, this,
|
connect(filterModel, &FilterTreeModel::layoutChanged, this,
|
||||||
[this]() { QTimer::singleShot(100, this, &VisualDatabaseDisplayNameFilterWidget::syncWithFilterModel); });
|
[this]() { QTimer::singleShot(100, this, &VisualDatabaseDisplayNameFilterWidget::syncWithFilterModel); });
|
||||||
|
|
||||||
|
|
@ -46,6 +54,8 @@ void VisualDatabaseDisplayNameFilterWidget::retranslateUi()
|
||||||
searchBox->setPlaceholderText(tr("Filter by name..."));
|
searchBox->setPlaceholderText(tr("Filter by name..."));
|
||||||
loadFromDeckButton->setText(tr("Load from Deck"));
|
loadFromDeckButton->setText(tr("Load from Deck"));
|
||||||
loadFromDeckButton->setToolTip(tr("Apply all card names in currently loaded deck as exact match name filters"));
|
loadFromDeckButton->setToolTip(tr("Apply all card names in currently loaded deck as exact match name filters"));
|
||||||
|
loadFromClipboardButton->setText(tr("Load from Clipboard"));
|
||||||
|
loadFromClipboardButton->setToolTip(tr("Apply all card names in clipboard as exact match name filters"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDatabaseDisplayNameFilterWidget::actLoadFromDeck()
|
void VisualDatabaseDisplayNameFilterWidget::actLoadFromDeck()
|
||||||
|
|
@ -75,6 +85,20 @@ void VisualDatabaseDisplayNameFilterWidget::actLoadFromDeck()
|
||||||
updateFilterModel();
|
updateFilterModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDatabaseDisplayNameFilterWidget::actLoadFromClipboard()
|
||||||
|
{
|
||||||
|
DlgLoadDeckFromClipboard dlg(this);
|
||||||
|
if (!dlg.exec())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList cardsInClipboard = dlg.getDeckList()->getCardList();
|
||||||
|
for (QString cardName : cardsInClipboard) {
|
||||||
|
createNameFilter(cardName);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFilterModel();
|
||||||
|
}
|
||||||
|
|
||||||
void VisualDatabaseDisplayNameFilterWidget::createNameFilter(const QString &name)
|
void VisualDatabaseDisplayNameFilterWidget::createNameFilter(const QString &name)
|
||||||
{
|
{
|
||||||
if (activeFilters.contains(name))
|
if (activeFilters.contains(name))
|
||||||
|
|
@ -85,7 +109,11 @@ void VisualDatabaseDisplayNameFilterWidget::createNameFilter(const QString &name
|
||||||
button->setStyleSheet("QPushButton { background-color: lightgray; border: 1px solid gray; padding: 5px; }"
|
button->setStyleSheet("QPushButton { background-color: lightgray; border: 1px solid gray; padding: 5px; }"
|
||||||
"QPushButton:hover { background-color: red; color: white; }");
|
"QPushButton:hover { background-color: red; color: white; }");
|
||||||
|
|
||||||
connect(button, &QPushButton::clicked, this, [this, name]() { removeNameFilter(name); });
|
connect(button, &QPushButton::clicked, this, [this, name]() {
|
||||||
|
removeNameFilter(name);
|
||||||
|
QTimer::singleShot(0, this,
|
||||||
|
&VisualDatabaseDisplayNameFilterWidget::updateFilterModel); // Avoid concurrent modification
|
||||||
|
});
|
||||||
|
|
||||||
flowWidget->addWidget(button);
|
flowWidget->addWidget(button);
|
||||||
activeFilters[name] = button;
|
activeFilters[name] = button;
|
||||||
|
|
@ -96,9 +124,6 @@ void VisualDatabaseDisplayNameFilterWidget::removeNameFilter(const QString &name
|
||||||
if (activeFilters.contains(name)) {
|
if (activeFilters.contains(name)) {
|
||||||
activeFilters[name]->deleteLater(); // Safe deletion
|
activeFilters[name]->deleteLater(); // Safe deletion
|
||||||
activeFilters.remove(name);
|
activeFilters.remove(name);
|
||||||
|
|
||||||
QTimer::singleShot(0, this,
|
|
||||||
&VisualDatabaseDisplayNameFilterWidget::updateFilterModel); // Avoid concurrent modification
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,13 @@ private:
|
||||||
QLineEdit *searchBox;
|
QLineEdit *searchBox;
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
QPushButton *loadFromDeckButton;
|
QPushButton *loadFromDeckButton;
|
||||||
|
QPushButton *loadFromClipboardButton;
|
||||||
|
|
||||||
QMap<QString, QPushButton *> activeFilters; // Store active name filter buttons
|
QMap<QString, QPushButton *> activeFilters; // Store active name filter buttons
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actLoadFromDeck();
|
void actLoadFromDeck();
|
||||||
|
void actLoadFromClipboard();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISUAL_DATABASE_DISPLAY_NAME_FILTER_WIDGET_H
|
#endif // VISUAL_DATABASE_DISPLAY_NAME_FILTER_WIDGET_H
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,15 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
|
||||||
clearFilterWidget = new QToolButton();
|
clearFilterWidget = new QToolButton();
|
||||||
clearFilterWidget->setFixedSize(32, 32);
|
clearFilterWidget->setFixedSize(32, 32);
|
||||||
clearFilterWidget->setIcon(QPixmap("theme:icons/delete"));
|
clearFilterWidget->setIcon(QPixmap("theme:icons/delete"));
|
||||||
connect(clearFilterWidget, &QToolButton::clicked, this, [this] { filterModel->clear(); });
|
connect(clearFilterWidget, &QToolButton::clicked, this, [this] {
|
||||||
|
filterModel->blockSignals(true);
|
||||||
|
filterModel->filterTree()->blockSignals(true);
|
||||||
|
filterModel->clear();
|
||||||
|
filterModel->blockSignals(false);
|
||||||
|
filterModel->filterTree()->blockSignals(false);
|
||||||
|
emit filterModel->filterTree()->changed();
|
||||||
|
emit filterModel->layoutChanged();
|
||||||
|
});
|
||||||
|
|
||||||
quickFilterSaveLoadWidget = new SettingsButtonWidget(this);
|
quickFilterSaveLoadWidget = new SettingsButtonWidget(this);
|
||||||
quickFilterSaveLoadWidget->setButtonIcon(QPixmap("theme:icons/lock"));
|
quickFilterSaveLoadWidget->setButtonIcon(QPixmap("theme:icons/lock"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue