Navigation Menu

Skip to content

Commit

Permalink
add allowAlpha option for color settings + better dox
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 16, 2023
1 parent 53f3745 commit 46dec7e
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 333 deletions.
14 changes: 8 additions & 6 deletions python/core/auto_generated/settings/qgssettingsentry.sip.in
Expand Up @@ -335,11 +335,12 @@ Returns the current value (or default) if there is no former value.
.. versionadded:: 3.26
%End

bool copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList(), bool deleteOldKey = false ) const;
bool copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList(), bool removeSettingAtKey = false ) const;
%Docstring
Checks if the settings does not exist and tries to set it from a given ``oldKey``.
\arg dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
If ``deleteOldKey``, the setting with the old key will be removed

:param dynamicKeyPartList: is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
:param removeSettingAtKey: if ``True``, the setting at the old key will be removed

:return: ``True`` if the key exists and the setting value could be copied

Expand All @@ -349,7 +350,8 @@ If ``deleteOldKey``, the setting with the old key will be removed
void copyValueToKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList() ) const;
%Docstring
Copies the settings to the given ``key``
\arg dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.

:param dynamicKeyPartList: is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.

.. versionadded:: 3.30
%End
Expand Down Expand Up @@ -430,14 +432,14 @@ The ``options`` arguments specifies the options for the settings entry.
%Docstring
Returns settings value.

\arg dynamicKeyPart specifies the dynamic part of the settings key.
:param dynamicKeyPart: specifies the dynamic part of the settings key.
%End

T value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Returns settings value.

\arg dynamicKeyPartList specifies the list of dynamic parts of the settings key.
:param dynamicKeyPartList: specifies the list of dynamic parts of the settings key.
%End


Expand Down
312 changes: 163 additions & 149 deletions python/core/auto_generated/settings/qgssettingsentryimpl.sip.in

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions python/core/auto_generated/settings/qgssettingstreeelement.sip.in
Expand Up @@ -81,8 +81,9 @@ Returns the type of element
void registerChildSetting( QgsSettingsEntryBase *setting, const QString &key ) throw( QgsSettingsException );
%Docstring
Registers a child setting
\arg setting the setting to register
\arg key the key of the setting (not the complete key from its parents)

:param setting: the setting to register
:param key: the key of the setting (not the complete key from its parents)

.. note::

Expand All @@ -96,8 +97,9 @@ Registers a child setting
void unregisterChildSetting( QgsSettingsEntryBase *setting, bool deleteSettingValues = false, const QStringList &parentsNamedItems = QStringList() );
%Docstring
Unregisters the child setting
\arg deleteSettingValues if ``True``, the values of the settings will also be deleted
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param deleteSettingValues: if ``True``, the values of the settings will also be deleted
:param parentsNamedItems: the list of named items in the parent named list (if any)
%End

void unregisterChildElement( QgsSettingsTreeElement *element );
Expand Down Expand Up @@ -201,33 +203,38 @@ the named list element is used to store a group of settings under a dynamically
QStringList items( const QStringList &parentsNamedItems = QStringList() ) const throw( QgsSettingsException );
%Docstring
Returns the list of items
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param parentsNamedItems: the list of named items in the parent named list (if any)
%End

QStringList items( Qgis::SettingsLocation location, const QStringList &parentsNamedItems = QStringList() ) const throw( QgsSettingsException );
%Docstring
Returns the list of items
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param parentsNamedItems: the list of named items in the parent named list (if any)
%End


void setSelectedItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) throw( QgsSettingsException );
%Docstring
Sets the selected named entry from the named list element
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param parentsNamedItems: the list of named items in the parent named list (if any)
%End

QString selectedItem( const QStringList &parentsNamedItems = QStringList() ) throw( QgsSettingsException );
%Docstring
Returns the selected named entry from the named list element
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param parentsNamedItems: the list of named items in the parent named list (if any)
%End

void deleteItem( const QString &item, const QStringList &parentsNamedItems = QStringList() ) throw( QgsSettingsException );
%Docstring
Deletes a named entry from the named list element
\arg entry the entry to delete
\arg parentsNamedItems the list of named items in the parent named list (if any)

:param entry: the entry to delete
:param parentsNamedItems: the list of named items in the parent named list (if any)
%End

