diff options
author | Maciej S. Szmigiero <mail@maciej.szmigiero.name> | 2019-09-21 17:22:05 +0200 |
---|---|---|
committer | Maciej S. Szmigiero <mail@maciej.szmigiero.name> | 2019-09-21 17:31:50 +0200 |
commit | 18400bcf2b17f1d9b7871f4985b1bccbb3384cf5 (patch) | |
tree | 9af6860211359d691650eea125cdc0788d454b9e /src/storemodel.cpp | |
parent | 377114ea98e11610f57325b88954c18ba56d8f9c (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.
Diffstat (limited to 'src/storemodel.cpp')
-rw-r--r-- | src/storemodel.cpp | 16 |
1 files changed, 16 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); +} |