mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[FEATURE] Expression variables for project CRS
Adds @project_crs and @project_crs_definition variables for retrieving the current project CRS
This commit is contained in:
parent
271e67e37b
commit
188033a6af
@ -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." ) );
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user