From f0e7c9c271f5e03e51ac35024a08958091f091ae Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 29 Dec 2018 18:54:34 +1000 Subject: [PATCH] Followup 0f8e291f, fix logic relating to overrding default application style and simplify --- src/app/main.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index dcab077d7651..2fc99c913e2d 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1221,24 +1221,20 @@ int main( int argc, char *argv[] ) // Set the application style. If it's not set QT will use the platform style except on Windows // as it looks really ugly so we use QPlastiqueStyle. - QString presetStyle = settings.value( QStringLiteral( "qgis/style" ) ).toString(); + QString desiredStyle = settings.value( QStringLiteral( "qgis/style" ) ).toString(); #ifndef Q_OS_MACX - QString theme = settings.value( QStringLiteral( "UI/UITheme" ) ).toString(); - if ( theme != QStringLiteral( "default" ) ) + const QString theme = settings.value( QStringLiteral( "UI/UITheme" ) ).toString(); + if ( theme != QLatin1String( "default" ) ) { if ( QStyleFactory::keys().contains( QStringLiteral( "fusion" ), Qt::CaseInsensitive ) ) { - presetStyle = QStringLiteral( "fusion" ); + desiredStyle = QStringLiteral( "fusion" ); } } #endif - QString activeStyleName = presetStyle; - if ( activeStyleName.isEmpty() ) // not set, using default style - { - //not set, check default - activeStyleName = QApplication::style()->metaObject()->className(); - } - if ( activeStyleName.contains( QStringLiteral( "adwaita" ), Qt::CaseInsensitive ) ) + const QString activeStyleName = QApplication::style()->metaObject()->className(); + if ( desiredStyle.contains( QLatin1String( "adwaita" ), Qt::CaseInsensitive ) + || ( desiredStyle.isEmpty() && activeStyleName.contains( QLatin1String( "adwaita" ), Qt::CaseInsensitive ) ) ) { //never allow Adwaita themes - the Qt variants of these are VERY broken //for apps like QGIS. E.g. oversized controls like spinbox widgets prevent actually showing @@ -1248,16 +1244,15 @@ int main( int argc, char *argv[] ) //style choices can cause Qt apps to crash... if ( QStyleFactory::keys().contains( QStringLiteral( "fusion" ), Qt::CaseInsensitive ) ) { - activeStyleName = QStringLiteral( "fusion" ); + desiredStyle = QStringLiteral( "fusion" ); } } - if ( activeStyleName != presetStyle ) + if ( !desiredStyle.isEmpty() ) { - settings.setValue( QStringLiteral( "qgis/style" ), QApplication::style()->objectName() ); - } - if ( !presetStyle.isEmpty() ) - { - QApplication::setStyle( presetStyle ); + QApplication::setStyle( desiredStyle ); + + if ( activeStyleName != desiredStyle ) + settings.setValue( QStringLiteral( "qgis/style" ), desiredStyle ); } // set authentication database directory