Skip to content

Commit 5eb3e6b

Browse files
authored
Save variables are key value in settings (#6411)
* Save variables are key value in settings This allows variables to be set in qgis_global_settings.ini correctly. This used to be a list of names and then a list of values making it impossible to set and override.
1 parent 6a8e423 commit 5eb3e6b

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

src/core/qgsapplication.cpp

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,25 +1381,12 @@ QVariantMap QgsApplication::customVariables()
13811381
QVariantMap variables;
13821382

13831383
//check if settings contains any variables
1384-
if ( settings.contains( QStringLiteral( "/variables/values" ) ) )
1384+
settings.beginGroup( "variables" );
1385+
QStringList childKeys = settings.childKeys();
1386+
for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
13851387
{
1386-
QList< QVariant > customVariableVariants = settings.value( QStringLiteral( "variables/values" ) ).toList();
1387-
QList< QVariant > customVariableNames = settings.value( QStringLiteral( "variables/names" ) ).toList();
1388-
int variableIndex = 0;
1389-
for ( QList< QVariant >::const_iterator it = customVariableVariants.constBegin();
1390-
it != customVariableVariants.constEnd(); ++it )
1391-
{
1392-
if ( variableIndex >= customVariableNames.length() )
1393-
{
1394-
break;
1395-
}
1396-
1397-
QVariant value = ( *it );
1398-
QString name = customVariableNames.at( variableIndex ).toString();
1399-
1400-
variables.insert( name, value );
1401-
variableIndex++;
1402-
}
1388+
QString name = *it;
1389+
variables.insert( name, settings.value( name ) );
14031390
}
14041391

14051392
return variables;
@@ -1409,19 +1396,14 @@ void QgsApplication::setCustomVariables( const QVariantMap &variables )
14091396
{
14101397
QgsSettings settings;
14111398

1412-
QList< QVariant > customVariableValues;
1413-
QList< QVariant > customVariableNames;
1414-
14151399
QVariantMap::const_iterator it = variables.constBegin();
1400+
settings.beginGroup("variables");
1401+
settings.remove("");
14161402
for ( ; it != variables.constEnd(); ++it )
14171403
{
1418-
customVariableNames << it.key();
1419-
customVariableValues << it.value();
1404+
settings.setValue( it.key(), it.value() );
14201405
}
14211406

1422-
settings.setValue( QStringLiteral( "variables/names" ), customVariableNames );
1423-
settings.setValue( QStringLiteral( "variables/values" ), customVariableValues );
1424-
14251407
emit instance()->customVariablesChanged();
14261408
}
14271409

@@ -1430,14 +1412,7 @@ void QgsApplication::setCustomVariable( const QString &name, const QVariant &val
14301412
// save variable to settings
14311413
QgsSettings settings;
14321414

1433-
QList< QVariant > customVariableVariants = settings.value( QStringLiteral( "variables/values" ) ).toList();
1434-
QList< QVariant > customVariableNames = settings.value( QStringLiteral( "variables/names" ) ).toList();
1435-
1436-
customVariableVariants << value;
1437-
customVariableNames << name;
1438-
1439-
settings.setValue( QStringLiteral( "variables/names" ), customVariableNames );
1440-
settings.setValue( QStringLiteral( "variables/values" ), customVariableVariants );
1415+
settings.setValue( QStringLiteral( "variables/" ) + name, value );
14411416

14421417
emit instance()->customVariablesChanged();
14431418
}

0 commit comments

Comments
 (0)