summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-04-21 08:17:56 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-04-21 08:21:23 (GMT)
commitb108e0479c6ec872ab767b8b81420b28ca1886cf (patch)
treef61d0d4b9147d87debd8685a4b76ea7674493e57 /tests
parent292a37301950a64f211e3a2909ff64884b73e1cc (diff)
downloadQt-b108e0479c6ec872ab767b8b81420b28ca1886cf.zip
Qt-b108e0479c6ec872ab767b8b81420b28ca1886cf.tar.gz
Qt-b108e0479c6ec872ab767b8b81420b28ca1886cf.tar.bz2
There is no way to delete a invalid entry in the sidebar of QFileDialog.
We can't remove an item in the sidebar if the bookmark is not valid (i.e. link to a non existing directory). ItemViews doesn't allow you to have disabled items and to select them at the same time, so i have implemented a delegate that paint in gray if the bookmark is invalid. So you can click on it and delete it. Task-number: 251341 Reviewed-by: jasplin
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfiledialog/tst_qfiledialog.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp
index 981d445..13b13d6 100644
--- a/tests/auto/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp
@@ -158,6 +158,7 @@ private slots:
void task239706_editableFilterCombo();
void task218353_relativePaths();
void task251321_sideBarHiddenEntries();
+ void task251341_sideBarRemoveEntries();
private:
QByteArray userSettings;
@@ -1886,5 +1887,86 @@ void tst_QFiledialog::task251321_sideBarHiddenEntries()
current.rmdir(".hidden");
}
+class MyQSideBar : public QSidebar
+{
+public :
+ MyQSideBar(QWidget *parent = 0) : QSidebar(parent)
+ {}
+
+ void removeSelection() {
+ QList<QModelIndex> idxs = selectionModel()->selectedIndexes();
+ QList<QPersistentModelIndex> indexes;
+ for (int i = 0; i < idxs.count(); i++)
+ indexes.append(idxs.at(i));
+
+ for (int i = 0; i < indexes.count(); ++i)
+ if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty())
+ model()->removeRow(indexes.at(i).row());
+ }
+};
+
+void tst_QFiledialog::task251341_sideBarRemoveEntries()
+{
+ QNonNativeFileDialog fd;
+
+ QDir current = QDir::currentPath();
+ current.mkdir("testDir");
+ QDir testSubDir = QDir("testDir");
+
+ QList<QUrl> urls;
+ urls << QUrl::fromLocalFile(testSubDir.absolutePath());
+ urls << QUrl::fromLocalFile("NotFound");
+ fd.setSidebarUrls(urls);
+ fd.show();
+ QTest::qWait(250);
+
+ QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar");
+ sidebar->setFocus();
+ //We enter in the first bookmark
+ sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.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");
+ //There is no file
+ QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0);
+ //Icon is not enabled QUrlModel::EnabledRole
+ QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2);
+ QCOMPARE(qvariant_cast<bool>(value), true);
+
+ sidebar->setFocus();
+ //We enter in the second bookmark which is invalid
+ sidebar->selectUrl(QUrl::fromLocalFile("NotFound"));
+ QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center());
+ QTest::qWait(250);
+
+ //We fallback to root because the entry in the bookmark is invalid
+ QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath())));
+ //Icon is not enabled QUrlModel::EnabledRole
+ value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2);
+ QCOMPARE(qvariant_cast<bool>(value), false);
+
+ MyQSideBar mySideBar;
+ mySideBar.init(model, urls);
+ mySideBar.show();
+ mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath()));
+ QTest::qWait(1000);
+ mySideBar.removeSelection();
+
+ //We remove the first entry
+ QList<QUrl> expected;
+ expected << QUrl::fromLocalFile("NotFound");
+ QCOMPARE(mySideBar.urls(), expected);
+
+ mySideBar.selectUrl(QUrl::fromLocalFile("NotFound"));
+ mySideBar.removeSelection();
+
+ //We remove the second entry
+ expected.clear();
+ QCOMPARE(mySideBar.urls(), expected);
+
+ current.rmdir("testDir");
+}
+
QTEST_MAIN(tst_QFiledialog)
#include "tst_qfiledialog.moc"