summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfilesystemmodel
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-09-10 11:40:42 +0200
committerAlexis Menard <alexis.menard@nokia.com>2009-09-10 11:44:42 +0200
commit9e8abb63ba4609887d988ee15ba6daee0b01380e (patch)
treedeb02261e3a6eae2869c51019bcd4397372af0b1 /tests/auto/qfilesystemmodel
parentb300c3022d285deb3b3203aca0746580ba9f3d91 (diff)
Fix random selection when the order is descending.
This commit fix the random selection that appear when the sort is not ascending. The problem is that sometimes the sort is not yet made (timer is not yet fired) so the visible children list contains both sorted items and non sorted items (at the end). translateVisibleLocation was buggy assuming that the list is always sorted. We have now a dirty index that indicate where the dirty items start. And then when the sort is made the dirty index is reset. I have added auto-test for that and fix one that was broken for Mac. The new version of the auto-test showed a crash because of this broken selection. Task-number:258751 Reviewed-by:thierry
Diffstat (limited to 'tests/auto/qfilesystemmodel')
-rw-r--r--tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp64
1 files changed, 46 insertions, 18 deletions
diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 04e60c474c..a388f0a514 100644
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -44,6 +44,7 @@
#include "../../../src/gui/dialogs/qfilesystemmodel_p.h"
#include <QFileIconProvider>
#include <QTreeView>
+#include <QHeaderView>
#include "../../shared/util.h"
#include <QTime>
#include <QStyle>
@@ -802,38 +803,65 @@ void tst_QFileSystemModel::sort()
if (fileDialogMode)
myModel->d_func()->disableRecursiveSort = true;
- const QString dirPath = QString("%1/sortTemp").arg(QDir::tempPath());
- QDir dir(dirPath);
- dir.mkpath(dirPath);
+ QDir dir(QDir::tempPath());
+ dir.mkdir("sortTemp");
+ dir.cd("sortTemp");
+ const QString dirPath = dir.absolutePath();
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();
+
+ //Create a file that will be at the end when sorting by name (For Mac, the default)
+ //but if we sort by size descending it will be the first
+ QFile tempFile(dirPath + "/plop2.txt");
+ tempFile.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream out(&tempFile);
+ out << "The magic number is: " << 49 << "\n";
+ tempFile.close();
+
+ QFile tempFile2(dirPath + "/plop.txt");
+ tempFile2.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream out2(&tempFile2);
+ out2 << "The magic number is : " << 49 << " but i write some stuff in the file \n";
+ tempFile2.close();
+
myModel->setRootPath(QDir::rootPath());
+ myModel->setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+ tree->setSortingEnabled(true);
tree->setModel(myModel);
tree->show();
+ tree->resize(800, 800);
QTest::qWait(500);
- tree->expand(myModel->index(dir.absolutePath(), 0));
- while (dir.cdUp())
+ tree->header()->setSortIndicator(1,Qt::DescendingOrder);
+ tree->header()->setResizeMode(0, QHeaderView::ResizeToContents);
+ QStringList dirsToOpen;
+ do
{
- tree->expand(myModel->index(dir.absolutePath(), 0));
+ dirsToOpen<<dir.absolutePath();
+ } while (dir.cdUp());
+
+ for (int i = dirsToOpen.size() -1 ; i > 0 ; --i) {
+ QString path = dirsToOpen[i];
+ QTest::qWait(500);
+ tree->expand(myModel->index(path, 0));
}
- QTest::qWait(250);
+ tree->expand(myModel->index(dirPath, 0));
+ QTest::qWait(500);
+ QModelIndex parent = myModel->index(dirPath, 0);
//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"));
+ QVERIFY(dirPath + QChar('/') + myModel->index(0, 1, parent).data(QFileSystemModel::FileNameRole).toString() != tempFile2.fileName());
else
- QCOMPARE(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString(), dirPath + QLatin1String("/a"));
+ QCOMPARE(dirPath + QChar('/') + myModel->index(0, 1, parent).data(QFileSystemModel::FileNameRole).toString(), tempFile2.fileName());
delete tree;
delete myModel;
+ dir.setPath(QDir::tempPath());
+ dir.cd("sortTemp");
+ tempFile.remove();
+ tempFile2.remove();
+ dir.cdUp();
+ dir.rmdir("sortTemp");
+
}
void tst_QFileSystemModel::mkdir()