22#include <QRegularExpression>
28 : mSettings( settings )
30 for (
const auto *setting : std::as_const( mSettings ) )
32 QString otherBaseKey = setting->definitionKey();
33 otherBaseKey = otherBaseKey.left( otherBaseKey.lastIndexOf( QLatin1Char(
'/' ) ) );
34 if ( mDefinitionBaseKey.isEmpty() )
36 mDefinitionBaseKey = otherBaseKey;
40 if ( mDefinitionBaseKey != otherBaseKey )
42 QgsDebugMsg(
"Settings do not share the same base definition key for this group. This will lead to unpredictable results." );
43 if ( fatalErrorIfInvalid )
53 QString key = mDefinitionBaseKey;
55 if ( dynamicKeyPartList.isEmpty() )
57 if ( hasDynamicKey() )
58 QgsDebugMsg( QStringLiteral(
"Settings group '%1' have a dynamic key but the dynamic key part was not provided" ).arg( key ) );
64 if ( !hasDynamicKey() )
66 QgsDebugMsg( QStringLiteral(
"Settings group '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( key ) );
70 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
72 key.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
81 QString key =
baseKey( dynamicKeyPartList );
83 const thread_local QRegularExpression regularExpression( QStringLiteral(
"^(\\/?(qgis\\/?)?)?$" ) );
84 if ( key.contains( regularExpression ) )
86 QgsDebugMsg( QStringLiteral(
"Preventing mass removal of settings at key %1" ).arg( key ) );
101 for (
const auto *setting : mSettings )
102 setting->remove( dynamicKeyPartList );
105bool QgsSettingsEntryGroup::hasDynamicKey()
const
107 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
108 return mDefinitionBaseKey.contains( regularExpression );
static QStringList dynamicKeyPartToList(const QString &dynamicKeyPart)
Transforms a dynamic key part string to list.
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: