mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -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();
|
||||
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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue