Sort Tags in TagFilterWidget

This commit is contained in:
Lukas Brübach 2025-02-14 13:20:54 +01:00
parent e8574641b0
commit e2671f03bf
2 changed files with 25 additions and 0 deletions

View file

@ -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;

View file

@ -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;