diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-28 08:54:11 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-28 08:59:44 (GMT) |
commit | 0901f3f8055240d97def42d59e6a76e0b299e985 (patch) | |
tree | 3898f7a46fdf25af66c391326d6ac67d9d2e490d | |
parent | 0f0dbd09f7bf2ef9d69d1e559ace961d9b236d3b (diff) | |
download | Qt-0901f3f8055240d97def42d59e6a76e0b299e985.zip Qt-0901f3f8055240d97def42d59e6a76e0b299e985.tar.gz Qt-0901f3f8055240d97def42d59e6a76e0b299e985.tar.bz2 |
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
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qfiledialog/tst_qfiledialog.cpp | 13 |
2 files changed, 14 insertions, 1 deletions
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<QSidebar*>(&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() |