Skip to content

Commit 83815ba

Browse files
authored
Merge pull request #4598 from Gustry/atlas_expressions
[needs-docs] add layerid and layername to atlas expressions
2 parents ba079d8 + 0a661d5 commit 83815ba

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎src/core/expression/qgsexpression.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ void QgsExpression::initVariableHelp()
638638
sVariableHelpTexts.insert( QStringLiteral( "layout_dpi" ), QCoreApplication::translate( "variable_help", "Composition resolution (DPI)." ) );
639639

640640
//atlas variables
641+
sVariableHelpTexts.insert( QStringLiteral( "atlas_layerid" ), QCoreApplication::translate( "variable_help", "Current atlas coverage layer ID." ) );
642+
sVariableHelpTexts.insert( QStringLiteral( "atlas_layername" ), QCoreApplication::translate( "variable_help", "Current atlas coverage layer name." ) );
641643
sVariableHelpTexts.insert( QStringLiteral( "atlas_totalfeatures" ), QCoreApplication::translate( "variable_help", "Total number of features in atlas." ) );
642644
sVariableHelpTexts.insert( QStringLiteral( "atlas_featurenumber" ), QCoreApplication::translate( "variable_help", "Current atlas feature number." ) );
643645
sVariableHelpTexts.insert( QStringLiteral( "atlas_filename" ), QCoreApplication::translate( "variable_help", "Current atlas file name." ) );

‎src/core/qgsexpressioncontext.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,8 @@ QgsExpressionContextScope *QgsExpressionContextUtils::atlasScope( const QgsAtlas
987987
if ( atlas->enabled() && atlas->coverageLayer() )
988988
{
989989
scope->setFields( atlas->coverageLayer()->fields() );
990+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layerid" ), atlas->coverageLayer()->id(), true ) );
991+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layername" ), atlas->coverageLayer()->name(), true ) );
990992
}
991993

992994
if ( atlas->enabled() )

0 commit comments

Comments
 (0)