Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved most core settings to SettingsEntry
  • Loading branch information
domi4484 committed Apr 26, 2021
1 parent 96cee9f commit 00a7936
Show file tree
Hide file tree
Showing 35 changed files with 242 additions and 83 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/network/qgsnewsfeedparser.sip.in
Expand Up @@ -93,6 +93,14 @@ Returns the authentication configuration for the parser.
Returns the settings key used for a feed with the given ``baseUrl``.
%End

struct Settings
{
const QgsSettingsEntryInteger feedLastFetchTime;
const QgsSettingsEntryString feedLanguage;
const QgsSettingsEntryDouble feedLatitude;
const QgsSettingsEntryDouble feedLongitude;
};

public slots:

void fetch();
Expand Down
8 changes: 8 additions & 0 deletions python/core/auto_generated/processing/qgsprocessing.sip.in
Expand Up @@ -52,6 +52,14 @@ Converts a source ``type`` to a string representation.
%End

static const QString TEMPORARY_OUTPUT;

struct Settings
{
const QgsSettingsEntryBool preferFilenameAsLayerName;
const QgsSettingsEntryString tempPath;
const QgsSettingsEntryInteger defaultOutputVectorLayerExt;
const QgsSettingsEntryInteger defaultOutputRasterLayerExt;
};
};

/************************************************************************
Expand Down
9 changes: 9 additions & 0 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -1003,6 +1003,15 @@ Emits the signal to collect all the strings of .qgs to be included in ts file
.. versionadded:: 3.4
%End

struct Settings
{
const QgsSettingsEntryString localeUserLocale;
const QgsSettingsEntryBool localeOverrideFlag;
const QgsSettingsEntryString localeGlobalLocale;
const QgsSettingsEntryBool localeShowGroupSeparator;
const QgsSettingsEntryStringList searchPathsForSVG;
};

%If (ANDROID)
//dummy method to workaround sip generation issue
bool x11EventFilter( XEvent *event );
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/qgsgeometryoptions.sip.in
Expand Up @@ -118,6 +118,11 @@ Read the geometry options from ``node``.
.. versionadded:: 3.4
%End

struct Settings
{
const QgsSettingsEntryString geometryValidationDefaultChecks;
};

signals:

void checkConfigurationChanged();
Expand Down
Expand Up @@ -60,6 +60,11 @@ Since the paths are stored by order of preference, lower positions in the list t
Unregisters a localized path
%End

struct Settings
{
const QgsSettingsEntryStringList localizedDataPaths;
};

private:
QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other );
};
Expand Down
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgsmaprendererjob.sip.in
Expand Up @@ -157,6 +157,12 @@ Returns map settings with which this job was started.




struct Settings
{
const QgsSettingsEntryBool logCanvasRefreshEvent;
};

signals:

void renderingLayersFinished();
Expand Down
Expand Up @@ -9,7 +9,10 @@



class QgsSettingsRegistryCore : QgsSettingsRegistry



class QgsSettingsRegistryCore
{
%Docstring(signature="appended")
:py:class:`QgsSettingsRegistryCore` is used for settings introspection and collects all
Expand All @@ -30,6 +33,16 @@ Constructor for QgsSettingsRegistryCore.

virtual ~QgsSettingsRegistryCore();

const QgsSettingsEntryBase *getSettingsEntry( const QString &key );
%Docstring
Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found.
%End

void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry );
%Docstring
Add ``settingsEntry`` to the register.
%End

};

/************************************************************************
Expand Down
14 changes: 6 additions & 8 deletions src/app/main.cpp
Expand Up @@ -966,20 +966,18 @@ int main( int argc, char *argv[] )
delete profile;

{
QgsSettings settings;

/* Translation file for QGIS.
*/
QString myUserTranslation = settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
QString myGlobalLocale = settings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString();
QString myUserTranslation = QgsApplication::Settings::localeUserLocale.value();
QString myGlobalLocale = QgsApplication::Settings::localeGlobalLocale.value();
bool myShowGroupSeparatorFlag = false; // Default to false
bool myLocaleOverrideFlag = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
bool myLocaleOverrideFlag = QgsApplication::Settings::localeOverrideFlag.value();

