Add group sorting feature

* Enabling sorting of groups and their children in ascending and descending direction
This commit is contained in:
Balazs Gyurak 2019-06-18 21:58:47 +01:00 committed by Jonathan White
parent 0c2d1bcc50
commit 09181fab13
15 changed files with 373 additions and 0 deletions

View file

@ -521,6 +521,11 @@ QStringList Group::hierarchy() const
return hierarchy;
}
bool Group::hasChildren() const
{
return !children().isEmpty();
}
Database* Group::database()
{
return m_db;
@ -1074,6 +1079,23 @@ void Group::applyGroupIconTo(Entry* entry)
}
}
void Group::sortChildrenRecursively(bool reverse)
{
std::sort(
m_children.begin(), m_children.end(), [reverse](const Group* childGroup1, const Group* childGroup2) -> bool {
QString name1 = childGroup1->name();
QString name2 = childGroup2->name();
return reverse ? name1.compare(name2, Qt::CaseInsensitive) > 0
: name1.compare(name2, Qt::CaseInsensitive) < 0;
});
for (auto child : m_children) {
child->sortChildrenRecursively(reverse);
}
emit groupModified();
}
bool Group::GroupData::operator==(const Group::GroupData& other) const
{
return equals(other, CompareItemDefault);