Consult QIcon::fallbackThemeName() even when theme name is empty

We still need to consult fallbackThemeName() when computing the
parent list for an individual theme, as the Freedesktop Theme Icon
spec mandates that the "hicolor" theme comes last, but we no longer
need to do explicit fallback to fallbackThemeName() if a theme is
not found.

Pick-to: 6.5 6.6
Change-Id: I6c0b5a45d8258c5b6eaa761402944a735b1606ba
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-05-10 18:46:22 +02:00
parent dde45bcefb
commit addde7843f
2 changed files with 12 additions and 7 deletions

View File

@ -438,9 +438,8 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
if (!theme.isValid()) {
theme = QIconTheme(themeName);
if (!theme.isValid()) {
qCDebug(lcIconLoader) << "Theme" << themeName << "not found;"
<< "trying fallback theme" << fallbackThemeName();
theme = QIconTheme(fallbackThemeName());
qCDebug(lcIconLoader) << "Theme" << themeName << "not found";
return info;
}
}
@ -582,10 +581,12 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const
qCDebug(lcIconLoader) << "Loading icon" << name;
QThemeIconInfo iconInfo;
if (!themeName().isEmpty()) {
QStringList visited;
iconInfo = findIconHelper(themeName(), name, visited);
}
QStringList visitedThemes;
if (!themeName().isEmpty())
iconInfo = findIconHelper(themeName(), name, visitedThemes);
if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty())
iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes);
if (iconInfo.entries.empty())
iconInfo = lookupFallbackIcon(name);

View File

@ -732,6 +732,10 @@ void tst_QIcon::fromTheme()
// named system icon theme.
QIcon::setThemeName(""); // Reset user-theme
if (QIcon::themeName().isEmpty()) {
// Test icon from fallback theme even when theme name is empty
QIcon::setFallbackThemeName("fallbacktheme");
QVERIFY(!QIcon::fromTheme("edit-cut").isNull());
// Test icon from fallback path even when theme name is empty
fallbackIcon = QIcon::fromTheme("red");
QVERIFY(!fallbackIcon.isNull());