diff options
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/dialogs/qfilesystemmodel_p.h | 12 | ||||
-rw-r--r-- | tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp | 41 |
3 files changed, 53 insertions, 2 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index f70669c..9935a80 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -1437,6 +1437,8 @@ void QFileDialog::setIconProvider(QFileIconProvider *provider) { Q_D(QFileDialog); d->model->setIconProvider(provider); + //It forces the refresh of all entries in the side bar, then we can get new icons + d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls()); } /*! diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h index 77c35a2..0a1265a 100644 --- a/src/gui/dialogs/qfilesystemmodel_p.h +++ b/src/gui/dialogs/qfilesystemmodel_p.h @@ -163,7 +163,11 @@ public: info->icon = iconProvider->icon(QFileInfo(path)); QHash<QString, QFileSystemNode *>::const_iterator iterator; for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { - iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) + if (!path.isEmpty()) + iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + else + iterator.value()->updateIcon(iconProvider, iterator.value()->fileName); } } @@ -172,7 +176,11 @@ public: info->displayType = iconProvider->type(QFileInfo(path)); QHash<QString, QFileSystemNode *>::const_iterator iterator; for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { - iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) + if (!path.isEmpty()) + iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + else + iterator.value()->retranslateStrings(iconProvider, iterator.value()->fileName); } } 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) |