summaryrefslogtreecommitdiff
path: root/tests/auto/qfilesystemmodel
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-05-28 14:46:39 +0200
committerAlexis Menard <alexis.menard@nokia.com>2009-05-28 17:26:48 +0200
commit8e4300e2866fd28881853509df6ff054e13f841b (patch)
treea27cf1b141948e0e34f6b60efdd47063e87265fa /tests/auto/qfilesystemmodel
parent89029a54cb3adfb54736a6aafaea9ec535407592 (diff)
downloadqt4-tools-8e4300e2866fd28881853509df6ff054e13f841b.tar.gz
Fix wrong sorting when using the QFileSystemModel with QTreeView
An optimization was made to the sorting of QFileDialog to sort only the current root (meaning what the user see). This avoided slowness when the model was big with lots of leafs. The problem here is for the treeview, the root is always the same, we expands only nodes. In that case, a recursive sorting is needed to ensure that all expanded nodes are correctly sorted (and filtered). This will be slower that's why i use an hidden flag in the d pointer to deactivate the recursive sort for the QFileDialog. Task-number:254701 Reviewed-by:olivier BT:yes
Diffstat (limited to 'tests/auto/qfilesystemmodel')
-rw-r--r--tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp65
1 files changed, 62 insertions, 3 deletions
diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 59d57cee1f..b109d4b7d3 100644
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -43,6 +43,7 @@
#include <QtTest/QtTest>
#include "../../../src/gui/dialogs/qfilesystemmodel_p.h"
#include <QFileIconProvider>
+#include <QTreeView>
#include "../../shared/util.h"
#include <QTime>
#include <QStyle>
@@ -102,6 +103,7 @@ private slots:
void setData_data();
void setData();
+ void sort_data();
void sort();
void mkdir();
@@ -452,8 +454,12 @@ void tst_QFileSystemModel::rowsInserted()
} else {
QCOMPARE(model->index(model->rowCount(root) - 1, 0, root).data().toString(), QString("b"));
}
- if (spy0.count() > 0)
- if (count == 0) QCOMPARE(spy0.count(), 0); else QVERIFY(spy0.count() >= 1);
+ if (spy0.count() > 0) {
+ if (count == 0)
+ QCOMPARE(spy0.count(), 0);
+ else
+ QVERIFY(spy0.count() >= 1);
+ }
if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1);
QVERIFY(createFiles(tmp, QStringList(".hidden_file"), 5 + count));
@@ -722,6 +728,19 @@ void tst_QFileSystemModel::setData()
QTRY_COMPARE(model->rowCount(root), files.count());
}
+class MyFriendFileSystemModel : public QFileSystemModel
+{
+ friend class tst_QFileSystemModel;
+ Q_DECLARE_PRIVATE(QFileSystemModel)
+};
+
+void tst_QFileSystemModel::sort_data()
+{
+ QTest::addColumn<bool>("fileDialogMode");
+ QTest::newRow("standard usage") << false;
+ QTest::newRow("QFileDialog usage") << true;
+}
+
void tst_QFileSystemModel::sort()
{
QTemporaryFile file;
@@ -733,8 +752,48 @@ void tst_QFileSystemModel::sort()
model->sort(0, Qt::AscendingOrder);
model->sort(0, Qt::DescendingOrder);
QVERIFY(idx.column() != 0);
-}
+ QFETCH(bool, fileDialogMode);
+
+ MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel();
+ QTreeView *tree = new QTreeView();
+
+ if (fileDialogMode)
+ myModel->d_func()->disableRecursiveSort = true;
+
+ const QString dirPath = QString("%1/sortTemp").arg(QDir::tempPath());
+ QDir dir(dirPath);
+ dir.mkpath(dirPath);
+ QVERIFY(dir.exists());
+ dir.mkdir("a");
+ dir.mkdir("b");
+ dir.mkdir("c");
+ dir.mkdir("d");
+ dir.mkdir("e");
+ dir.mkdir("f");
+ dir.mkdir("g");
+ QTemporaryFile tempFile(dirPath + "/rXXXXXX");
+ tempFile.open();
+ myModel->setRootPath(QDir::rootPath());
+ tree->setModel(myModel);
+ tree->show();
+ QTest::qWait(500);
+ tree->expand(myModel->index(dir.absolutePath(), 0));
+ while (dir.cdUp())
+ {
+ tree->expand(myModel->index(dir.absolutePath(), 0));
+ }
+ QTest::qWait(250);
+ //File dialog Mode means sub trees are not sorted, only the current root
+ if (fileDialogMode)
+ QVERIFY(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString() != dirPath + QLatin1String("/a"));
+ else
+ QCOMPARE(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString(), dirPath + QLatin1String("/a"));
+
+ delete tree;
+ delete myModel;
+
+}
void tst_QFileSystemModel::mkdir()
{