static inline settings

This commit is contained in:
Damiano 2021-03-30 17:08:50 +02:00
parent 2db776ec35
commit 21c19aba9c
15 changed files with 632 additions and 252 deletions

View File

@ -614,6 +614,14 @@ should be canceled.
.. versionadded:: 3.10 .. versionadded:: 3.10
%End %End
struct Settings
{
static QgsSettingsEntryStringList searchPathForTemplates = QgsSettingsEntryStringList( QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), "Search path for templates" );
};
public slots: public slots:
void refresh(); void refresh();

View File

@ -141,6 +141,11 @@ This list is updated when preparing the search
.. versionadded:: 3.16 .. versionadded:: 3.16
%End %End
struct Settings
{
};
signals: signals:
void foundResult( const QgsLocatorResult &result ); void foundResult( const QgsLocatorResult &result );

View File

@ -657,6 +657,13 @@ Returns the application's task manager, used for managing application
wide background task handling. wide background task handling.
.. versionadded:: 3.0 .. versionadded:: 3.0
%End
static QgsSettingsRegistryCore *settingsRegistryCore() /KeepReference/;
%Docstring
Returns the application's settings registry, used for managing application settings.
.. versionadded:: 3.20
%End %End
static QgsColorSchemeRegistry *colorSchemeRegistry() /KeepReference/; static QgsColorSchemeRegistry *colorSchemeRegistry() /KeepReference/;

View File

