summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfilesystemmodel
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-04-20 10:32:31 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-04-20 10:37:07 (GMT)
commit2e3f7621d696bec6173810c75b042249645fa714 (patch)
treeb505e35c7f20de039d2b3dca2edfef72ee8f9484 /tests/auto/qfilesystemmodel
parent0b15f59c648633357e9263e93c688e5462e3e01e (diff)
downloadQt-2e3f7621d696bec6173810c75b042249645fa714.zip
Qt-2e3f7621d696bec6173810c75b042249645fa714.tar.gz
Qt-2e3f7621d696bec6173810c75b042249645fa714.tar.bz2
This fix a bug on the QFileSystemModel with a custom icon provider
We were calling the provider with invalid path, with the default one it fallback to all standard icons but with a custom one we call a public method with an invalid QFileInfo. It was happening on windows only for the My Drives view because in that case the parent path is null, my Drives is a logical view. Task-number: 251295 Reviewed-by: jasplin
Diffstat (limited to 'tests/auto/qfilesystemmodel')
-rw-r--r--tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 826d278..59d57ce 100644
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -45,6 +45,7 @@
#include <QFileIconProvider>
#include "../../shared/util.h"
#include <QTime>
+#include <QStyle>
#include <QtGlobal>
//TESTED_CLASS=
@@ -284,6 +285,33 @@ void tst_QFileSystemModel::readOnly()
QVERIFY(model->flags(model->index(file.fileName())) & Qt::ItemIsEditable);
}
+class CustomFileIconProvider : public QFileIconProvider
+{
+public:
+ CustomFileIconProvider() : QFileIconProvider() {
+ mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical);
+ dvd = qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon);
+ }
+
+ virtual QIcon icon(const QFileInfo &info) const
+ {
+ if (info.isDir())
+ return mb;
+
+ return QFileIconProvider::icon(info);
+ }
+ virtual QIcon icon(IconType type) const
+ {
+ if (type == QFileIconProvider::Folder)
+ return dvd;
+
+ return QFileIconProvider::icon(type);
+ }
+private:
+ QIcon mb;
+ QIcon dvd;
+};
+
void tst_QFileSystemModel::iconProvider()
{
QVERIFY(model->iconProvider());
@@ -292,6 +320,19 @@ void tst_QFileSystemModel::iconProvider()
QCOMPARE(model->iconProvider(), p);
model->setIconProvider(0);
delete p;
+
+ QFileSystemModel *myModel = new QFileSystemModel();
+ myModel->setRootPath(QDir::homePath());
+ //Let's wait to populate the model
+ QTest::qWait(250);
+ //We change the provider, icons must me updated
+ CustomFileIconProvider *custom = new CustomFileIconProvider();
+ myModel->setIconProvider(custom);
+
+ QPixmap mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(50, 50);
+ QCOMPARE(myModel->fileIcon(myModel->index(QDir::homePath())).pixmap(50, 50), mb);
+ delete myModel;
+ delete custom;
}
bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs, const QString &dir)