From 75663be3b580d1b763c354f69f7828a0c32536d9 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Fri, 28 Mar 2025 09:53:03 +0100 Subject: [PATCH] QXdgDesktopPortalTheme: Refactor base theme creation loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The search for a base theme was handled in 2 separate loops. Combine those in sync with QGuiApplication. Make list of theme names const, as it doesn't and mustn't change. Pick-to: 6.8 6.5 Task-number: QTBUG-134702 Change-Id: If4ae8212bbefa2934639feec983b94e8e2d6b168 Reviewed-by: Jan Grulich Reviewed-by: Tor Arne Vestbø (cherry picked from commit 63ba867dddd5bfe3827f48eb24884c534c80541a) Reviewed-by: Qt Cherry-pick Bot --- .../qxdgdesktopportaltheme.cpp | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp index 58b613baeb2..2b3fb2b9494 100644 --- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp +++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp @@ -84,28 +84,19 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme() { Q_D(QXdgDesktopPortalTheme); - QStringList themeNames; - themeNames += QGuiApplicationPrivate::platform_integration->themeNames(); - // 1) Look for a theme plugin. - for (const QString &themeName : std::as_const(themeNames)) { + const QStringList themeNames = QGuiApplicationPrivate::platform_integration->themeNames(); + for (const QString &themeName : themeNames) { if (QXdgDesktopPortalTheme::isXdgPlugin(themeName)) continue; + // 1) Look for a theme plugin. d->baseTheme = QPlatformThemeFactory::create(themeName, nullptr); if (d->baseTheme) break; - } - // 2) If no theme plugin was found ask the platform integration to - // create a theme - if (!d->baseTheme) { - for (const QString &themeName : std::as_const(themeNames)) { - if (QXdgDesktopPortalTheme::isXdgPlugin(themeName)) - continue; - d->baseTheme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName); - if (d->baseTheme) - break; - } - // No error message; not having a theme plugin is allowed. + // 2) If no theme plugin was found ask the platform integration to create a theme + d->baseTheme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName); + if (d->baseTheme) + break; } // 3) Fall back on the built-in "null" platform theme.