// Override Show Group Separator if the global override flag is set
if ( myLocaleOverrideFlag )
{
// Default to false again
myShowGroupSeparatorFlag = settings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
myShowGroupSeparatorFlag = QgsApplication::Settings::localeShowGroupSeparator.value();
}

//
Expand All @@ -993,7 +991,7 @@ int main( int argc, char *argv[] )
//
if ( !translationCode.isNull() && !translationCode.isEmpty() )
{
settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode );
QgsApplication::Settings::localeUserLocale.setValue( translationCode );
}
else
{
Expand All @@ -1002,7 +1000,7 @@ int main( int argc, char *argv[] )
translationCode = QLocale().name();
//setting the locale/userLocale when the --lang= option is not set will allow third party
//plugins to always use the same locale as the QGIS, otherwise they can be out of sync
settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode );
QgsApplication::Settings::localeUserLocale.setValue( translationCode );
}
else
{
Expand Down
22 changes: 11 additions & 11 deletions src/app/options/qgsoptions.cpp
Expand Up @@ -24,6 +24,7 @@
#include "qgsgdalutils.h"
#include "qgshighlight.h"
#include "qgsmapcanvas.h"
#include "qgsmaprendererjob.h"
#include "qgsprojectionselectiondialog.h"
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
Expand Down Expand Up @@ -474,7 +475,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
cmbScanZipInBrowser->setCurrentIndex( index );

// log rendering events, for userspace debugging
mLogCanvasRefreshChkBx->setChecked( mSettings->value( QStringLiteral( "/Map/logCanvasRefreshEvent" ), false ).toBool() );
mLogCanvasRefreshChkBx->setChecked( QgsMapRendererJob::Settings::logCanvasRefreshEvent.value() );

//set the default projection behavior radio buttons
const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App );
Expand Down Expand Up @@ -1014,9 +1015,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
//
QString currentLocale = QLocale().name();
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) );
QString userLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString( ) ).toString();
bool showGroupSeparator = mSettings->value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
QString globalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), currentLocale ).toString();
QString userLocale = QgsApplication::Settings::localeUserLocale.value();
bool showGroupSeparator = QgsApplication::Settings::localeShowGroupSeparator.value();
QString globalLocale = QgsApplication::Settings::localeGlobalLocale.value();
const QStringList language18nList( i18nList() );
for ( const auto &l : language18nList )
{
Expand All @@ -1043,8 +1044,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti

cboTranslation->setCurrentIndex( cboTranslation->findData( userLocale ) );
cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) );
bool localeOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
grpLocale->setChecked( localeOverrideFlag );
grpLocale->setChecked( QgsApplication::Settings::localeOverrideFlag.value() );
cbShowGroupSeparator->setChecked( showGroupSeparator );


Expand Down Expand Up @@ -1673,7 +1673,7 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/Raster/cumulativeCutUpper" ), mRasterCumulativeCutUpperDoubleSpinBox->value() / 100.0 );

// log rendering events, for userspace debugging
mSettings->setValue( QStringLiteral( "/Map/logCanvasRefreshEvent" ), mLogCanvasRefreshChkBx->isChecked() );
QgsMapRendererJob::Settings::logCanvasRefreshEvent.setValue( mLogCanvasRefreshChkBx->isChecked() );

//check behavior so default projection when new layer is added with no
//projection defined...
Expand Down Expand Up @@ -1856,12 +1856,12 @@ void QgsOptions::saveOptions()
//
// Locale settings
//
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() );
mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() );
mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() );
QgsApplication::Settings::localeUserLocale.setValue( cboTranslation->currentData().toString() );
QgsApplication::Settings::localeOverrideFlag.setValue( grpLocale->isChecked() );
QgsApplication::Settings::localeGlobalLocale.setValue( cboGlobalLocale->currentData( ).toString() );

// Number settings
mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) );
QgsApplication::Settings::localeShowGroupSeparator.setValue( cbShowGroupSeparator->isChecked( ) );

QgsLocalDefaultSettings::setBearingFormat( mBearingFormat.get() );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -983,7 +983,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
}

cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QLatin1String( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) );
cbtsLocale->setCurrentIndex( cbtsLocale->findData( QgsApplication::Settings::localeUserLocale.value() ) );

connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton );

Expand Down
4 changes: 2 additions & 2 deletions src/core/network/qgsnetworkaccessmanager.cpp
Expand Up @@ -674,12 +674,12 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn

int QgsNetworkAccessManager::timeout()
{
return QgsSettings().value( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 60000 ).toInt();
return Settings::networkTimeout.value();
}

void QgsNetworkAccessManager::setTimeout( const int time )
{
QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), time );
Settings::networkTimeout.setValue( time );
}

QgsNetworkReplyContent QgsNetworkAccessManager::blockingGet( QNetworkRequest &request, const QString &authCfg, bool forceRefresh, QgsFeedback *feedback )
Expand Down
1 change: 1 addition & 0 deletions src/core/network/qgsnetworkaccessmanager.h
Expand Up @@ -31,6 +31,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgssettingsentry.h"

class QgsFeedback;

Expand Down
17 changes: 8 additions & 9 deletions src/core/network/qgsnewsfeedparser.cpp
Expand Up @@ -40,24 +40,23 @@ QgsNewsFeedParser::QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcf

QUrlQuery query( feedUrl );

const qint64 after = QgsSettings().value( QStringLiteral( "%1/lastFetchTime" ).arg( mSettingsKey ), 0, QgsSettings::Core ).toUInt();
const qint64 after = Settings::feedLastFetchTime.value( mSettingsKey );
if ( after > 0 )
query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) );

QString feedLanguage = QgsSettings().value( QStringLiteral( "%1/lang" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toString();
QString feedLanguage = Settings::feedLanguage.value( mSettingsKey );
if ( feedLanguage.isEmpty() )
{
feedLanguage = QgsSettings().value( QStringLiteral( "locale/userLocale" ), QStringLiteral( "en_US" ) ).toString().left( 2 );
feedLanguage = QgsSettings().value( QgsApplication::Settings::localeUserLocale.key(), QStringLiteral( "en_US" ) ).toString().left( 2 );
}
if ( !feedLanguage.isEmpty() && feedLanguage != QLatin1String( "C" ) )
query.addQueryItem( QStringLiteral( "lang" ), feedLanguage );

bool latOk = false;
bool longOk = false;
const double feedLat = QgsSettings().value( QStringLiteral( "%1/latitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &latOk );
const double feedLong = QgsSettings().value( QStringLiteral( "%1/longitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &longOk );
if ( latOk && longOk )
if ( Settings::feedLatitude.exists( mSettingsKey ) && Settings::feedLongitude.exists( mSettingsKey ) )
{
const double feedLat = Settings::feedLatitude.value( mSettingsKey );
const double feedLong = Settings::feedLongitude.value( mSettingsKey );

// hack to allow testing using local files
if ( feedUrl.isLocalFile() )
{
Expand Down Expand Up @@ -170,7 +169,7 @@ void QgsNewsFeedParser::fetch()

void QgsNewsFeedParser::onFetch( const QString &content )
{
QgsSettings().setValue( mSettingsKey + "/lastFetchTime", mFetchStartTime, QgsSettings::Core );
Settings::feedLastFetchTime.setValue( mFetchStartTime, mSettingsKey );

const QVariant json = QgsJsonUtils::parseJson( content );

Expand Down
17 changes: 17 additions & 0 deletions src/core/network/qgsnewsfeedparser.h
Expand Up @@ -17,6 +17,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgssettingsentry.h"
#include <QObject>
#include <QUrl>
#include <QPixmap>
Expand Down Expand Up @@ -110,6 +111,22 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject
*/
static QString keyForFeed( const QString &baseUrl );

/**
* Contains QgsNewsFeedParser settings
* \since QGIS 3.20
*/
struct Settings
{
//! Settings entry last fetch time
static const inline QgsSettingsEntryInteger feedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 );
//! Settings entry feed language
static const inline QgsSettingsEntryString feedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) );
//! Settings entry feed latitude
static const inline QgsSettingsEntryDouble feedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) );
//! Settings entry feed longitude
static const inline QgsSettingsEntryDouble feedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) );
};

public slots:

/**
Expand Down
17 changes: 17 additions & 0 deletions src/core/processing/qgsprocessing.h
Expand Up @@ -19,6 +19,7 @@
#define QGSPROCESSING_H

#include "qgis_core.h"
#include "qgssettingsentry.h"
#include <QString>

//
Expand Down Expand Up @@ -97,6 +98,22 @@ class CORE_EXPORT QgsProcessing
* \since QGIS 3.6
*/
static const QString TEMPORARY_OUTPUT;

/**
* Contains QgsProcessing settings
* \since QGIS 3.20
*/
struct Settings
{
//! Settings entry prefer filename as layer name
static const inline QgsSettingsEntryBool preferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::NoSection, true, QObject::tr( "Prefer filename as layer name" ) );
//! Settings entry temp path
static const inline QgsSettingsEntryString tempPath = QgsSettingsEntryString( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QgsSettings::NoSection, QString() );
//! Settings entry default output vector layer ext
static const inline QgsSettingsEntryInteger defaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 );
//! Settings entry default output raster layer ext
static const inline QgsSettingsEntryInteger defaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 );
};
};

#endif // QGSPROCESSING_H
2 changes: 1 addition & 1 deletion src/core/processing/qgsprocessingcontext.cpp
Expand Up @@ -197,7 +197,7 @@ void QgsProcessingContext::LayerDetails::setOutputLayerName( QgsMapLayer *layer
if ( !layer )
return;

const bool preferFilenameAsLayerName = QgsSettings().value( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), true ).toBool();
const bool preferFilenameAsLayerName = QgsProcessing::Settings::preferFilenameAsLayerName.value();

// note - for temporary layers, we don't use the filename, regardless of user setting (it will be meaningless!)
if ( ( !forceName && preferFilenameAsLayerName && !layer->isTemporary() ) || name.isEmpty() )
Expand Down
8 changes: 3 additions & 5 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -954,7 +954,7 @@ QString QgsProcessingUtils::tempFolder()
static QString sFolder;
static QMutex sMutex;
QMutexLocker locker( &sMutex );
const QString basePath = QgsSettings().value( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ) ).toString();
const QString basePath = QgsProcessing::Settings::tempPath.value();
if ( basePath.isEmpty() )
{
// default setting -- automatically create a temp folder
Expand Down Expand Up @@ -1211,17 +1211,15 @@ QgsFields QgsProcessingUtils::indicesToFields( const QList<int> &indices, const

QString QgsProcessingUtils::defaultVectorExtension()
{
QgsSettings settings;
const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), -1 ).toInt();
const int setting = QgsProcessing::Settings::defaultOutputVectorLayerExt.value();
if ( setting == -1 )
return QStringLiteral( "gpkg" );
return QgsVectorFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "gpkg" ) );
}

QString QgsProcessingUtils::defaultRasterExtension()
{
QgsSettings settings;
const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), -1 ).toInt();
const int setting = QgsProcessing::Settings::defaultOutputRasterLayerExt.value();
if ( setting == -1 )
return QStringLiteral( "tif" );
return QgsRasterFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "tif" ) );
Expand Down

0 comments on commit 00a7936

Please sign in to comment.