@ -0,0 +1,306 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsentry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsSettingsEntry
{
%Docstring(signature="appended")
Represent settings entry and provides methods for reading and writing settings values.
Different subclasses are provided for different settings types with metainformations
to validate set values and provide more accurate settings description for the gui.
.. versionadded:: 3.20
%End
%TypeHeaderCode
#include "qgssettingsentry.h"
%End
%ConvertToSubClassCode
if ( dynamic_cast< QgsSettingsEntryString * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryString;
if ( dynamic_cast< QgsSettingsEntryStringList * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryStringList;
else if ( dynamic_cast< QgsSettingsEntryBool * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryBool;
// else if ( dynamic_cast< QgsSettingsEntryInteger * >( sipCpp ) )
// sipType = sipType_QgsSettingsEntryInteger;
// else if ( dynamic_cast< QgsSettingsEntryDouble * >( sipCpp ) )
// sipType = sipType_QgsSettingsEntryDouble;
else
sipType = NULL;
%End
public:
enum SettingsType
{
Variant,
String,
StringList,
Bool,
Integer,
Double,
Enum
};
QgsSettingsEntry( QString key,
QgsSettings::Section section,
QVariant defaultValue = QVariant(),
QString description = QString() );
%Docstring
Constructor for QgsSettingsEntry.
The ``key`` argument specifies the key of the settings.
The ``section`` argument specifies the section of the settings.
The ``default`` value argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
%End
virtual ~QgsSettingsEntry();
QString key( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings entry key.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End
bool hasDynamicKey() const;
%Docstring
Returns true if a part of the settings key is built dynamically.
%End
bool exists( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Returns true if the settings is contained in the underlying QSettings.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End
void remove( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Removes the settings from the underlying QSettings.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End
QgsSettings::Section section() const;
%Docstring
Get settings section. The settings section of the parent group is returned if available.
%End
virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() );
%Docstring
Set settings value.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End
QVariant valueFromPython() const /PyName=value/;
%Docstring
Get settings value.
%End
QVariant defaultValueFromPython() const /PyName=defaultValue/;
%Docstring
Get settings default value.
%End
virtual SettingsType settingsType() const;
%Docstring
Get the settings entry type.
%End
QString description() const;
%Docstring
Get the settings entry description.
%End
};
class QgsSettingsEntryString : QgsSettingsEntry
{
%Docstring(signature="appended")
A string settings entry.
.. versionadded:: 3.20
%End
%TypeHeaderCode
#include "qgssettingsentry.h"
%End
public:
QgsSettingsEntryString( const QString &key,
QgsSettings::Section section,
const QString &defaultValue = QString(),
const QString &description = QString(),
int minLength = 0,
int maxLength = -1 );
%Docstring
Constructor for QgsSettingsEntryString.
The ``key`` argument specifies the final part of the settings key.
The ``parentGroup`` argument specifies a parent group which is used to rebuild
the entiere settings key and to determine the settings section.
The ``default`` value argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``minLength`` argument specifies the minimal length of the string value.
The ``maxLength`` argument specifies the maximal length of the string value.
By -1 the there is no limit
%End
virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() );
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.setValue
%End
virtual SettingsType settingsType() const;
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.settingsType
%End
int minLength();
%Docstring
Returns the string minimum length.
%End
int maxLength();
%Docstring
Returns the string maximum length. By -1 there is no limitation.
%End
};
class QgsSettingsEntryStringList : QgsSettingsEntry
{
%Docstring(signature="appended")
A string list settings entry.
.. versionadded:: 3.20
%End
%TypeHeaderCode
#include "qgssettingsentry.h"
%End
public:
QgsSettingsEntryStringList( const QString &key,
QgsSettings::Section section,
const QStringList &defaultValue = QStringList(),
const QString &description = QString() );
%Docstring
Constructor for QgsSettingsEntryStringList.
The ``key`` argument specifies the final part of the settings key.
The ``parentGroup`` argument specifies a parent group which is used to rebuild
the entiere settings key and to determine the settings section.
The ``default`` value argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
%End
virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() );
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.setValue
%End
virtual SettingsType settingsType() const;
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.settingsType
%End
};
class QgsSettingsEntryBool : QgsSettingsEntry
{
%Docstring(signature="appended")
A boolean settings entry.
.. versionadded:: 3.20
%End
%TypeHeaderCode
#include "qgssettingsentry.h"
%End
public:
QgsSettingsEntryBool( const QString &key,
QgsSettings::Section section,
bool defaultValue = false,
const QString &description = QString() );
%Docstring
Constructor for QgsSettingsEntryBool.
The ``key`` argument specifies the final part of the settings key.
The ``parentGroup`` argument specifies a parent group which is used to rebuild
the entiere settings key and to determine the settings section.
The ``default`` value argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
%End
virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() );
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.setValue
%End
virtual SettingsType settingsType() const;
%Docstring
\copydoc :py:class:`QgsSettingsEntry`.settingsType
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsentry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,39 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsregistrycore.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsSettingsRegistryCore
{
%Docstring(signature="appended")
.. versionadded:: 3.20
%End
%TypeHeaderCode
#include "qgssettingsregistrycore.h"
%End
public:
QgsSettingsRegistryCore();
~QgsSettingsRegistryCore();
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsregistrycore.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -602,6 +602,8 @@
%Include auto_generated/textrenderer/qgstextrenderer.sip %Include auto_generated/textrenderer/qgstextrenderer.sip
%Include auto_generated/textrenderer/qgstextrendererutils.sip %Include auto_generated/textrenderer/qgstextrendererutils.sip
%Include auto_generated/textrenderer/qgstextshadowsettings.sip %Include auto_generated/textrenderer/qgstextshadowsettings.sip
%Include auto_generated/settings/qgssettingsentry.sip
%Include auto_generated/settings/qgssettingsregistrycore.sip
%Include auto_generated/validity/qgsabstractvaliditycheck.sip %Include auto_generated/validity/qgsabstractvaliditycheck.sip
%Include auto_generated/validity/qgsvaliditycheckcontext.sip %Include auto_generated/validity/qgsvaliditycheckcontext.sip
%Include auto_generated/validity/qgsvaliditycheckregistry.sip %Include auto_generated/validity/qgsvaliditycheckregistry.sip

View File

@ -330,26 +330,30 @@ void QgsLocatorFiltersModel::commitChanges()
if ( !activePrefix.isEmpty() && activePrefix != filter->prefix() ) if ( !activePrefix.isEmpty() && activePrefix != filter->prefix() )
{ {
filter->setActivePrefix( activePrefix ); filter->setActivePrefix( activePrefix );
QgsLocator::Settings::LocatorFilterPrefix().setValue( activePrefix, filter->name() ); // QgsLocator::Settings::LocatorFilterPrefix().setValue( activePrefix, filter->name() );
// QgsLocator::Settings::locatorFilterPrefix.setValue( activePrefix, filter->name() );
} }
else else
{ {
filter->setActivePrefix( QString() ); filter->setActivePrefix( QString() );
QgsLocator::Settings::LocatorFilterPrefix().remove( filter->name() ); // QgsLocator::Settings::LocatorFilterPrefix().remove( filter->name() );
// QgsLocator::Settings::locatorFilterPrefix.remove( filter->name() );
} }
} }
QHash< QgsLocatorFilter *, bool >::const_iterator it = mEnabledChanges.constBegin(); QHash< QgsLocatorFilter *, bool >::const_iterator it = mEnabledChanges.constBegin();
for ( ; it != mEnabledChanges.constEnd(); ++it ) for ( ; it != mEnabledChanges.constEnd(); ++it )
{ {
QgsLocatorFilter *filter = it.key(); QgsLocatorFilter *filter = it.key();
QgsLocator::Settings::LocatorFilterEnabled().setValue( it.value(), filter->name() ); // QgsLocator::Settings::LocatorFilterEnabled().setValue( it.value(), filter->name() );
// QgsLocator::Settings::locatorFilterEnabled.setValue( it.value(), filter->name() );
filter->setEnabled( it.value() ); filter->setEnabled( it.value() );
} }
it = mDefaultChanges.constBegin(); it = mDefaultChanges.constBegin();
for ( ; it != mDefaultChanges.constEnd(); ++it ) for ( ; it != mDefaultChanges.constEnd(); ++it )
{ {
QgsLocatorFilter *filter = it.key(); QgsLocatorFilter *filter = it.key();
QgsLocator::Settings::LocatorFilterDefault().setValue( it.value(), filter->name() ); // QgsLocator::Settings::LocatorFilterDefault().setValue( it.value(), filter->name() );
// QgsLocator::Settings::locatorFilterDefault.setValue( it.value(), filter->name() );
filter->setUseWithoutPrefix( it.value() ); filter->setUseWithoutPrefix( it.value() );
} }
} }

