Skip to content

Commit

Permalink
[FEATURE] Expression variables for project CRS
Browse files Browse the repository at this point in the history
Adds @project_crs and @project_crs_definition variables
for retrieving the current project CRS
  • Loading branch information
nyalldawson committed Nov 22, 2016
1 parent 271e67e commit 188033a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -5712,6 +5712,8 @@ void QgsExpression::initVariableHelp()
gVariableHelpTexts.insert( QStringLiteral( "project_path" ), QCoreApplication::translate( "variable_help", "Full path (including file name) of current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_folder" ), QCoreApplication::translate( "variable_help", "Folder for current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_filename" ), QCoreApplication::translate( "variable_help", "Filename of current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_crs" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (eg 'EPSG:4326')." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_crs_definition" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (full definition)." ) );

//layer variables
gVariableHelpTexts.insert( QStringLiteral( "layer_name" ), QCoreApplication::translate( "variable_help", "Name of current layer." ) );
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -644,6 +644,9 @@ QgsExpressionContextScope* QgsExpressionContextUtils::projectScope()
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), project->fileInfo().filePath(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), project->fileInfo().dir().path(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true ) );
QgsCoordinateReferenceSystem projectCrs = project->crs();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true ) );

scope->addFunction( QStringLiteral( "project_color" ), new GetNamedProjectColor() );
return scope;
Expand Down

1 comment on commit 188033a

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 188033a Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking, would it make sense to also expose the canvas crs (thinking about @ahuarte47 work on multi canvas or maybe different maps in the print composer)

Please sign in to comment.