mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-08-23 09:15:02 -05:00
Sort Tags in TagFilterWidget (#5660)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
@@ -67,6 +67,7 @@ void VisualDeckStorageTagFilterWidget::refreshTags()
|
||||
QStringList allTags = gatherAllTags();
|
||||
removeTagsNotInList(gatherAllTags());
|
||||
addTagsIfNotPresent(gatherAllTags());
|
||||
sortTags();
|
||||
}
|
||||
|
||||
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 allTags;
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
void removeTagsNotInList(const QStringList &tags);
|
||||
void addTagsIfNotPresent(const QStringList &tags);
|
||||
void addTagIfNotPresent(const QString &tag);
|
||||
void sortTags();
|
||||
QStringList getAllKnownTags();
|
||||
VisualDeckStorageWidget *parent;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user