View File

@ -1481,7 +1481,8 @@ void QgsOptions::saveOptions()
{ {
pathsList << mListComposerTemplatePaths->item( i )->text(); pathsList << mListComposerTemplatePaths->item( i )->text();
} }
QgsLayout::Settings::SearchPathForTemplates().setValue( pathsList ); // QgsLayout::Settings::searchPathForTemplates.setValue( pathsList );
// QgsLayout::Settings::SearchPathForTemplates().setValue( pathsList );
pathsList.clear(); pathsList.clear();
for ( int r = 0; r < mLocalizedDataPathListWidget->count(); r++ ) for ( int r = 0; r < mLocalizedDataPathListWidget->count(); r++ )

View File

@ -658,9 +658,19 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/ */
bool accept( QgsStyleEntityVisitorInterface *visitor ) const; bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
struct Settings struct Settings
{ {
QGS_SETTING_ENTRY_STRINGLIST( SearchPathForTemplates, QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), tr( "Search path for templates" ) ) static inline QgsSettingsEntryStringList searchPathForTemplates = QgsSettingsEntryStringList( QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), "Search path for templates" );
// QGS_SETTING_ENTRY_STRINGLIST( SearchPathForTemplates, QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), tr( "Search path for templates" ) )
// struct SearchPathForTemplates : public QgsSettingsEntryStringList
// {
// SearchPathForTemplates()
// : QgsSettingsEntryStringList( QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), tr( "Search path for templates" ) )
// {}
// };
}; };
public slots: public slots:

View File