QgsSettingsEntryString *selectedItemSetting() const;
Expand Down
4 changes: 2 additions & 2 deletions src/core/settings/qgssettingsentry.cpp
Expand Up @@ -309,7 +309,7 @@ QVariant QgsSettingsEntryBase::formerValueAsVariant( const QStringList &dynamicK
}


bool QgsSettingsEntryBase::copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList, bool deleteOldKey ) const
bool QgsSettingsEntryBase::copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList, bool removeSettingAtKey ) const
{
if ( exists( dynamicKeyPartList ) )
return false;
Expand All @@ -322,7 +322,7 @@ bool QgsSettingsEntryBase::copyValueFromKey( const QString &key, const QStringLi
{
QVariant oldValue = settings.value( oldCompleteKey, mDefaultValue );
setVariantValuePrivate( oldValue, dynamicKeyPartList );
if ( deleteOldKey )
if ( removeSettingAtKey )
settings.remove( oldCompleteKey );
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/settings/qgssettingsentry.h
Expand Up @@ -344,16 +344,16 @@ class CORE_EXPORT QgsSettingsEntryBase

/**
* Checks if the settings does not exist and tries to set it from a given \a oldKey.
* \arg dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
* If \a deleteOldKey, the setting with the old key will be removed
* \param dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
* \param removeSettingAtKey if TRUE, the setting at the old key will be removed
* \returns TRUE if the key exists and the setting value could be copied
* \since QGIS 3.30
*/
bool copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList(), bool deleteOldKey = false ) const;
bool copyValueFromKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList(), bool removeSettingAtKey = false ) const;

/**
* Copies the settings to the given \a key
* \arg dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
* \param dynamicKeyPartList is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
* \since QGIS 3.30
*/
void copyValueToKey( const QString &key, const QStringList &dynamicKeyPartList = QStringList() ) const;
Expand Down Expand Up @@ -441,14 +441,14 @@ class QgsSettingsEntryByReference : public QgsSettingsEntryBase
/**
* Returns settings value.
*
* \arg dynamicKeyPart specifies the dynamic part of the settings key.
* \param dynamicKeyPart specifies the dynamic part of the settings key.
*/
T value( const QString &dynamicKeyPart = QString() ) const { return this->convertFromVariant( valueAsVariant( dynamicKeyPart ) );}

/**
* Returns settings value.
*
* \arg dynamicKeyPartList specifies the list of dynamic parts of the settings key.
* \param dynamicKeyPartList specifies the list of dynamic parts of the settings key.
*/
T value( const QStringList &dynamicKeyPartList ) const { return this->convertFromVariant( valueAsVariant( dynamicKeyPartList ) );}

Expand Down
18 changes: 14 additions & 4 deletions src/core/settings/qgssettingsentryimpl.cpp
Expand Up @@ -159,16 +159,14 @@ bool QgsSettingsEntryDouble::checkValue( double value ) const
if ( value < mMinValue )
{
QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is less than minimum value '%2'." )
.arg( QString::number( value ) )
.arg( QString::number( mMinValue ) ) );
.arg( QString::number( value ), QString::number( mMinValue ) ) );
return false;
}

if ( value > mMaxValue )
{
QgsDebugMsg( QObject::tr( "Can't set value for setting. Value '%1' is greather than maximum value '%2'." )
.arg( QString::number( value ) )
.arg( QString::number( mMaxValue ) ) );
.arg( QString::number( value ), QString::number( mMaxValue ) ) );
return false;
}

Expand Down Expand Up @@ -226,6 +224,17 @@ Qgis::SettingsType QgsSettingsEntryColor::settingsType() const
return Qgis::SettingsType::Color;
}

bool QgsSettingsEntryColor::checkValue( const QColor &value ) const
{
if ( !mAllowAlpha && value.alpha() != 255 )
{
QgsDebugMsg( QObject::tr( "Settings %1 doesn't allow transparency and the given color has transparency." ).arg( definitionKey() ) );
return false;
}

return true;
}

QVariantMap QgsSettingsEntryVariantMap::convertFromVariant( const QVariant &value ) const
{
return value.value<QVariantMap>();
Expand All @@ -235,3 +244,4 @@ Qgis::SettingsType QgsSettingsEntryVariantMap::settingsType() const
{
return Qgis::SettingsType::VariantMap;
}

0 comments on commit 46dec7e

Please sign in to comment.