Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/group/GroupModel.cpp')
-rw-r--r--src/gui/group/GroupModel.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp
index dae9f759a..d3f2f40f6 100644
--- a/src/gui/group/GroupModel.cpp
+++ b/src/gui/group/GroupModel.cpp
@@ -410,3 +410,30 @@ void GroupModel::groupMoved()
{
endMoveRows();
}
+
+void GroupModel::sortChildren(Group* rootGroup, bool reverse)
+{
+ emit layoutAboutToBeChanged();
+
+ QList<QModelIndex> oldIndexes;
+ collectIndexesRecursively(oldIndexes, rootGroup->children());
+
+ rootGroup->sortChildrenRecursively(reverse);
+
+ QList<QModelIndex> newIndexes;
+ collectIndexesRecursively(newIndexes, rootGroup->children());
+
+ for (int i = 0; i < oldIndexes.count(); i++) {
+ changePersistentIndex(oldIndexes[i], newIndexes[i]);
+ }
+
+ emit layoutChanged();
+}
+
+void GroupModel::collectIndexesRecursively(QList<QModelIndex>& indexes, QList<Group*> groups)
+{
+ for (auto group : groups) {
+ indexes.append(index(group));
+ collectIndexesRecursively(indexes, group->children());
+ }
+}