diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2010-01-04 16:25:38 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2010-01-04 16:27:04 (GMT) |
commit | 5c2d319ce56fa7914afe52ae13f1a24c03608629 (patch) | |
tree | 693badecb0df7b049f59d40b4e318c4243d4ac00 /tests | |
parent | 4cfb341b0cc38f32fb6fba134bfeb96197337867 (diff) | |
download | Qt-5c2d319ce56fa7914afe52ae13f1a24c03608629.zip Qt-5c2d319ce56fa7914afe52ae13f1a24c03608629.tar.gz Qt-5c2d319ce56fa7914afe52ae13f1a24c03608629.tar.bz2 |
Make the ShowDirsOnly option work in QFileDialog.
This option was simply not implemented at all so it didn't work.
Task-number:QTBUG-6558
Reviewed-by:ogoffart
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfiledialog2/tst_qfiledialog2.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp index 83ddd39..83380a5 100644 --- a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp @@ -130,6 +130,7 @@ private slots: void task259105_filtersCornerCases(); void QTBUG4419_lineEditSelectAll(); + void QTBUG6558_showDirsOnly(); private: QByteArray userSettings; @@ -1040,5 +1041,72 @@ void tst_QFiledialog::QTBUG4419_lineEditSelectAll() QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName()); } +void tst_QFiledialog::QTBUG6558_showDirsOnly() +{ + const QString tempPath = QDir::tempPath(); + QDir dirTemp(tempPath); + const QString tempName = QLatin1String("showDirsOnly.") + QString::number(qrand()); + dirTemp.mkdir(tempName); + dirTemp.cd(tempName); + QTRY_VERIFY(dirTemp.exists()); + + const QString dirPath = dirTemp.absolutePath(); + QDir dir(dirPath); + + //We create two dirs + dir.mkdir("a"); + dir.mkdir("b"); + + //Create a file + QFile tempFile(dirPath + "/plop.txt"); + tempFile.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream out(&tempFile); + out << "The magic number is: " << 49 << "\n"; + tempFile.close(); + + QNonNativeFileDialog fd(0, "TestFileDialog"); + + fd.setDirectory(dir.absolutePath()); + fd.setViewMode(QFileDialog::List); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setOption(QFileDialog::ShowDirsOnly, true); + fd.show(); + + QApplication::setActiveWindow(&fd); + QTest::qWaitForWindowShown(&fd); + QTRY_COMPARE(fd.isVisible(), true); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&fd)); + + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 2); + + fd.setOption(QFileDialog::ShowDirsOnly, false); + QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 3); + + fd.setOption(QFileDialog::ShowDirsOnly, true); + QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 2); + + fd.setFileMode(QFileDialog::DirectoryOnly); + QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 2); + QTRY_COMPARE(bool(fd.options() & QFileDialog::ShowDirsOnly), true); + + fd.setFileMode(QFileDialog::AnyFile); + QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 3); + QTRY_COMPARE(bool(fd.options() & QFileDialog::ShowDirsOnly), false); + + fd.setDirectory(QDir::homePath()); + + //We remove the dirs + dir.rmdir("a"); + dir.rmdir("b"); + + //we delete the file + tempFile.remove(); + + dirTemp.cdUp(); + dirTemp.rmdir(tempName); + QTRY_VERIFY(!dir.exists()); +} + QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog2.moc" |