From 0901f3f8055240d97def42d59e6a76e0b299e985 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Tue, 28 Apr 2009 10:54:11 +0200 Subject: Fix a crash with a proxy model applied on the QFileDialog. The problem was located in _q_enterDirectory, this method take a QModelIndex that can be a model index from the treeview/listview (so it comes from the proxy that is applied) and from the side bar where there is always no proxy applied. Previously we were trying to convert from a proxy index to a source index the value that come from the sidebar which is already a source model index. Now, we just check if the model index is coming from the proxy and in that case we convert it otherwise this model index come from the source. Task-number: 252068 Reviewed-by: jasplin Reviewed-by: ogoffart --- src/gui/dialogs/qfiledialog.cpp | 2 +- tests/auto/qfiledialog/tst_qfiledialog.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 073c25b..abb13c0 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -2793,7 +2793,7 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index) { Q_Q(QFileDialog); // My Computer or a directory - QModelIndex sourceIndex = mapToSource(index); + QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index; QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); if (path.isEmpty() || model->isDir(sourceIndex)) { q->setDirectory(path); diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index 13b13d6..689f73d 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -1602,6 +1602,19 @@ void tst_QFiledialog::task227304_proxyOnFileDialog() QTest::keyClick(list, Qt::Key_Return); QTest::qWait(200); + dialog->close(); + fd.close(); + + QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0); + QSortFilterProxyModel *pm = new QSortFilterProxyModel; + fd2.setProxyModel(pm); + fd2.show(); + QSidebar *sidebar = qFindChild(&fd2, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); + QTest::qWait(250); + //We shouldn't crash } void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior() -- cgit v0.12