From cb16ba59804e312ba809cf078c8695c7e6656947 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 13 Jul 2023 15:24:35 +0200 Subject: [PATCH] QIcon: use fallback also with platform icon engine Amends a452e2254644ffbed289fdf051eaf41d7e6a3b0d. No new tests, existing tests fails when QPlatformTheme returns a QIconEngine implementation that provides the tested icons. However, the existing test fails when the platform icon engine provides and address-book-new icon, and depends on the order of test functions, as the name() test function modifies the global theme name and search path. Fix those issues in the test. Pick-to: 6.6 Change-Id: Ie1c1d14f08fad5e906296bab662df5cfacdbbf07 Reviewed-by: Axel Spoerl --- src/gui/image/qiconloader.cpp | 12 ++++++++---- tests/auto/gui/image/qicon/tst_qicon.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 530f4af8d11..e6951f975e3 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -620,11 +620,15 @@ QIconEngine *QIconLoader::iconEngine(const QString &iconName) const qCDebug(lcIconLoader) << "Resolving icon engine for icon" << iconName; auto *platformTheme = QGuiApplicationPrivate::platformTheme(); - auto *iconEngine = hasUserTheme() || !platformTheme ? - new QIconLoaderEngine(iconName) : platformTheme->createIconEngine(iconName); + std::unique_ptr iconEngine; + if (!hasUserTheme() && platformTheme) + iconEngine.reset(platformTheme->createIconEngine(iconName)); + if (!iconEngine || iconEngine->isNull()) { + iconEngine.reset(new QIconLoaderEngine(iconName)); + } - qCDebug(lcIconLoader) << "Resulting engine" << iconEngine; - return iconEngine; + qCDebug(lcIconLoader) << "Resulting engine" << iconEngine.get(); + return iconEngine.release(); } /*! diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 0d8213a6171..71df9f12ca6 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -552,6 +552,10 @@ void tst_QIcon::availableSizes() void tst_QIcon::name() { + const auto reset = qScopeGuard([]{ + QIcon::setThemeName({}); + QIcon::setThemeSearchPaths({}); + }); { // No name if icon does not come from a theme QIcon icon(":/image.png"); @@ -629,6 +633,7 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { + const bool abIconFromPlatform = !QIcon::fromTheme("address-book-new").isNull(); QString firstSearchPath = QLatin1String(":/icons"); QString secondSearchPath = QLatin1String(":/second_icons"); QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath); @@ -725,7 +730,7 @@ void tst_QIcon::fromTheme() // Make sure setting the theme name clears the state QIcon::setThemeName(""); abIcon = QIcon::fromTheme("address-book-new"); - QVERIFY(abIcon.isNull()); + QCOMPARE_NE(abIcon.isNull(), abIconFromPlatform); // Test fallback icon behavior for empty theme names. // Can only reliably test this on systems that don't have a