Sort Tags in TagFilterWidget (#5660)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-02-26 17:59:59 +01:00 committed by GitHub
parent e8574641b0
commit 05d06f9016
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;