From 2a02487ff00341fcc07023b37ec527c2694fa4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 20 Dec 2019 17:51:01 +0100 Subject: Move tracking of widget specific app palettes to QApplicationPrivate Change-Id: I43cc25207026f174e46534baedf08e0c300728d1 Reviewed-by: Timur Pocheptsov --- src/widgets/kernel/qapplication.cpp | 42 ++++++++++++++++++------------------- src/widgets/kernel/qapplication_p.h | 6 +++--- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index d28a425c43..28575a20f5 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -414,11 +414,9 @@ bool Q_WIDGETS_EXPORT qt_tab_all_widgets() } // ######## move to QApplicationPrivate -// Default application palettes and fonts (per widget type) -Q_GLOBAL_STATIC(PaletteHash, app_palettes) +// Default fonts (per widget type) Q_GLOBAL_STATIC(FontHash, app_fonts) -// Exported accessors for use outside of this file -PaletteHash *qt_app_palettes_hash() { return app_palettes(); } +// Exported accessor for use outside of this file FontHash *qt_app_fonts_hash() { return app_fonts(); } QWidgetList *QApplicationPrivate::popupWidgets = 0; // has keyboard input focus @@ -643,7 +641,8 @@ void QApplicationPrivate::initializeWidgetPaletteHash() QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme(); if (!platformTheme) return; - app_palettes()->clear(); + + widgetPalettes.clear(); setPossiblePalette(platformTheme->palette(QPlatformTheme::ToolButtonPalette), "QToolButton"); setPossiblePalette(platformTheme->palette(QPlatformTheme::ButtonPalette), "QAbstractButton"); @@ -802,7 +801,7 @@ QApplication::~QApplication() delete QApplicationPrivate::app_pal; QApplicationPrivate::app_pal = 0; clearSystemPalette(); - app_palettes()->clear(); + QApplicationPrivate::widgetPalettes.clear(); delete QApplicationPrivate::sys_font; QApplicationPrivate::sys_font = 0; @@ -1315,6 +1314,8 @@ void QApplication::setGlobalStrut(const QSize& strut) QApplicationPrivate::app_strut = strut; } +// Widget specific palettes +QApplicationPrivate::PaletteHash QApplicationPrivate::widgetPalettes; /*! \fn QPalette QApplication::palette(const QWidget* widget) @@ -1329,15 +1330,13 @@ void QApplication::setGlobalStrut(const QSize& strut) */ QPalette QApplication::palette(const QWidget* w) { - typedef PaletteHash::const_iterator PaletteHashConstIt; - - PaletteHash *hash = app_palettes(); - if (w && hash && hash->size()) { - PaletteHashConstIt it = hash->constFind(w->metaObject()->className()); - const PaletteHashConstIt cend = hash->constEnd(); + auto &widgetPalettes = QApplicationPrivate::widgetPalettes; + if (w && !widgetPalettes.isEmpty()) { + auto it = widgetPalettes.constFind(w->metaObject()->className()); + const auto cend = widgetPalettes.constEnd(); if (it != cend) return *it; - for (it = hash->constBegin(); it != cend; ++it) { + for (it = widgetPalettes.constBegin(); it != cend; ++it) { if (w->inherits(it.key())) return it.value(); } @@ -1354,10 +1353,10 @@ QPalette QApplication::palette(const QWidget* w) */ QPalette QApplication::palette(const char *className) { - PaletteHash *hash = app_palettes(); - if (className && hash && hash->size()) { - QHash::ConstIterator it = hash->constFind(className); - if (it != hash->constEnd()) + auto &widgetPalettes = QApplicationPrivate::widgetPalettes; + if (className && !widgetPalettes.isEmpty()) { + auto it = widgetPalettes.constFind(className); + if (it != widgetPalettes.constEnd()) return *it; } @@ -1372,7 +1371,6 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* QApplicationPrivate::app_style->polish(pal); // NB: non-const reference bool all = false; - PaletteHash *hash = app_palettes(); if (!className) { if (!QGuiApplicationPrivate::setPalette(pal)) return; @@ -1380,13 +1378,13 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* if (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal)) QCoreApplication::setAttribute(Qt::AA_SetPalette); - if (hash && hash->size()) { + if (!widgetPalettes.isEmpty()) { all = true; if (clearWidgetPaletteHash) - hash->clear(); + widgetPalettes.clear(); } - } else if (hash) { - hash->insert(className, pal); + } else { + widgetPalettes.insert(className, pal); } if (qApp) diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 79d06ed98c..8751cc772b 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -94,9 +94,6 @@ extern QClipboard *qt_clipboard; typedef QHash FontHash; Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash(); -typedef QHash PaletteHash; -PaletteHash *qt_app_palettes_hash(); - #define QApplicationPrivateBase QGuiApplicationPrivate class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase @@ -193,6 +190,9 @@ public: static void initializeWidgetFontHash(); static void setSystemFont(const QFont &font); + using PaletteHash = QHash; + static PaletteHash widgetPalettes; + static QApplicationPrivate *instance() { return self; } #ifdef QT_KEYPAD_NAVIGATION -- cgit v1.2.3