mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 19:13:55 -07:00
VDS: Optimize refreshTags in VisualDeckStorageTagFilterWidget (#5856)
* make methods const * remove redundant calls to gatherAllTags * make methods private * use QSet instead of QStringList
This commit is contained in:
parent
aff4ffdf83
commit
39f87a5e78
2 changed files with 21 additions and 17 deletions
|
|
@ -64,13 +64,13 @@ void VisualDeckStorageTagFilterWidget::filterDecksBySelectedTags(const QList<Dec
|
||||||
|
|
||||||
void VisualDeckStorageTagFilterWidget::refreshTags()
|
void VisualDeckStorageTagFilterWidget::refreshTags()
|
||||||
{
|
{
|
||||||
QStringList allTags = gatherAllTags();
|
QSet<QString> allTags = gatherAllTags();
|
||||||
removeTagsNotInList(gatherAllTags());
|
removeTagsNotInList(allTags);
|
||||||
addTagsIfNotPresent(gatherAllTags());
|
addTagsIfNotPresent(allTags);
|
||||||
sortTags();
|
sortTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageTagFilterWidget::removeTagsNotInList(const QStringList &tags)
|
void VisualDeckStorageTagFilterWidget::removeTagsNotInList(const QSet<QString> &tags)
|
||||||
{
|
{
|
||||||
// Iterate through all DeckPreviewTagDisplayWidgets
|
// Iterate through all DeckPreviewTagDisplayWidgets
|
||||||
for (DeckPreviewTagDisplayWidget *tagWidget : findChildren<DeckPreviewTagDisplayWidget *>()) {
|
for (DeckPreviewTagDisplayWidget *tagWidget : findChildren<DeckPreviewTagDisplayWidget *>()) {
|
||||||
|
|
@ -83,7 +83,7 @@ void VisualDeckStorageTagFilterWidget::removeTagsNotInList(const QStringList &ta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageTagFilterWidget::addTagsIfNotPresent(const QStringList &tags)
|
void VisualDeckStorageTagFilterWidget::addTagsIfNotPresent(const QSet<QString> &tags)
|
||||||
{
|
{
|
||||||
for (const QString &tag : tags) {
|
for (const QString &tag : tags) {
|
||||||
addTagIfNotPresent(tag);
|
addTagIfNotPresent(tag);
|
||||||
|
|
@ -136,20 +136,22 @@ void VisualDeckStorageTagFilterWidget::sortTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList VisualDeckStorageTagFilterWidget::gatherAllTags()
|
QSet<QString> VisualDeckStorageTagFilterWidget::gatherAllTags() const
|
||||||
{
|
{
|
||||||
QStringList allTags;
|
QSet<QString> allTags;
|
||||||
QList<DeckPreviewWidget *> deckWidgets = parent->findChildren<DeckPreviewWidget *>();
|
QList<DeckPreviewWidget *> deckWidgets = parent->findChildren<DeckPreviewWidget *>();
|
||||||
|
|
||||||
for (DeckPreviewWidget *widget : deckWidgets) {
|
for (DeckPreviewWidget *widget : deckWidgets) {
|
||||||
if (widget->checkVisibility()) {
|
if (widget->checkVisibility()) {
|
||||||
allTags << widget->deckLoader->getTags();
|
for (const QString &tag : widget->deckLoader->getTags()) {
|
||||||
|
allTags.insert(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allTags;
|
return allTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList VisualDeckStorageTagFilterWidget::getAllKnownTags()
|
QStringList VisualDeckStorageTagFilterWidget::getAllKnownTags() const
|
||||||
{
|
{
|
||||||
QStringList allTags;
|
QStringList allTags;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,18 @@ class VisualDeckStorageTagFilterWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
VisualDeckStorageWidget *parent;
|
||||||
explicit VisualDeckStorageTagFilterWidget(VisualDeckStorageWidget *_parent);
|
|
||||||
QStringList gatherAllTags();
|
QSet<QString> gatherAllTags() const;
|
||||||
void filterDecksBySelectedTags(const QList<DeckPreviewWidget *> &deckPreviews) const;
|
void removeTagsNotInList(const QSet<QString> &tags);
|
||||||
void removeTagsNotInList(const QStringList &tags);
|
void addTagsIfNotPresent(const QSet<QString> &tags);
|
||||||
void addTagsIfNotPresent(const QStringList &tags);
|
|
||||||
void addTagIfNotPresent(const QString &tag);
|
void addTagIfNotPresent(const QString &tag);
|
||||||
void sortTags();
|
void sortTags();
|
||||||
QStringList getAllKnownTags();
|
|
||||||
VisualDeckStorageWidget *parent;
|
public:
|
||||||
|
explicit VisualDeckStorageTagFilterWidget(VisualDeckStorageWidget *_parent);
|
||||||
|
QStringList getAllKnownTags() const;
|
||||||
|
void filterDecksBySelectedTags(const QList<DeckPreviewWidget *> &deckPreviews) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void refreshTags();
|
void refreshTags();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue