summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <mail@maciej.szmigiero.name>2019-09-21 17:22:05 +0200
committerMaciej S. Szmigiero <mail@maciej.szmigiero.name>2019-09-21 17:31:50 +0200
commit18400bcf2b17f1d9b7871f4985b1bccbb3384cf5 (patch)
tree9af6860211359d691650eea125cdc0788d454b9e
parent377114ea98e11610f57325b88954c18ba56d8f9c (diff)
Restore directories-first order of passwords tree view on non-Mac platforms
Since commit b4dc9e69e7c553 ("Auto update CHANGELOG and sorting of treeview") directories are no longer listed first in the tree view of passwords. This is because a simple sort of the tree view widget (as enabled by the aforementioned commit) does its work by sorting the backing StoreModel (QSortFilterProxyModel), which in turn does just a simple lexicographical order sort on the path of each its item. Before that commit the sort was done by QFileSystemModel via QFileSystemModelSorter, which always places its directories first on non-Mac platforms. Unfortunately, QFileSystemModelSorter is an internal Qt helper class, so we can't just use it directly, we need to open-code a bit of logic from QFileSystemModelSorter::compareNodes() into StoreModel::lessThan() to restore the old behavior.
-rw-r--r--src/storemodel.cpp16
-rw-r--r--src/storemodel.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/src/storemodel.cpp b/src/storemodel.cpp
index b6fef94c..06c3c036 100644
--- a/src/storemodel.cpp
+++ b/src/storemodel.cpp
@@ -256,3 +256,19 @@ bool StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
}
return true;
}
+
+bool StoreModel::lessThan(const QModelIndex &source_left,
+ const QModelIndex &source_right) const {
+/* matches logic in QFileSystemModelSorter::compareNodes() */
+#ifndef Q_OS_MAC
+ if (fs && (source_left.column() == 0 || source_left.column() == 1)) {
+ bool leftD = fs->isDir(source_left);
+ bool rightD = fs->isDir(source_right);
+
+ if (leftD ^ rightD)
+ return leftD;
+ }
+#endif
+
+ return QSortFilterProxyModel::lessThan(source_left, source_right);
+}
diff --git a/src/storemodel.h b/src/storemodel.h
index 66486b10..6c8053e9 100644
--- a/src/storemodel.h
+++ b/src/storemodel.h
@@ -23,6 +23,8 @@ public:
bool ShowThis(const QModelIndex) const;
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore);
QVariant data(const QModelIndex &index, int role) const;
+ bool lessThan(const QModelIndex &source_left,
+ const QModelIndex &source_right) const override;
// QAbstractItemModel interface
public: