Skip to content
Permalink
Browse files

[options] Ensure that the "Advanced" tab is always the last tab in th…

…e list
  • Loading branch information
nyalldawson committed Oct 5, 2020
1 parent ba4906e commit f6b03314c63b27a80049087f723f026950745bcb
@@ -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
@@ -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 );
}
@@ -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
@@ -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 QList<QgsOpti
locatorLayout->addWidget( 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 QList<QgsOpti

mAdditionalOptionWidgets << page;
mOptionsStackedWidget->addWidget( page );

if ( QgsAdvancedSettingsWidget *advancedPage = qobject_cast< QgsAdvancedSettingsWidget * >( page ) )
{
advancedPage->settingsTree()->setSettingsObject( mSettings );
}
}

#ifdef HAVE_OPENCL
@@ -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;
}

@@ -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 );
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAdvancedSettingsWidgetBase</class>
<widget class="QWidget" name="QgsAdvancedSettingsWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>714</width>
<height>610</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox_26">
<property name="title">
<string>Advanced Settings Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_42">
<item>
<widget class="QWidget" name="mAdvancedSettingsWarning" native="true">
<layout class="QVBoxLayout" name="verticalLayout_44">
<item>
<widget class="QLabel" name="label_44">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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 &lt;span style=&quot; font-style:italic;&quot;&gt;OK&lt;/span&gt; button.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mAdvancedSettingsEnableButton">
<property name="text">
<string>I will be careful, I promise!</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsSettingsTree" name="mAdvancedSettingsEditor" native="true">
<property name="visible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSettingsTree</class>
<extends>QWidget</extends>
<header>qgssettingstree.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit f6b0331

Please sign in to comment.
You can’t perform that action at this time.