Filter: sort filter items in FilterModelBase::updateList()

All callers of FilterModelBase::updateList() sorted the items
(except the last one). Thus we can do the sorting inside the
function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-28 20:54:53 +02:00 committed by Dirk Hohndel
parent 9b90c461a2
commit 236f0512be
2 changed files with 7 additions and 6 deletions

View file

@ -102,8 +102,13 @@ void FilterModelBase::changeName(const QString &oldName, const QString &newName)
// Update the the items array. // Update the the items array.
// The last item is supposed to be the "Show Empty Tags" entry. // The last item is supposed to be the "Show Empty Tags" entry.
void FilterModelBase::updateList(const QStringList &newList) // All other items will be sorted alphabetically. Attention: the passed-in list is modified!
void FilterModelBase::updateList(QStringList &newList)
{ {
// Sort list, but leave out last element by using std::prev()
if (!newList.empty())
std::sort(newList.begin(), std::prev(newList.end()));
beginResetModel(); beginResetModel();
// Keep copy of the old items array to reimport the checked state later. // Keep copy of the old items array to reimport the checked state later.
@ -264,7 +269,6 @@ void SuitsFilterModel::repopulate()
list.append(suit); list.append(suit);
} }
} }
qSort(list);
list << tr("No suit set"); list << tr("No suit set");
updateList(list); updateList(list);
} }
@ -289,7 +293,6 @@ void TagFilterModel::repopulate()
list.append(QString(current_tag_entry->tag->name)); list.append(QString(current_tag_entry->tag->name));
current_tag_entry = current_tag_entry->next; current_tag_entry = current_tag_entry->next;
} }
qSort(list);
list << tr("Empty tags"); list << tr("Empty tags");
updateList(list); updateList(list);
} }
@ -368,7 +371,6 @@ void BuddyFilterModel::repopulate()
} }
} }
} }
qSort(list);
list << tr("No buddies"); list << tr("No buddies");
updateList(list); updateList(list);
} }
@ -415,7 +417,6 @@ void LocationFilterModel::repopulate()
list.append(location); list.append(location);
} }
} }
qSort(list);
list << tr("No location set"); list << tr("No location set");
updateList(list); updateList(list);
} }

View file

@ -36,7 +36,7 @@ slots:
void changeName(const QString &oldName, const QString &newName); void changeName(const QString &oldName, const QString &newName);
protected: protected:
explicit FilterModelBase(QObject *parent = 0); explicit FilterModelBase(QObject *parent = 0);
void updateList(const QStringList &new_list); void updateList(QStringList &new_list);
virtual int countDives(const char *) const = 0; virtual int countDives(const char *) const = 0;
private: private:
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;