Skip to content
Permalink
Browse files

Rename QgsProject::variables to QgsProject::customVariables

  • Loading branch information
m-kuhn committed Dec 22, 2016
1 parent b07ecfa commit 79f32ab6b2101f57d0157c0b5f4ef5e6297f71a7
@@ -426,13 +426,13 @@ class QgsProject : QObject, QgsExpressionContextGenerator
* To get all available variables including generated ones
* use QgsExpressionContextUtils::projectScope() instead.
*/
QgsStringMap variables() const;
QgsStringMap customVariables() const;

/**
* A map of custom project variables.
* Be careful not to set generated variables.
*/
void setVariables( const QgsStringMap& variables );
void setCustomVariables( const QgsStringMap& customVariables );

//
// Functionality from QgsMapLayerRegistry
@@ -661,7 +661,7 @@ class QgsProject : QObject, QgsExpressionContextGenerator
/** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0
*/
void variablesChanged();
void customVariablesChanged();

/**
* Emitted whenever a new transaction group has been created or a
@@ -178,7 +178,7 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
connect( mVariableEditor, SIGNAL( scopeChanged() ), this, SLOT( variablesChanged() ) );
// listen out for variable edits
connect( QgsApplication::instance(), &QgsApplication::customVariablesChanged, this, &QgsComposerItemWidget::updateVariables );
connect( QgsProject::instance(), &QgsProject::variablesChanged, this, &QgsComposerItemWidget::updateVariables );
connect( QgsProject::instance(), &QgsProject::customVariablesChanged, this, &QgsComposerItemWidget::updateVariables );

if ( mItem->composition() )
connect( mItem->composition(), SIGNAL( variablesChanged() ), this, SLOT( updateVariables() ) );
@@ -53,7 +53,7 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
connect( mVariableEditor, SIGNAL( scopeChanged() ), this, SLOT( variablesChanged() ) );
// listen out for variable edits
connect( QgsApplication::instance(), &QgsApplication::customVariablesChanged, this, &QgsCompositionWidget::updateVariables );
connect( QgsProject::instance(), &QgsProject::variablesChanged, this, &QgsCompositionWidget::updateVariables );
connect( QgsProject::instance(), &QgsProject::customVariablesChanged, this, &QgsCompositionWidget::updateVariables );

if ( mComposition )
{
@@ -1190,7 +1190,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->relationManager()->setRelations( mRelationManagerDlg->relations() );

//save variables
QgsProject::instance()->setVariables( mVariableEditor->variablesInActiveScope() );
QgsProject::instance()->setCustomVariables( mVariableEditor->variablesInActiveScope() );

emit refresh();
}
@@ -589,7 +589,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::projectScope()

QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Project" ) );

const QgsStringMap vars = QgsProject::instance()->variables();
const QgsStringMap vars = QgsProject::instance()->customVariables();

QgsStringMap::const_iterator it = vars.constBegin();

@@ -615,16 +615,16 @@ void QgsExpressionContextUtils::setProjectVariable( const QString& name, const Q
{
QgsProject* project = QgsProject::instance();

QgsStringMap vars = project->variables();
QgsStringMap vars = project->customVariables();

vars.insert( name, value.toString() );

project->setVariables( vars );
project->setCustomVariables( vars );
}

void QgsExpressionContextUtils::setProjectVariables( const QgsStringMap& variables )
{
QgsProject::instance()->setVariables( variables );
QgsProject::instance()->setCustomVariables( variables );
}

QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLayer* layer )
@@ -448,7 +448,7 @@ void QgsProject::clear()
mAutoTransaction = false;
mEvaluateDefaultValues = false;
mDirty = false;
mVariables.clear();
mCustomVariables.clear();

mEmbeddedLayers.clear();
mRelationManager->clear();
@@ -925,19 +925,19 @@ bool QgsProject::read()
QStringList variableNames = readListEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableNames" ) );
QStringList variableValues = readListEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableValues" ) );

mVariables.clear();
mCustomVariables.clear();
if ( variableNames.length() == variableValues.length() )
{
for ( int i = 0; i < variableNames.length(); ++i )
{
mVariables.insert( variableNames.at( i ), variableValues.at( i ) );
mCustomVariables.insert( variableNames.at( i ), variableValues.at( i ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "Project Variables Invalid" ), tr( "The project contains invalid variable settings." ) );
}
emit variablesChanged();
emit customVariablesChanged();

// read the project: used by map canvas and legend
emit readProject( *doc );
@@ -994,14 +994,14 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
}
}

QgsStringMap QgsProject::variables() const
QgsStringMap QgsProject::customVariables() const
{
return mVariables;
return mCustomVariables;
}

void QgsProject::setVariables( const QgsStringMap& variables )
void QgsProject::setCustomVariables( const QgsStringMap& variables )
{
if ( variables == mVariables )
if ( variables == mCustomVariables )
return;

//write variable to project
@@ -1018,9 +1018,9 @@ void QgsProject::setVariables( const QgsStringMap& variables )
writeEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableNames" ), variableNames );
writeEntry( QStringLiteral( "Variables" ), QStringLiteral( "/variableValues" ), variableValues );

mVariables = variables;
mCustomVariables = variables;

emit variablesChanged();
emit customVariablesChanged();
}

QStringList QgsProject::avoidIntersectionsList() const
@@ -504,13 +504,13 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
* To get all available variables including generated ones
* use QgsExpressionContextUtils::projectScope() instead.
*/
QgsStringMap variables() const;
QgsStringMap customVariables() const;

/**
* A map of custom project variables.
* Be careful not to set generated variables.
*/
void setVariables( const QgsStringMap& variables );
void setCustomVariables( const QgsStringMap& customVariables );

//
// Functionality from QgsMapLayerRegistry
@@ -767,7 +767,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
/** Emitted whenever the expression variables stored in the project have been changed.
* @note added in QGIS 3.0
*/
void variablesChanged();
void customVariablesChanged();

/**
* Emitted whenever a new transaction group has been created or a
@@ -994,7 +994,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera

QScopedPointer<QgsMapThemeCollection> mMapThemeCollection;

QgsStringMap mVariables;
QgsStringMap mCustomVariables;

QFile mFile; // current physical project file
mutable QgsPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
@@ -131,10 +131,10 @@ void TestQgsProject::testProjectUnits()
void TestQgsProject::variablesChanged()
{
QgsProject* prj = new QgsProject;
QSignalSpy spyVariablesChanged( prj, SIGNAL( variablesChanged() ) );
QSignalSpy spyVariablesChanged( prj, &QgsProject::customVariablesChanged );
QgsStringMap vars;
vars.insert( QStringLiteral( "variable" ), QStringLiteral( "1" ) );
prj->setVariables( vars );
prj->setCustomVariables( vars );
QVERIFY( spyVariablesChanged.count() == 1 );
delete prj;
}

0 comments on commit 79f32ab

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