mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
Sort Tags in TagFilterWidget (#5660)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
e8574641b0
commit
05d06f9016
2 changed files with 25 additions and 0 deletions
|
|
@ -67,6 +67,7 @@ void VisualDeckStorageTagFilterWidget::refreshTags()
|
||||||
QStringList allTags = gatherAllTags();
|
QStringList allTags = gatherAllTags();
|
||||||
removeTagsNotInList(gatherAllTags());
|
removeTagsNotInList(gatherAllTags());
|
||||||
addTagsIfNotPresent(gatherAllTags());
|
addTagsIfNotPresent(gatherAllTags());
|
||||||
|
sortTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageTagFilterWidget::removeTagsNotInList(const QStringList &tags)
|
void VisualDeckStorageTagFilterWidget::removeTagsNotInList(const QStringList &tags)
|
||||||
|
|
@ -112,6 +113,29 @@ void VisualDeckStorageTagFilterWidget::addTagIfNotPresent(const QString &tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDeckStorageTagFilterWidget::sortTags()
|
||||||
|
{
|
||||||
|
auto *flowWidget = findChild<FlowWidget *>();
|
||||||
|
if (!flowWidget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get all tag widgets
|
||||||
|
QList<DeckPreviewTagDisplayWidget *> tagWidgets = findChildren<DeckPreviewTagDisplayWidget *>();
|
||||||
|
|
||||||
|
// Sort widgets by tag name
|
||||||
|
std::sort(tagWidgets.begin(), tagWidgets.end(), [](DeckPreviewTagDisplayWidget *a, DeckPreviewTagDisplayWidget *b) {
|
||||||
|
return a->getTagName().toLower() < b->getTagName().toLower();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear and re-add widgets in sorted order
|
||||||
|
for (DeckPreviewTagDisplayWidget *tagWidget : tagWidgets) {
|
||||||
|
flowWidget->removeWidget(tagWidget);
|
||||||
|
}
|
||||||
|
for (DeckPreviewTagDisplayWidget *tagWidget : tagWidgets) {
|
||||||
|
flowWidget->addWidget(tagWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QStringList VisualDeckStorageTagFilterWidget::gatherAllTags()
|
QStringList VisualDeckStorageTagFilterWidget::gatherAllTags()
|
||||||
{
|
{
|
||||||
QStringList allTags;
|
QStringList allTags;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public:
|
||||||
void removeTagsNotInList(const QStringList &tags);
|
void removeTagsNotInList(const QStringList &tags);
|
||||||
void addTagsIfNotPresent(const QStringList &tags);
|
void addTagsIfNotPresent(const QStringList &tags);
|
||||||
void addTagIfNotPresent(const QString &tag);
|
void addTagIfNotPresent(const QString &tag);
|
||||||
|
void sortTags();
|
||||||
QStringList getAllKnownTags();
|
QStringList getAllKnownTags();
|
||||||
VisualDeckStorageWidget *parent;
|
VisualDeckStorageWidget *parent;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue