Skip to content
Permalink
Browse files

Moved most core settings to SettingsEntry

  • Loading branch information
domi4484 committed Apr 26, 2021
1 parent 96cee9f commit 00a7936389a755fb8c71879ade49c47dfefe1c70
Showing with 242 additions and 83 deletions.
  1. +8 −0 python/core/auto_generated/network/qgsnewsfeedparser.sip.in
  2. +8 −0 python/core/auto_generated/processing/qgsprocessing.sip.in
  3. +9 −0 python/core/auto_generated/qgsapplication.sip.in
  4. +5 −0 python/core/auto_generated/qgsgeometryoptions.sip.in
  5. +5 −0 python/core/auto_generated/qgslocalizeddatapathregistry.sip.in
  6. +6 −0 python/core/auto_generated/qgsmaprendererjob.sip.in
  7. +14 −1 python/core/auto_generated/settings/qgssettingsregistrycore.sip.in
  8. +6 −8 src/app/main.cpp
  9. +11 −11 src/app/options/qgsoptions.cpp
  10. +1 −1 src/app/qgsprojectproperties.cpp
  11. +2 −2 src/core/network/qgsnetworkaccessmanager.cpp
  12. +1 −0 src/core/network/qgsnetworkaccessmanager.h
  13. +8 −9 src/core/network/qgsnewsfeedparser.cpp
  14. +17 −0 src/core/network/qgsnewsfeedparser.h
  15. +17 −0 src/core/processing/qgsprocessing.h
  16. +1 −1 src/core/processing/qgsprocessingcontext.cpp
  17. +3 −5 src/core/processing/qgsprocessingutils.cpp
  18. +1 −1 src/core/project/qgsproject.cpp
  19. +4 −7 src/core/qgsapplication.cpp
  20. +19 −0 src/core/qgsapplication.h
  21. +1 −1 src/core/qgsgeometryoptions.cpp
  22. +11 −0 src/core/qgsgeometryoptions.h
  23. +2 −2 src/core/qgslocalizeddatapathregistry.cpp
  24. +11 −0 src/core/qgslocalizeddatapathregistry.h
  25. +1 −2 src/core/qgsmaprendererjob.cpp
  26. +12 −0 src/core/qgsmaprendererjob.h
  27. +31 −0 src/core/settings/qgssettingsregistrycore.cpp
  28. +4 −4 src/gui/qgsconfigureshortcutsdialog.cpp
  29. +1 −2 src/gui/qgsgui.cpp
  30. +2 −2 src/gui/qgsmapcanvas.cpp
  31. +9 −11 tests/src/analysis/testqgsprocessing.cpp
  32. +1 −2 tests/src/core/testqgscompositionconverter.cpp
  33. +1 −1 tests/src/core/testqgsnetworkaccessmanager.cpp
  34. +5 −5 tests/src/core/testqgsnewsfeedparser.cpp
  35. +4 −5 tests/src/core/testqgstranslateproject.cpp
@@ -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();
@@ -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;
};
};

/************************************************************************
@@ -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 );
@@ -118,6 +118,11 @@ Read the geometry options from ``node``.
.. versionadded:: 3.4
%End

struct Settings
{
const QgsSettingsEntryString geometryValidationDefaultChecks;
};

signals:

void checkConfigurationChanged();
@@ -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 );
};
@@ -157,6 +157,12 @@ Returns map settings with which this job was started.




struct Settings
{
const QgsSettingsEntryBool logCanvasRefreshEvent;
};

signals:

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



class QgsSettingsRegistryCore : QgsSettingsRegistry



class QgsSettingsRegistryCore
{
%Docstring(signature="appended")
:py:class:`QgsSettingsRegistryCore` is used for settings introspection and collects 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

};

/************************************************************************
@@ -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();
}

//
@@ -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
{
@@ -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
{
@@ -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"
@@ -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 );
@@ -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 )
{
@@ -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 );


@@ -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...
@@ -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() );

@@ -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 );

@@ -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 )
@@ -31,6 +31,7 @@

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

class QgsFeedback;

@@ -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() )
{
@@ -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 );

@@ -17,6 +17,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgssettingsentry.h"
#include <QObject>
#include <QUrl>
#include <QPixmap>
@@ -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:

/**
@@ -19,6 +19,7 @@
#define QGSPROCESSING_H

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

//
@@ -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
@@ -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() )
@@ -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
@@ -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" ) );

0 comments on commit 00a7936

Please sign in to comment.