19 #include <QRegularExpression>
25 : mSettings( settings )
27 for (
const auto *setting : std::as_const( mSettings ) )
29 QString otherBaseKey = setting->definitionKey();
30 otherBaseKey = otherBaseKey.left( otherBaseKey.lastIndexOf( QLatin1Char(
'/' ) ) );
31 if ( mDefinitionBaseKey.isEmpty() )
33 mDefinitionBaseKey = otherBaseKey;
37 if ( mDefinitionBaseKey != otherBaseKey )
39 QgsDebugMsg(
"Settings do not share the same base definition key for this group. This will lead to unpredictable results." );
40 if ( fatalErrorIfInvalid )
50 QString key = mDefinitionBaseKey;
52 if ( dynamicKeyPartList.isEmpty() )
54 if ( hasDynamicKey() )
55 QgsDebugMsg( QStringLiteral(
"Settings group '%1' have a dynamic key but the dynamic key part was not provided" ).arg( key ) );
61 if ( !hasDynamicKey() )
63 QgsDebugMsg( QStringLiteral(
"Settings group '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( key ) );
67 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
69 key.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
78 QString key =
baseKey( dynamicKeyPartList );
80 const thread_local QRegularExpression regularExpression( QStringLiteral(
"^(\\/?(qgis\\/?)?)?$" ) );
81 if ( key.contains( regularExpression ) )
83 QgsDebugMsg( QStringLiteral(
"Preventing mass removal of settings at key %1" ).arg( key ) );
98 for (
const auto *setting : mSettings )
99 setting->remove( dynamicKeyPartList );
102 bool QgsSettingsEntryGroup::hasDynamicKey()
const
104 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
105 return mDefinitionBaseKey.contains( regularExpression );
116 QString completeKey = mKey;
117 if ( !mPluginName.isEmpty() )
119 if ( !completeKey.startsWith(
'/' ) )
120 completeKey.prepend(
'/' );
121 completeKey.prepend( mPluginName );
124 if ( dynamicKeyPartList.isEmpty() )
127 QgsDebugMsg( QStringLiteral(
"Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) );
135 QgsDebugMsg( QStringLiteral(
"Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) );
139 for (
int i = 0; i < dynamicKeyPartList.size(); i++ )
141 completeKey.replace( QStringLiteral(
"%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) );
157 const QRegularExpression regularExpression(
definitionKey().replace( QRegularExpression( QStringLiteral(
"%\\d+" ) ), QStringLiteral(
".*" ) ) );
158 const QRegularExpressionMatch regularExpressionMatch = regularExpression.match(
key );
159 return regularExpressionMatch.hasMatch();
169 const thread_local QRegularExpression regularExpression( QStringLiteral(
"%\\d+" ) );
170 return mKey.contains( regularExpression );
207 if (
exists( dynamicKeyPartList ) )
210 if ( value != currentValue )
222 QStringList dynamicKeyPartList;
223 if ( !dynamicKeyPart.isNull() )
224 dynamicKeyPartList.append( dynamicKeyPart );
225 return dynamicKeyPartList;
247 if ( useDefaultValueOverride )
266 return mDefaultValue;
283 return QgsSettings().
value( formerValuekey( dynamicKeyPartList ), defaultValueOverride );
286 QString QgsSettingsEntryBase::formerValuekey(
const QStringList &dynamicKeyPartList )
const
288 return key( dynamicKeyPartList ) + QStringLiteral(
"_formervalue" );