diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-20 16:49:21 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-21 08:21:23 (GMT) |
commit | 292a37301950a64f211e3a2909ff64884b73e1cc (patch) | |
tree | cf21b0824ffc294b5ddefd5bb4dab55add5f936b | |
parent | 7d572f0b4adf33db00352d8183b1e934cee85c39 (diff) | |
download | Qt-292a37301950a64f211e3a2909ff64884b73e1cc.zip Qt-292a37301950a64f211e3a2909ff64884b73e1cc.tar.gz Qt-292a37301950a64f211e3a2909ff64884b73e1cc.tar.bz2 |
Fix a bug in QFileDialog sidebar when the bookmark has an hidden parent
If the bookmark in the sidebar has an hidden parent and the QFileDialog
is set up to not show hidden files, then clicking on the bookmark move
the current dir to root (like if the bookmark was invalid) instead of
entering in the dir. The fix was to fetch the parent dir and the
bookmark dir when the user select it in the sidebar.
Task-number: 251321
Reviewed-by: jasplin
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 5 | ||||
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel.h | 2 | ||||
-rw-r--r-- | tests/auto/qfiledialog/tst_qfiledialog.cpp | 34 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 9935a80..d786f3e 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -693,7 +693,10 @@ void QFileDialog::setVisible(bool visible) */ void QFileDialogPrivate::_q_goToUrl(const QUrl &url) { - QModelIndex idx = model->index(url.toLocalFile()); + //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file) + //so we force the fetching + QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); + QModelIndex idx = model->d_func()->index(node); _q_enterDirectory(idx); } diff --git a/src/gui/dialogs/qfilesystemmodel.h b/src/gui/dialogs/qfilesystemmodel.h index 52ecaf9..995268b 100644 --- a/src/gui/dialogs/qfilesystemmodel.h +++ b/src/gui/dialogs/qfilesystemmodel.h @@ -158,6 +158,8 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort()) Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &)) Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName)) + + friend class QFileDialogPrivate; }; inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index 695bfe7..981d445 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -157,6 +157,7 @@ private slots: void task228844_ensurePreviousSorting(); void task239706_editableFilterCombo(); void task218353_relativePaths(); + void task251321_sideBarHiddenEntries(); private: QByteArray userSettings; @@ -1852,5 +1853,38 @@ void tst_QFiledialog::task218353_relativePaths() appDir.rmdir("test"); } +void tst_QFiledialog::task251321_sideBarHiddenEntries() +{ + QNonNativeFileDialog fd; + + QDir current = QDir::currentPath(); + current.mkdir(".hidden"); + QDir hiddenDir = QDir(".hidden"); + hiddenDir.mkdir("subdir"); + QDir hiddenSubDir = QDir(".hidden/subdir"); + hiddenSubDir.mkdir("happy"); + hiddenSubDir.mkdir("happy2"); + + QList<QUrl> urls; + urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); + fd.setSidebarUrls(urls); + fd.show(); + QTest::qWait(250); + + QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); + QTest::qWait(250); + + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2); + + hiddenSubDir.rmdir("happy2"); + hiddenSubDir.rmdir("happy"); + hiddenDir.rmdir("subdir"); + current.rmdir(".hidden"); +} + QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog.moc" |