From f6b03314c63b27a80049087f723f026950745bcb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 5 Oct 2020 16:34:24 +1000 Subject: [PATCH] [options] Ensure that the "Advanced" tab is always the last tab in the list --- src/app/CMakeLists.txt | 1 + src/app/options/qgsadvancedoptions.cpp | 70 +++++++++++++++++++ src/app/options/qgsadvancedoptions.h | 65 ++++++++++++++++++ src/app/options/qgsoptions.cpp | 15 ++-- src/app/qgisapp.cpp | 5 +- src/app/qgsappscreenshots.cpp | 6 +- src/ui/qgsadvancedsettingswidget.ui | 68 +++++++++++++++++++ src/ui/qgsoptionsbase.ui | 94 -------------------------- 8 files changed, 222 insertions(+), 102 deletions(-) create mode 100644 src/app/options/qgsadvancedoptions.cpp create mode 100644 src/app/options/qgsadvancedoptions.h create mode 100644 src/ui/qgsadvancedsettingswidget.ui diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 4db4a0fac304..304bee583cb2 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -197,6 +197,7 @@ SET(QGIS_APP_SRCS locator/qgsinbuiltlocatorfilters.cpp locator/qgslocatoroptionswidget.cpp + options/qgsadvancedoptions.cpp options/qgscodeeditoroptions.cpp options/qgsoptions.cpp options/qgsoptionsutils.cpp diff --git a/src/app/options/qgsadvancedoptions.cpp b/src/app/options/qgsadvancedoptions.cpp new file mode 100644 index 000000000000..488c38b02d5e --- /dev/null +++ b/src/app/options/qgsadvancedoptions.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + qgsadvancedoptions.cpp + ------------------------- + begin : September 2020 + copyright : (C) 2020 by Nyall Dawson + email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgsadvancedoptions.h" +#include "qgsapplication.h" +#include "qgssettings.h" +#include "qgis.h" + +// +// QgsAdvancedSettingsWidget +// + +QgsAdvancedSettingsWidget::QgsAdvancedSettingsWidget( QWidget *parent ) + : QgsOptionsPageWidget( parent ) +{ + setupUi( this ); + + layout()->setContentsMargins( 0, 0, 0, 0 ); + + connect( mAdvancedSettingsEnableButton, &QPushButton::clicked, this, [ = ] + { + mAdvancedSettingsEditor->show(); + mAdvancedSettingsWarning->hide(); + } ); +} + +QgsAdvancedSettingsWidget::~QgsAdvancedSettingsWidget() +{ +} + +void QgsAdvancedSettingsWidget::apply() +{ +// nothing to do -- mAdvancedSettingsEditor applies changes immediately +} + +QgsSettingsTree *QgsAdvancedSettingsWidget::settingsTree() +{ + return mAdvancedSettingsEditor; +} + +// +// QgsAdvancedSettingsOptionsFactory +// +QgsAdvancedSettingsOptionsFactory::QgsAdvancedSettingsOptionsFactory() + : QgsOptionsWidgetFactory( tr( "Advanced" ), QIcon() ) +{ + +} + +QIcon QgsAdvancedSettingsOptionsFactory::icon() const +{ + return QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ); +} + +QgsOptionsPageWidget *QgsAdvancedSettingsOptionsFactory::createWidget( QWidget *parent ) const +{ + return new QgsAdvancedSettingsWidget( parent ); +} diff --git a/src/app/options/qgsadvancedoptions.h b/src/app/options/qgsadvancedoptions.h new file mode 100644 index 000000000000..04183a0bf956 --- /dev/null +++ b/src/app/options/qgsadvancedoptions.h @@ -0,0 +1,65 @@ +/*************************************************************************** + qgsadvancedoptions.h + ------------------------- + begin : September 2020 + copyright : (C) 2020 by Nyall Dawson + email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef QGSADVANCEDOPTIONS_H +#define QGSADVANCEDOPTIONS_H + +#include "ui_qgsadvancedsettingswidget.h" +#include "qgsoptionswidgetfactory.h" +#include "qgssettings.h" + +/** + * \ingroup app + * \class QgsAdvancedSettingsWidget + * \brief An options widget showing an advanced settings editor. + * + * \since QGIS 3.16 + */ +class QgsAdvancedSettingsWidget : public QgsOptionsPageWidget, private Ui::QgsAdvancedSettingsWidgetBase +{ + Q_OBJECT + + public: + + /** + * Constructor for QgsAdvancedSettingsWidget with the specified \a parent widget. + */ + QgsAdvancedSettingsWidget( QWidget *parent ); + ~QgsAdvancedSettingsWidget() override; + void apply() override; + + QgsSettingsTree *settingsTree(); + + private: + + QgsSettings mSettings; + +}; + + +class QgsAdvancedSettingsOptionsFactory : public QgsOptionsWidgetFactory +{ + Q_OBJECT + + public: + + QgsAdvancedSettingsOptionsFactory(); + + QIcon icon() const override; + QgsOptionsPageWidget *createWidget( QWidget *parent = nullptr ) const override; + +}; + + +#endif // QGSADVANCEDOPTIONS_H diff --git a/src/app/options/qgsoptions.cpp b/src/app/options/qgsoptions.cpp index 1826f686498f..4fd17b8df3eb 100644 --- a/src/app/options/qgsoptions.cpp +++ b/src/app/options/qgsoptions.cpp @@ -60,6 +60,7 @@ #include "qgsnewsfeedparser.h" #include "qgsbearingnumericformat.h" #include "qgssublayersdialog.h" +#include "options/qgsadvancedoptions.h" #ifdef HAVE_OPENCL #include "qgsopenclutils.h" @@ -1140,10 +1141,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListaddWidget( mLocatorOptionsWidget ); mOptionsLocatorGroupBox->setLayout( locatorLayout ); - mAdvancedSettingsEditor->setSettingsObject( mSettings ); - - const auto constOptionsFactories = optionsFactories; - for ( QgsOptionsWidgetFactory *factory : constOptionsFactories ) + QList< QgsOptionsWidgetFactory *> factories = optionsFactories; + // ensure advanced factory is always last + QgsAdvancedSettingsOptionsFactory advancedFactory; + factories << &advancedFactory; + for ( QgsOptionsWidgetFactory *factory : qgis::as_const( factories ) ) { QListWidgetItem *item = new QListWidgetItem(); item->setIcon( factory->icon() ); @@ -1158,6 +1160,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListaddWidget( page ); + + if ( QgsAdvancedSettingsWidget *advancedPage = qobject_cast< QgsAdvancedSettingsWidget * >( page ) ) + { + advancedPage->settingsTree()->setSettingsObject( mSettings ); + } } #ifdef HAVE_OPENCL diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index dd33932050eb..c27b8c7cb067 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -12273,8 +12273,7 @@ QMap< QString, int > QgisApp::optionsPagesMap() sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Authentication" ), 13 ); sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Network" ), 14 ); sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Locator" ), 15 ); - sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Advanced" ), 16 ); - sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Acceleration" ), 17 ); + sOptionsPagesMap.insert( QCoreApplication::translate( "QgsOptionsBase", "Acceleration" ), 16 ); } ); QMap< QString, int > map = sOptionsPagesMap; @@ -12289,6 +12288,8 @@ QMap< QString, int > QgisApp::optionsPagesMap() idx++; } + map.insert( QCoreApplication::translate( "QgsOptionsBase", "Advanced" ), idx ); + return map; } diff --git a/src/app/qgsappscreenshots.cpp b/src/app/qgsappscreenshots.cpp index 324bdbe79b09..17534165cc0b 100644 --- a/src/app/qgsappscreenshots.cpp +++ b/src/app/qgsappscreenshots.cpp @@ -317,11 +317,13 @@ void QgsAppScreenShots::takeGlobalOptions() } // ----------------- // advanced settings - dlg->mOptionsListWidget->setCurrentRow( 15 ); + dlg->mOptionsListWidget->setCurrentRow( dlg->mOptionsListWidget->count() - 1 ); QCoreApplication::processEvents(); Q_ASSERT( dlg->mOptionsListWidget->currentItem()->icon().pixmap( 24, 24 ).toImage() == QgsApplication::getThemeIcon( QStringLiteral( "/mIconWarning.svg" ) ).pixmap( 24, 24 ).toImage() ); - dlg->mAdvancedSettingsEditor->show(); + QWidget *editor = dlg->findChild< QWidget * >( QStringLiteral( "mAdvancedSettingsEditor" ) ); + if ( editor ) + editor->show(); QCoreApplication::processEvents(); QCoreApplication::processEvents(); // seems a second call is needed, the tabble might not be fully displayed otherwise takeScreenshot( QStringLiteral( "advanced_with_settings_shown" ), folder, dlg ); diff --git a/src/ui/qgsadvancedsettingswidget.ui b/src/ui/qgsadvancedsettingswidget.ui new file mode 100644 index 000000000000..026d8a7ace1d --- /dev/null +++ b/src/ui/qgsadvancedsettingswidget.ui @@ -0,0 +1,68 @@ + + + QgsAdvancedSettingsWidgetBase + + + + 0 + 0 + 714 + 610 + + + + Form + + + + + + Advanced Settings Editor + + + + + + + + + <html><head/><body><p>Changes on this page are dangerous and can break your QGIS installation in various ways. Any change you make is applied immediately, without clicking the <span style=" font-style:italic;">OK</span> button.</p></body></html> + + + true + + + + + + + I will be careful, I promise! + + + + + + + + + + false + + + + + + + + + + + QgsSettingsTree + QWidget +
qgssettingstree.h
+ 1 +
+
+ + +
diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index b24b619f0df3..f0342c2168ee 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -287,18 +287,6 @@ :/images/themes/default/search.svg:/images/themes/default/search.svg - - - Advanced - - - Advanced - - - - :/images/themes/default/mIconWarning.svg:/images/themes/default/mIconWarning.svg - - Acceleration @@ -5613,49 +5601,6 @@ The bigger the number, the faster zooming with the mouse wheel will be. - - - - - - Advanced Settings Editor - - - - - - - - - <html><head/><body><p>Changes on this page are dangerous and can break your QGIS installation in various ways. Any change you make is applied immediately, without clicking the <span style=" font-style:italic;">OK</span> button.</p></body></html> - - - true - - - - - - - I will be careful, I promise! - - - - - - - - - - false - - - - - - - - @@ -5868,12 +5813,6 @@ p, li { white-space: pre-wrap; } QComboBox
qgsscalecombobox.h
- - QgsSettingsTree - QWidget -
qgssettingstree.h
- 1 -
QgsAuthEditorWidgets QTabWidget @@ -6117,7 +6056,6 @@ p, li { white-space: pre-wrap; } mAddUrlPushButton mRemoveUrlPushButton mNoProxyUrlListWidget - mAdvancedSettingsEnableButton mGPUEnableCheckBox mOpenClDevicesCombo mGPUInfoTextBrowser @@ -6159,38 +6097,6 @@ p, li { white-space: pre-wrap; } - - mAdvancedSettingsEnableButton - clicked() - mAdvancedSettingsEditor - show() - - - 481 - 261 - - - 481 - 412 - - - - - mAdvancedSettingsEnableButton - clicked() - mAdvancedSettingsWarning - hide() - - - 481 - 261 - - - 481 - 164 - - -