summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2019-09-23 14:35:33 +0200
committerGitHub <noreply@github.com>2019-09-23 14:35:33 +0200
commit9e730832d11b9a0eb5040e477500d77185beb529 (patch)
tree618b81aa10acf0fa0457071cac6ac309a4dac552
parentf9f9fba7ebad4f7fee7516f562d7bf9aa41dd703 (diff)
parenta06be7ff54122c0b10834d2b8ffcf3a74dc6b7b2 (diff)
Merge pull request #475 from maciejsszmigiero/directories-first-order-fix
Restore directories-first order of passwords tree view on non-Mac platforms
-rw-r--r--src/mainwindow.cpp9
-rw-r--r--src/storemodel.cpp17
-rw-r--r--src/storemodel.h2
3 files changed, 23 insertions, 5 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index c794a521..a3b1c9c5 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -65,16 +65,15 @@ MainWindow::MainWindow(const QString &searchText, QWidget *parent)
QString passStore = QtPassSettings::getPassStore(Util::findPasswordStore());
- proxyModel.setSourceModel(&model);
+ QModelIndex rootDir = model.setRootPath(passStore);
+ model.fetchMore(rootDir);
+
proxyModel.setModelAndStore(&model, passStore);
- // proxyModel.sort(0, Qt::AscendingOrder);
selectionModel.reset(new QItemSelectionModel(&proxyModel));
- model.fetchMore(model.setRootPath(passStore));
- // model.sort(0, Qt::AscendingOrder);
ui->treeView->setModel(&proxyModel);
ui->treeView->setRootIndex(
- proxyModel.mapFromSource(model.setRootPath(passStore)));
+ proxyModel.mapFromSource(rootDir));
ui->treeView->setColumnHidden(1, true);
ui->treeView->setColumnHidden(2, true);
ui->treeView->setColumnHidden(3, true);
diff --git a/src/storemodel.cpp b/src/storemodel.cpp
index a46e1b03..06c3c036 100644
--- a/src/storemodel.cpp
+++ b/src/storemodel.cpp
@@ -80,6 +80,7 @@ bool StoreModel::ShowThis(const QModelIndex index) const {
*/
void StoreModel::setModelAndStore(QFileSystemModel *sourceModel,
QString passStore) {
+ setSourceModel(sourceModel);
fs = sourceModel;
store = std::move(passStore);
}
@@ -255,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: