Skip to content
Permalink
Browse files

[layout expressions] add Y page offset expression

this is useful for dynamically position items
relative to pages in multi-pages layouts
  • Loading branch information
olivierdalang authored and nyalldawson committed Aug 21, 2020
1 parent a462a17 commit 6ac8f6158b1a1b513db4584cb20f1ea8fd3dec27
Showing with 10 additions and 0 deletions.
  1. +1 −0 src/core/expression/qgsexpression.cpp
  2. +9 −0 src/core/expression/qgsexpressioncontextutils.cpp
@@ -736,6 +736,7 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts()->insert( QStringLiteral( "layout_page" ), QCoreApplication::translate( "variable_help", "Current page number in composition." ) );
sVariableHelpTexts()->insert( QStringLiteral( "layout_pageheight" ), QCoreApplication::translate( "variable_help", "Composition page height in mm." ) );
sVariableHelpTexts()->insert( QStringLiteral( "layout_pagewidth" ), QCoreApplication::translate( "variable_help", "Composition page width in mm." ) );
sVariableHelpTexts()->insert( QStringLiteral( "layout_pageoffsets" ), QCoreApplication::translate( "variable_help", "Array of Y coordinate of the top of each page." ) );
sVariableHelpTexts()->insert( QStringLiteral( "layout_dpi" ), QCoreApplication::translate( "variable_help", "Composition resolution (DPI)." ) );

//atlas variables
@@ -510,6 +510,15 @@ QgsExpressionContextScope *QgsExpressionContextUtils::layoutScope( const QgsLayo
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pageheight" ), s.height(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pagewidth" ), s.width(), true ) );
}

QVariantList offsets;
for ( int i = 0; i < layout->pageCollection()->pageCount(); i++ )
{
QPointF p = layout->pageCollection()->pagePositionToLayoutPosition( i, QgsLayoutPoint( 0, 0 ) );
offsets << p.y();
}
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pageoffsets" ), offsets, true ) );

scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_dpi" ), layout->renderContext().dpi(), true ) );

scope->addFunction( QStringLiteral( "item_variables" ), new GetLayoutItemVariables( layout ) );

0 comments on commit 6ac8f61

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