22#include <QRegularExpression>
32 : mSettings( settings )
34 for (
const auto *setting : std::as_const( mSettings ) )
36 QString otherBaseKey = setting->definitionKey();
37 otherBaseKey = otherBaseKey.left( otherBaseKey.lastIndexOf( QLatin1Char(
'/' ) ) );
38 if ( mDefinitionBaseKey.isEmpty() )
40 mDefinitionBaseKey = otherBaseKey;
44 if ( mDefinitionBaseKey != otherBaseKey )
46 QgsDebugError(
"Settings do not share the same base definition key for this group. This will lead to unpredictable results." );
47 if ( fatalErrorIfInvalid )
57 QString key = mDefinitionBaseKey;
59 if ( dynamicKeyPartList.isEmpty() )
61 if ( hasDynamicKey() )
62 QgsDebugError( QStringLiteral(
"Settings group '%1' have a dynamic key but the dynamic key part was not provided" ).arg( key ) );
68 if ( !hasDynamicKey() )
70 QgsDebugError( QStringLiteral(
"Settings group '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( key ) );
74 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
76 key.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
85 QString key =
baseKey( dynamicKeyPartList );
87 const thread_local QRegularExpression regularExpression( QStringLiteral(
"^(\\/?(qgis\\/?)?)?$" ) );
88 if ( key.contains( regularExpression ) )
90 QgsDebugError( QStringLiteral(
"Preventing mass removal of settings at key %1" ).arg( key ) );
105 for (
const auto *setting : mSettings )
106 setting->remove( dynamicKeyPartList );
109bool QgsSettingsEntryGroup::hasDynamicKey()
const
111 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
112 return mDefinitionBaseKey.contains( regularExpression );
static QStringList dynamicKeyPartToList(const QString &dynamicKeyPart)
Transforms a dynamic key part string to list.
Creates a group of setting which have a common definition of base key.
void removeAllChildrenSettings(const QString &dynamicKeyPart=QString()) const
Removes all the settings from this group The dynamicKeyPart argument specifies the dynamic part of th...
const QList< const QgsSettingsEntryBase * > settings() const
Returns all the settings.
void removeAllSettingsAtBaseKey(const QStringList &dynamicKeyPartList=QStringList()) const
Removes all the settings at the base key for the given dynamicKeyPartList This means it might remove ...
QgsSettingsEntryGroup(QList< const QgsSettingsEntryBase * > settings)
Constructor.
QString baseKey(const QStringList &dynamicKeyPartList=QStringList()) const
Returns the base key for the given dynamicKeyPartList.
This class is a composition of two QSettings instances:
#define QgsDebugError(str)