Skip to content
Permalink
Browse files

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.
  • Loading branch information
NathanW2 committed Feb 22, 2018
1 parent 6a8e423 commit 5eb3e6b0994ee8d3a051ebb708f719da48a66108
Showing with 9 additions and 34 deletions.
  1. +9 −34 src/core/qgsapplication.cpp
@@ -1381,25 +1381,12 @@ QVariantMap QgsApplication::customVariables()
QVariantMap variables;

//check if settings contains any variables
if ( settings.contains( QStringLiteral( "/variables/values" ) ) )
settings.beginGroup( "variables" );
QStringList childKeys = settings.childKeys();
for ( QStringList::const_iterator it = childKeys.constBegin(); it != childKeys.constEnd(); ++it )
{
QList< QVariant > customVariableVariants = settings.value( QStringLiteral( "variables/values" ) ).toList();
QList< QVariant > customVariableNames = settings.value( QStringLiteral( "variables/names" ) ).toList();
int variableIndex = 0;
for ( QList< QVariant >::const_iterator it = customVariableVariants.constBegin();
it != customVariableVariants.constEnd(); ++it )
{
if ( variableIndex >= customVariableNames.length() )
{
break;
}

QVariant value = ( *it );
QString name = customVariableNames.at( variableIndex ).toString();

variables.insert( name, value );
variableIndex++;
}
QString name = *it;
variables.insert( name, settings.value( name ) );
}

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

QList< QVariant > customVariableValues;
QList< QVariant > customVariableNames;

QVariantMap::const_iterator it = variables.constBegin();
settings.beginGroup("variables");
settings.remove("");
for ( ; it != variables.constEnd(); ++it )
{
customVariableNames << it.key();
customVariableValues << it.value();
settings.setValue( it.key(), it.value() );
}

settings.setValue( QStringLiteral( "variables/names" ), customVariableNames );
settings.setValue( QStringLiteral( "variables/values" ), customVariableValues );

emit instance()->customVariablesChanged();
}

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

QList< QVariant > customVariableVariants = settings.value( QStringLiteral( "variables/values" ) ).toList();
QList< QVariant > customVariableNames = settings.value( QStringLiteral( "variables/names" ) ).toList();

customVariableVariants << value;
customVariableNames << name;

settings.setValue( QStringLiteral( "variables/names" ), customVariableNames );
settings.setValue( QStringLiteral( "variables/values" ), customVariableVariants );
settings.setValue( QStringLiteral( "variables/" ) + name, value );

emit instance()->customVariablesChanged();
}

0 comments on commit 5eb3e6b

Please sign in to comment.
You can’t perform that action at this time.