Skip to content

Commit

Permalink
Rename QgsProject::variables to QgsProject::customVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 22, 2016
1 parent b07ecfa commit 79f32ab
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions python/core/qgsproject.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposeritemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscompositionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 )
Expand Down
20 changes: 10 additions & 10 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void QgsProject::clear()
mAutoTransaction = false;
mEvaluateDefaultValues = false;
mDirty = false;
mVariables.clear();
mCustomVariables.clear();

mEmbeddedLayers.clear();
mRelationManager->clear();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 79f32ab

Please sign in to comment.