@ -95,14 +95,20 @@ void QgsLocator::registerFilter( QgsLocatorFilter *filter )
// restore settings // restore settings
bool enabled = true; bool enabled = true;
if ( QgsLocator::Settings::LocatorFilterEnabled().exists( filter->name() ) ) // if ( QgsLocator::Settings::LocatorFilterEnabled().exists( filter->name() ) )
enabled = QgsLocator::Settings::LocatorFilterEnabled().value<bool>( filter->name() ); // enabled = QgsLocator::Settings::LocatorFilterEnabled().value<bool>( filter->name() );
// if ( QgsLocator::Settings::locatorFilterEnabled.exists( filter->name() ) )
// enabled = QgsLocator::Settings::locatorFilterEnabled.value<bool>( filter->name() );
bool byDefault = filter->useWithoutPrefix(); bool byDefault = filter->useWithoutPrefix();
if ( QgsLocator::Settings::LocatorFilterDefault().exists( filter->name() ) ) // if ( QgsLocator::Settings::LocatorFilterDefault().exists( filter->name() ) )
byDefault = QgsLocator::Settings::LocatorFilterDefault().value<bool>( filter->name() ); // byDefault = QgsLocator::Settings::LocatorFilterDefault().value<bool>( filter->name() );
// if ( QgsLocator::Settings::locatorFilterDefault.exists( filter->name() ) )
// byDefault = QgsLocator::Settings::locatorFilterDefault.value<bool>( filter->name() );
QString prefix = filter->prefix(); QString prefix = filter->prefix();
if ( QgsLocator::Settings::LocatorFilterPrefix().exists( filter->name() ) ) // if ( QgsLocator::Settings::LocatorFilterPrefix().exists( filter->name() ) )
prefix = QgsLocator::Settings::LocatorFilterPrefix().value<QString>( filter->name() ); // prefix = QgsLocator::Settings::LocatorFilterPrefix().value<QString>( filter->name() );
// if ( QgsLocator::Settings::locatorFilterPrefix.exists( filter->name() ) )
// prefix = QgsLocator::Settings::locatorFilterPrefix.value<QString>( filter->name() );
if ( prefix.isEmpty() ) if ( prefix.isEmpty() )
{ {
prefix = filter->prefix(); prefix = filter->prefix();

View File

@ -155,9 +155,13 @@ class CORE_EXPORT QgsLocator : public QObject
struct Settings struct Settings
{ {
QGS_SETTING_ENTRY_BOOL( LocatorFilterEnabled, QStringLiteral( "locator_filters/enabled_%" ), QgsSettings::Gui, true, tr( "Enabled" ) ) // static inline QgsSettingsEntryBool locatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "locator_filters/enabled_%" ), QgsSettings::Gui, true, "Enabled" );
QGS_SETTING_ENTRY_BOOL( LocatorFilterDefault, QStringLiteral( "locator_filters/default_%" ), QgsSettings::Gui, false, tr( "Default value" ) ) // static inline QgsSettingsEntryBool locatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "locator_filters/default_%" ), QgsSettings::Gui, false, "Default value" );
QGS_SETTING_ENTRY_STRING( LocatorFilterPrefix, QStringLiteral( "locator_filters/prefix_%" ), QgsSettings::Gui, QString(), tr( "Locator filter prefix" ) ) // static inline QgsSettingsEntryString locatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "locator_filters/prefix_%" ), QgsSettings::Gui, QString(), "Locator filter prefix" );
// QGS_SETTING_ENTRY_BOOL( LocatorFilterEnabled, QStringLiteral( "locator_filters/enabled_%" ), QgsSettings::Gui, true, tr( "Enabled" ) )
// QGS_SETTING_ENTRY_BOOL( LocatorFilterDefault, QStringLiteral( "locator_filters/default_%" ), QgsSettings::Gui, false, tr( "Default value" ) )
// QGS_SETTING_ENTRY_STRING( LocatorFilterPrefix, QStringLiteral( "locator_filters/prefix_%" ), QgsSettings::Gui, QString(), tr( "Locator filter prefix" ) )
}; };
signals: signals:

View File

@ -1107,7 +1107,8 @@ QStringList QgsApplication::layoutTemplatePaths()
{ {
//local directories to search when looking for an template with a given basename //local directories to search when looking for an template with a given basename
//defined by user in options dialog //defined by user in options dialog
return QgsLayout::Settings::SearchPathForTemplates().value<QStringList>(); return QgsLayout::Settings::searchPathForTemplates.value<QStringList>();
// return QgsLayout::Settings::SearchPathForTemplates().value<QStringList>();
} }
QMap<QString, QString> QgsApplication::systemEnvVars() QMap<QString, QString> QgsApplication::systemEnvVars()

View File

@ -229,140 +229,140 @@ QgsSettingsEntry::SettingsType QgsSettingsEntryBool::settingsType() const
return QgsSettingsEntry::Bool; return QgsSettingsEntry::Bool;
} }
QgsSettingsEntryInteger::QgsSettingsEntryInteger( const QString &key, //QgsSettingsEntryInteger::QgsSettingsEntryInteger( const QString &key,
QgsSettings::Section section, // QgsSettings::Section section,
qlonglong defaultValue, // qlonglong defaultValue,
const QString &description, // const QString &description,
qlonglong minValue, // qlonglong minValue,
qlonglong maxValue ) // qlonglong maxValue )
: QgsSettingsEntry( key, // : QgsSettingsEntry( key,
section, // section,
defaultValue, // defaultValue,
description ) // description )
, mMinValue( minValue ) // , mMinValue( minValue )
, mMaxValue( maxValue ) // , mMaxValue( maxValue )
{ //{
} //}
bool QgsSettingsEntryInteger::setValue( const QVariant &value, const QString &dynamicKeyPart ) //bool QgsSettingsEntryInteger::setValue( const QVariant &value, const QString &dynamicKeyPart )
{ //{
if ( value.canConvert<qlonglong>() == false ) // if ( value.canConvert<qlonglong>() == false )
{ // {
QgsDebugMsg( QObject::tr( "Can't convert value '%1' to qlonglong for settings with key '%2'" ) // QgsDebugMsg( QObject::tr( "Can't convert value '%1' to qlonglong for settings with key '%2'" )
.arg( value.toString() ) // .arg( value.toString() )
.arg( QgsSettingsEntry::key() ) ); // .arg( QgsSettingsEntry::key() ) );
return false; // return false;
} // }
qlonglong valueLongLong = value.toLongLong(); // qlonglong valueLongLong = value.toLongLong();
if ( valueLongLong < mMinValue ) // if ( valueLongLong < mMinValue )
{ // {
QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." ) // QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." )
.arg( QgsSettingsEntry::key() ) // .arg( QgsSettingsEntry::key() )
.arg( valueLongLong ) // .arg( valueLongLong )
.arg( mMinValue ) ); // .arg( mMinValue ) );
return false; // return false;
} // }
if ( valueLongLong > mMaxValue ) // if ( valueLongLong > mMaxValue )
{ // {
QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." ) // QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." )
.arg( QgsSettingsEntry::key() ) // .arg( QgsSettingsEntry::key() )
.arg( valueLongLong ) // .arg( valueLongLong )
.arg( mMinValue ) ); // .arg( mMinValue ) );
return false; // return false;
} // }
QgsSettingsEntry::setValue( value, dynamicKeyPart ); // QgsSettingsEntry::setValue( value, dynamicKeyPart );
return true; // return true;
} //}
QgsSettingsEntry::SettingsType QgsSettingsEntryInteger::settingsType() const //QgsSettingsEntry::SettingsType QgsSettingsEntryInteger::settingsType() const
{ //{
return QgsSettingsEntry::Integer; // return QgsSettingsEntry::Integer;
} //}
qlonglong QgsSettingsEntryInteger::minValue() //qlonglong QgsSettingsEntryInteger::minValue()
{ //{
return mMinValue; // return mMinValue;
} //}
qlonglong QgsSettingsEntryInteger::maxValue() //qlonglong QgsSettingsEntryInteger::maxValue()
{ //{
return mMaxValue; // return mMaxValue;
} //}
QgsSettingsEntryDouble::QgsSettingsEntryDouble( const QString &key, //QgsSettingsEntryDouble::QgsSettingsEntryDouble( const QString &key,
QgsSettings::Section section, // QgsSettings::Section section,
double defaultValue, // double defaultValue,
const QString &description, // const QString &description,
double minValue, // double minValue,
double maxValue, // double maxValue,
double displayDecimals ) // double displayDecimals )
: QgsSettingsEntry( key, // : QgsSettingsEntry( key,
section, // section,
defaultValue, // defaultValue,
description ) // description )
, mMinValue( minValue ) // , mMinValue( minValue )
, mMaxValue( maxValue ) // , mMaxValue( maxValue )
, mDisplayHintDecimals( displayDecimals ) // , mDisplayHintDecimals( displayDecimals )
{ //{
} //}
bool QgsSettingsEntryDouble::setValue( const QVariant &value, const QString &dynamicKeyPart ) //bool QgsSettingsEntryDouble::setValue( const QVariant &value, const QString &dynamicKeyPart )
{ //{
if ( value.canConvert<double>() == false ) // if ( value.canConvert<double>() == false )
{ // {
QgsDebugMsg( QObject::tr( "Can't convert value '%1' to double for settings with key '%2'" ) // QgsDebugMsg( QObject::tr( "Can't convert value '%1' to double for settings with key '%2'" )
.arg( value.toString() ) // .arg( value.toString() )
.arg( QgsSettingsEntry::key() ) ); // .arg( QgsSettingsEntry::key() ) );
return false; // return false;
} // }
double valueDouble = value.toDouble(); // double valueDouble = value.toDouble();
if ( valueDouble < mMinValue ) // if ( valueDouble < mMinValue )
{ // {
QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." ) // QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is less than minimum value '%3'." )
.arg( QgsSettingsEntry::key() ) // .arg( QgsSettingsEntry::key() )
.arg( valueDouble ) // .arg( valueDouble )
.arg( mMinValue ) ); // .arg( mMinValue ) );
return false; // return false;
} // }
if ( valueDouble > mMaxValue ) // if ( valueDouble > mMaxValue )
{ // {
QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." ) // QgsDebugMsg( QObject::tr( "Can't set value for settings with key '%1'. Value '%2' is greather than maximum value '%3'." )
.arg( QgsSettingsEntry::key() ) // .arg( QgsSettingsEntry::key() )
.arg( valueDouble ) // .arg( valueDouble )
.arg( mMinValue ) ); // .arg( mMinValue ) );
return false; // return false;
} // }
QgsSettingsEntry::setValue( value, dynamicKeyPart ); // QgsSettingsEntry::setValue( value, dynamicKeyPart );
return true; // return true;
} //}
QgsSettingsEntry::SettingsType QgsSettingsEntryDouble::settingsType() const //QgsSettingsEntry::SettingsType QgsSettingsEntryDouble::settingsType() const
{ //{
return QgsSettingsEntry::Double; // return QgsSettingsEntry::Double;
} //}
double QgsSettingsEntryDouble::minValue() const //double QgsSettingsEntryDouble::minValue() const
{ //{
return mMinValue; // return mMinValue;
} //}
double QgsSettingsEntryDouble::maxValue() const //double QgsSettingsEntryDouble::maxValue() const
{ //{
return mMaxValue; // return mMaxValue;
} //}
int QgsSettingsEntryDouble::displayHintDecimals() const //int QgsSettingsEntryDouble::displayHintDecimals() const
{ //{
return mDisplayHintDecimals; // return mDisplayHintDecimals;
} //}
bool QgsSettingsEntryEnum::setValue( const QVariant &value, const QString &dynamicKeyPart ) bool QgsSettingsEntryEnum::setValue( const QVariant &value, const QString &dynamicKeyPart )
{ {

View File

@ -23,9 +23,7 @@
#include "qgis_sip.h" #include "qgis_sip.h"
#include "qgssettings.h" #include "qgssettings.h"
#define QGS_SETTING_ENTRY_VARIANT(name, path, section, defaultValue, ...) \ #define QGS_SETTING_ENTRY_VARIANT(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntry { name() : QgsSettingsEntry( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntry\
{ name() : QgsSettingsEntry( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** /**
* \ingroup core * \ingroup core
@ -48,10 +46,10 @@ class CORE_EXPORT QgsSettingsEntry
sipType = sipType_QgsSettingsEntryStringList; sipType = sipType_QgsSettingsEntryStringList;
else if ( dynamic_cast< QgsSettingsEntryBool * >( sipCpp ) ) else if ( dynamic_cast< QgsSettingsEntryBool * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryBool; sipType = sipType_QgsSettingsEntryBool;
else if ( dynamic_cast< QgsSettingsEntryInteger * >( sipCpp ) ) // else if ( dynamic_cast< QgsSettingsEntryInteger * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryInteger; // sipType = sipType_QgsSettingsEntryInteger;
else if ( dynamic_cast< QgsSettingsEntryDouble * >( sipCpp ) ) // else if ( dynamic_cast< QgsSettingsEntryDouble * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryDouble; // sipType = sipType_QgsSettingsEntryDouble;
else else
sipType = NULL; sipType = NULL;
SIP_END SIP_END
@ -185,9 +183,7 @@ class CORE_EXPORT QgsSettingsEntry
}; };
#define QGS_SETTING_ENTRY_STRING(name, path, section, defaultValue, ...) \ #define QGS_SETTING_ENTRY_STRING(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryString { name() : QgsSettingsEntryString( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryString \
{ name() : QgsSettingsEntryString( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** /**
* \class QgsSettingsEntryString * \class QgsSettingsEntryString
@ -242,9 +238,7 @@ class CORE_EXPORT QgsSettingsEntryString : public QgsSettingsEntry
}; };
# define QGS_SETTING_ENTRY_STRINGLIST(name, path, section, defaultValue, ...) \ #define QGS_SETTING_ENTRY_STRINGLIST(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryStringList { name() : QgsSettingsEntryStringList( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryStringList \
{ name() : QgsSettingsEntryStringList( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** /**
* \class QgsSettingsEntryStringList * \class QgsSettingsEntryStringList
@ -279,9 +273,7 @@ class CORE_EXPORT QgsSettingsEntryStringList : public QgsSettingsEntry
}; };
# define QGS_SETTING_ENTRY_BOOL(name, path, section, defaultValue, ...) \ #define QGS_SETTING_ENTRY_BOOL(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryBool { name() : QgsSettingsEntryBool( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryBool \
{ name() : QgsSettingsEntryBool( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** /**
* \class QgsSettingsEntryBool * \class QgsSettingsEntryBool
@ -316,131 +308,125 @@ class CORE_EXPORT QgsSettingsEntryBool : public QgsSettingsEntry
}; };
# define QGS_SETTING_ENTRY_INTEGER(name, path, section, defaultValue, ...) \ //#define QGS_SETTING_ENTRY_INTEGER(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryInteger { name() : QgsSettingsEntryInteger( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryInteger \
{ name() : QgsSettingsEntryInteger( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** ///**
* \class QgsSettingsEntryInteger // * \class QgsSettingsEntryInteger
* \ingroup core // * \ingroup core
* An integer settings entry. // * An integer settings entry.
* \since QGIS 3.20 // * \since QGIS 3.20
*/ // */
class CORE_EXPORT QgsSettingsEntryInteger : public QgsSettingsEntry //class CORE_EXPORT QgsSettingsEntryInteger : public QgsSettingsEntry
{ //{
public: // public:
/** // /**
* Constructor for QgsSettingsEntryInteger. // * Constructor for QgsSettingsEntryInteger.
* // *
* The \a key argument specifies the final part of the settings key. // * The \a key argument specifies the final part of the settings key.
* The \a parentGroup argument specifies a parent group which is used to rebuild // * The \a parentGroup argument specifies a parent group which is used to rebuild
* the entiere settings key and to determine the settings section. // * the entiere settings key and to determine the settings section.
* The \a default value argument specifies the default value for the settings entry. // * The \a default value argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry. // * The \a description argument specifies a description for the settings entry.
* The \a minValue argument specifies the minimal value. // * The \a minValue argument specifies the minimal value.
* The \a maxValue argument specifies the maximal value. // * The \a maxValue argument specifies the maximal value.
*/ // */
QgsSettingsEntryInteger( const QString &key, // QgsSettingsEntryInteger( const QString &key,
QgsSettings::Section section, // QgsSettings::Section section,
qlonglong defaultValue = 0, // qlonglong defaultValue = 0,
const QString &description = QString(), // const QString &description = QString(),
qlonglong minValue = std::numeric_limits<qlonglong>::min(), // qlonglong minValue = std::numeric_limits<qlonglong>::min(),
qlonglong maxValue = std::numeric_limits<qlonglong>::max() ); // qlonglong maxValue = std::numeric_limits<qlonglong>::max() );
//! \copydoc QgsSettingsEntry::setValue // //! \copydoc QgsSettingsEntry::setValue
bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) override; // bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) override;
//! \copydoc QgsSettingsEntry::settingsType // //! \copydoc QgsSettingsEntry::settingsType
virtual SettingsType settingsType() const override; // virtual SettingsType settingsType() const override;
/** // /**
* Returns the minimum value. // * Returns the minimum value.
*/ // */
qlonglong minValue(); // qlonglong minValue();
/** // /**
* Returns the maximum value. // * Returns the maximum value.
*/ // */
qlonglong maxValue(); // qlonglong maxValue();
private: // private:
qlonglong mMinValue; // qlonglong mMinValue;
qlonglong mMaxValue; // qlonglong mMaxValue;
}; //};
# define QGS_SETTING_ENTRY_DOUBLE(name, path, section, defaultValue, ...) \ //#define QGS_SETTING_ENTRY_DOUBLE(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryDouble { name() : QgsSettingsEntryDouble( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryDouble \
{ name() : QgsSettingsEntryDouble( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** ///**
* \class QgsSettingsEntryDouble // * \class QgsSettingsEntryDouble
* \ingroup core // * \ingroup core
* A double settings entry. // * A double settings entry.
* \since QGIS 3.20 // * \since QGIS 3.20
*/ // */
class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntry //class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntry
{ //{
public: // public:
/** // /**
* Constructor for QgsSettingsEntryDouble. // * Constructor for QgsSettingsEntryDouble.
* // *
* The \a key argument specifies the final part of the settings key. // * The \a key argument specifies the final part of the settings key.
* The \a parentGroup argument specifies a parent group which is used to rebuild // * The \a parentGroup argument specifies a parent group which is used to rebuild
* the entiere settings key and to determine the settings section. // * the entiere settings key and to determine the settings section.
* The \a default value argument specifies the default value for the settings entry. // * The \a default value argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry. // * The \a description argument specifies a description for the settings entry.
* The \a minValue argument specifies the minimal value. // * The \a minValue argument specifies the minimal value.
* The \a maxValue argument specifies the maximal value. // * The \a maxValue argument specifies the maximal value.
*/ // */
QgsSettingsEntryDouble( const QString &key, // QgsSettingsEntryDouble( const QString &key,
QgsSettings::Section section, // QgsSettings::Section section,
double defaultValue = 0.0, // double defaultValue = 0.0,
const QString &description = QString(), // const QString &description = QString(),
double minValue = std::numeric_limits<double>::min(), // double minValue = std::numeric_limits<double>::min(),
double maxValue = std::numeric_limits<double>::max(), // double maxValue = std::numeric_limits<double>::max(),
double displayDecimals = 1 ); // double displayDecimals = 1 );
//! \copydoc QgsSettingsEntry::setValue // //! \copydoc QgsSettingsEntry::setValue
bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) override; // bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) override;
//! \copydoc QgsSettingsEntry::settingsType // //! \copydoc QgsSettingsEntry::settingsType
virtual SettingsType settingsType() const override; // virtual SettingsType settingsType() const override;
/** // /**
* Returns the minimum value. // * Returns the minimum value.
*/ // */
double minValue() const; // double minValue() const;
/** // /**
* Returns the maximum value. // * Returns the maximum value.
*/ // */
double maxValue() const; // double maxValue() const;
/** // /**
* Returns how much decimals should be shown in the Gui. // * Returns how much decimals should be shown in the Gui.
*/ // */
int displayHintDecimals() const; // int displayHintDecimals() const;
private: // private:
double mMinValue; // double mMinValue;
double mMaxValue; // double mMaxValue;
int mDisplayHintDecimals; // int mDisplayHintDecimals;
}; //};
#ifndef SIP_RUN #ifndef SIP_RUN
# define QGS_SETTING_ENTRY_ENUM(name, path, section, defaultValue, ...) \ #define QGS_SETTING_ENTRY_ENUM(name, path, section, defaultValue, ...) struct name : public QgsSettingsEntryEnum { name() : QgsSettingsEntryEnum( path, section, defaultValue, ##__VA_ARGS__ ) {} };
struct name : public QgsSettingsEntryEnum \
{ name() : QgsSettingsEntryEnum( path, section, defaultValue, ##__VA_ARGS__ ) {} };
/** /**
* \class QgsSettingsEntryEnum * \class QgsSettingsEntryEnum

View File

@ -21,16 +21,17 @@
QgsSettingsRegistryCore::QgsSettingsRegistryCore() QgsSettingsRegistryCore::QgsSettingsRegistryCore()
: mSettingsEntries() : mSettingsEntries()
{ {
mSettingsEntries.append( new QgsLayout::Settings::SearchPathForTemplates() ); mSettingsEntries.append( &QgsLayout::Settings::searchPathForTemplates );
// mSettingsEntries.append( new QgsLayout::Settings::SearchPathForTemplates() );
mSettingsEntries.append( new QgsLocator::Settings::LocatorFilterEnabled() ); // mSettingsEntries.append( &QgsLocator::Settings::locatorFilterEnabled );
mSettingsEntries.append( new QgsLocator::Settings::LocatorFilterDefault() ); // mSettingsEntries.append( &QgsLocator::Settings::locatorFilterDefault );
mSettingsEntries.append( new QgsLocator::Settings::LocatorFilterPrefix() ); // mSettingsEntries.append( &QgsLocator::Settings::locatorFilterPrefix );
} }
QgsSettingsRegistryCore::~QgsSettingsRegistryCore() QgsSettingsRegistryCore::~QgsSettingsRegistryCore()
{ {
qDeleteAll( mSettingsEntries ); // qDeleteAll( mSettingsEntries );
} }