Skip to content

Commit

Permalink
[settings] add new type for variant map: QgsSettingsEntryVariantMap
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Dec 16, 2022
1 parent aa8d902 commit da48658
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/core/auto_additions/qgis.py
Expand Up @@ -158,6 +158,9 @@
QgsSettingsEntryBase.StringList = Qgis.SettingsType.StringList
QgsSettingsEntryBase.StringList.is_monkey_patched = True
QgsSettingsEntryBase.StringList.__doc__ = "List of strings"
QgsSettingsEntryBase.VariantMap = Qgis.SettingsType.VariantMap
QgsSettingsEntryBase.VariantMap.is_monkey_patched = True
QgsSettingsEntryBase.VariantMap.__doc__ = "Map of strings"
QgsSettingsEntryBase.Bool = Qgis.SettingsType.Bool
QgsSettingsEntryBase.Bool.is_monkey_patched = True
QgsSettingsEntryBase.Bool.__doc__ = "Boolean"
Expand All @@ -173,7 +176,7 @@
QgsSettingsEntryBase.Color = Qgis.SettingsType.Color
QgsSettingsEntryBase.Color.is_monkey_patched = True
QgsSettingsEntryBase.Color.__doc__ = "Color"
Qgis.SettingsType.__doc__ = 'Types of settings entries\n\n.. versionadded:: 3.26\n\n' + '* ``Variant``: ' + Qgis.SettingsType.Variant.__doc__ + '\n' + '* ``String``: ' + Qgis.SettingsType.String.__doc__ + '\n' + '* ``StringList``: ' + Qgis.SettingsType.StringList.__doc__ + '\n' + '* ``Bool``: ' + Qgis.SettingsType.Bool.__doc__ + '\n' + '* ``Integer``: ' + Qgis.SettingsType.Integer.__doc__ + '\n' + '* ``Double``: ' + Qgis.SettingsType.Double.__doc__ + '\n' + '* ``EnumFlag``: ' + Qgis.SettingsType.EnumFlag.__doc__ + '\n' + '* ``Color``: ' + Qgis.SettingsType.Color.__doc__
Qgis.SettingsType.__doc__ = 'Types of settings entries\n\n.. versionadded:: 3.26\n\n' + '* ``Variant``: ' + Qgis.SettingsType.Variant.__doc__ + '\n' + '* ``String``: ' + Qgis.SettingsType.String.__doc__ + '\n' + '* ``StringList``: ' + Qgis.SettingsType.StringList.__doc__ + '\n' + '* ``VariantMap``: ' + Qgis.SettingsType.VariantMap.__doc__ + '\n' + '* ``Bool``: ' + Qgis.SettingsType.Bool.__doc__ + '\n' + '* ``Integer``: ' + Qgis.SettingsType.Integer.__doc__ + '\n' + '* ``Double``: ' + Qgis.SettingsType.Double.__doc__ + '\n' + '* ``EnumFlag``: ' + Qgis.SettingsType.EnumFlag.__doc__ + '\n' + '* ``Color``: ' + Qgis.SettingsType.Color.__doc__
# --
Qgis.SettingsType.baseClass = Qgis
# monkey patching scoped based enum
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -153,6 +153,7 @@ The development version
Variant,
String,
StringList,
VariantMap,
Bool,
Integer,
Double,
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_generated/settings/qgssettingsentry.sip.in
Expand Up @@ -91,6 +91,8 @@ to validate set values and provide more accurate settings description for the gu
sipType = sipType_QgsSettingsEntryString;
else if ( dynamic_cast< QgsSettingsEntryStringList * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryStringList;
else if ( dynamic_cast< QgsSettingsEntryVariantMap * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryVariantMap;
else if ( dynamic_cast< QgsSettingsEntryBool * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryBool;
else if ( dynamic_cast< QgsSettingsEntryInteger * >( sipCpp ) )
Expand Down
62 changes: 62 additions & 0 deletions python/core/auto_generated/settings/qgssettingsentryimpl.sip.in
Expand Up @@ -569,6 +569,68 @@ The ``options`` arguments specifies the options for the settings entry.

};


typedef QgsSettingsEntryByReference<QVariantMap> QgsSettingsEntryByReferenceQVariantMapBase;

class QgsSettingsEntryVariantMap : QgsSettingsEntryByReferenceQVariantMapBase
{
%Docstring(signature="appended")

A string list settings entry.

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgssettingsentryimpl.h"
#include "qgssettingsentry.h"
typedef QgsSettingsEntryByReference<QVariantMap> QgsSettingsEntryByReferenceQVariantMapBase;
%End
public:

private:
QgsSettingsEntryVariantMap( const QString &key,
const QString &section,
const QVariantMap &defaultValue = QVariantMap(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryVariantMap.

The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
public:

QgsSettingsEntryVariantMap( const QString &key,
const QString &pluginName,
const QVariantMap &defaultValue = QVariantMap(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for :py:class:`QgsSettingsEntryStringMap`.
This constructor is intended to be used from plugins.

The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryVariantMap( QgsSettingsEntryVariantMap( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
%End

virtual Qgis::SettingsType settingsType() const;

private:
virtual QVariantMap convertFromVariant( const QVariant &value ) const;

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
1 change: 1 addition & 0 deletions src/core/qgis.h
Expand Up @@ -232,6 +232,7 @@ class CORE_EXPORT Qgis
Variant, //!< Generic variant
String, //!< String
StringList, //!< List of strings
VariantMap, //!< Map of strings
Bool, //!< Boolean
Integer, //!< Integer
Double, //!< Double precision number
Expand Down
3 changes: 3 additions & 0 deletions src/core/settings/qgssettingsentry.cpp
Expand Up @@ -106,6 +106,9 @@ bool QgsSettingsEntryGroup::hasDynamicKey() const
}


/*--------------*/


QString QgsSettingsEntryBase::key( const QString &dynamicKeyPart ) const
{
return key( dynamicKeyPartToList( dynamicKeyPart ) );
Expand Down
2 changes: 2 additions & 0 deletions src/core/settings/qgssettingsentry.h
Expand Up @@ -110,6 +110,8 @@ class CORE_EXPORT QgsSettingsEntryBase
sipType = sipType_QgsSettingsEntryString;
else if ( dynamic_cast< QgsSettingsEntryStringList * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryStringList;
else if ( dynamic_cast< QgsSettingsEntryVariantMap * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryVariantMap;
else if ( dynamic_cast< QgsSettingsEntryBool * >( sipCpp ) )
sipType = sipType_QgsSettingsEntryBool;
else if ( dynamic_cast< QgsSettingsEntryInteger * >( sipCpp ) )
Expand Down
9 changes: 9 additions & 0 deletions src/core/settings/qgssettingsentryimpl.cpp
Expand Up @@ -226,3 +226,12 @@ Qgis::SettingsType QgsSettingsEntryColor::settingsType() const
return Qgis::SettingsType::Color;
}

QVariantMap QgsSettingsEntryVariantMap::convertFromVariant( const QVariant &value ) const
{
return value.value<QVariantMap>();
}

Qgis::SettingsType QgsSettingsEntryVariantMap::settingsType() const
{
return Qgis::SettingsType::VariantMap;
}
58 changes: 58 additions & 0 deletions src/core/settings/qgssettingsentryimpl.h
Expand Up @@ -558,4 +558,62 @@ class CORE_EXPORT QgsSettingsEntryColor : public QgsSettingsEntryByReference<QCo

};

/**
* \class QgsSettingsEntryStringMap
* \ingroup core
*
* \brief A string list settings entry.
* \since QGIS 3.20
*/
class CORE_EXPORT QgsSettingsEntryVariantMap : public QgsSettingsEntryByReference<QVariantMap>
{
public:

/**
* Constructor for QgsSettingsEntryVariantMap.
*
* The \a key argument specifies the final part of the settings key.
* The \a section argument specifies the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryVariantMap( const QString &key,
const QString &section,
const QVariantMap &defaultValue = QVariantMap(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{
}

#ifdef SIP_RUN

/**
* Constructor for QgsSettingsEntryStringMap.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryVariantMap( const QString &key,
const QString &pluginName,
const QVariantMap &defaultValue = QVariantMap(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
% MethodCode
sipCpp = new sipQgsSettingsEntryVariantMap( QgsSettingsEntryVariantMap( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
% End
#endif

virtual Qgis::SettingsType settingsType() const override;

private:
QVariantMap convertFromVariant( const QVariant &value ) const override SIP_FORCE;

};

#endif // QGSSETTINGSENTRYIMPL_H

0 comments on commit da48658

Please sign in to comment.