From 2a8b27bf6c523de6f3f466f8062279c093940a60 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Thu, 4 Jan 2024 21:02:45 +0200 Subject: QFileSystemModel: don't crash with setIconProvider(nullptr) The method takes a pointer, so the code shouldn't crash when passed a nullptr. QFileInfoGatherer::getInfo() still needs to generate a descriptive string for the file, so we refactor QAbstractFileIconProvider::type() to put the implementation into a reusable static function QAbstractFileIconProviderPrivate::getFileType(const QFileInfo &info). This unfortunately involves constructing a QMimeDatabase on the fly, but the docs say that is fine. Drive-by change: use nullptr instead of `0` for pointers. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-99178 Change-Id: Ia32ea0a26701d593e74fbecced7be8d9e0aa0f52 Reviewed-by: Ahmad Samir Reviewed-by: Shawn Rutledge --- tests/manual/dialogs/filedialogpanel.cpp | 11 ++++++++++- tests/manual/dialogs/filedialogpanel.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'tests/manual/dialogs') diff --git a/tests/manual/dialogs/filedialogpanel.cpp b/tests/manual/dialogs/filedialogpanel.cpp index 6f807d9280..47a1b54ae3 100644 --- a/tests/manual/dialogs/filedialogpanel.cpp +++ b/tests/manual/dialogs/filedialogpanel.cpp @@ -86,6 +86,7 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) , m_resolveSymLinks(new QCheckBox(tr("Resolve symlinks"))) , m_native(new QCheckBox(tr("Use native dialog"))) , m_customDirIcons(new QCheckBox(tr("Don't use custom directory icons"))) + , m_noIconProvider(new QCheckBox(tr("Null icon provider"))) , m_acceptMode(createCombo(this, acceptModeComboData, sizeof(acceptModeComboData)/sizeof(FlagData))) , m_fileMode(createCombo(this, fileModeComboData, sizeof(fileModeComboData)/sizeof(FlagData))) , m_viewMode(createCombo(this, viewModeComboData, sizeof(viewModeComboData)/sizeof(FlagData))) @@ -113,6 +114,7 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) optionsLayout->addRow(m_resolveSymLinks); optionsLayout->addRow(m_readOnly); optionsLayout->addRow(m_customDirIcons); + optionsLayout->addRow(m_noIconProvider); // Files QGroupBox *filesGroupBox = new QGroupBox(tr("Files / Filters")); @@ -417,12 +419,19 @@ void FileDialogPanel::restoreDefaults() l->restoreDefault(&d); } -void FileDialogPanel::applySettings(QFileDialog *d) const +void FileDialogPanel::applySettings(QFileDialog *d) { d->setAcceptMode(comboBoxValue(m_acceptMode)); d->setViewMode(comboBoxValue(m_viewMode)); d->setFileMode(comboBoxValue(m_fileMode)); d->setOptions(options()); + if (m_noIconProvider->isChecked()) { + m_origIconProvider = d->iconProvider(); + d->setIconProvider(nullptr); + } else if (m_origIconProvider) { + d->setIconProvider(m_origIconProvider); + } + d->setDefaultSuffix(m_defaultSuffix->text().trimmed()); const QString directory = m_directory->text().trimmed(); if (!directory.isEmpty()) diff --git a/tests/manual/dialogs/filedialogpanel.h b/tests/manual/dialogs/filedialogpanel.h index 1cce1dfdd1..ec36835f6e 100644 --- a/tests/manual/dialogs/filedialogpanel.h +++ b/tests/manual/dialogs/filedialogpanel.h @@ -9,6 +9,8 @@ #include QT_BEGIN_NAMESPACE + +class QAbstractFileIconProvider; class QPushButton; class QCheckBox; class QComboBox; @@ -52,7 +54,7 @@ private: QString filterString() const; QFileDialog::Options options() const; QStringList allowedSchemes() const; - void applySettings(QFileDialog *d) const; + void applySettings(QFileDialog *d); QFormLayout *filesLayout; QCheckBox *m_showDirsOnly; @@ -62,6 +64,9 @@ private: QCheckBox *m_resolveSymLinks; QCheckBox *m_native; QCheckBox *m_customDirIcons; + QCheckBox *m_noIconProvider = nullptr; + QAbstractFileIconProvider *m_origIconProvider = nullptr; + QComboBox *m_acceptMode; QComboBox *m_fileMode; QComboBox *m_viewMode; -- cgit v1.2.3