QIcon: use fallback also with platform icon engine
Amends a452e22546
. 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 <axel.spoerl@qt.io>
This commit is contained in:
parent
3f9817b26c
commit
cb16ba5980
@ -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<QIconEngine> 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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user