File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,9 @@ QgsExpressionContext QgsLayout::createExpressionContext() const
393393 QgsExpressionContext context = QgsExpressionContext ();
394394 context.appendScope ( QgsExpressionContextUtils::globalScope () );
395395 context.appendScope ( QgsExpressionContextUtils::projectScope ( mProject ) );
396+ if ( mReportContext ->layer () )
397+ context.appendScope ( QgsExpressionContextUtils::layerScope ( mReportContext ->layer () ) );
398+
396399 context.appendScope ( QgsExpressionContextUtils::layoutScope ( this ) );
397400 return context;
398401}
Original file line number Diff line number Diff line change 2323#include " qgsgeometry.h"
2424#include " qgsproject.h"
2525#include " qgslayout.h"
26+ #include " qgsexpressionutils.h"
2627#include < QObject>
2728#include " qgstest.h"
2829#include < QtTest/QSignalSpy>
@@ -145,6 +146,12 @@ void TestQgsLayoutContext::layer()
145146 context.setLayer ( nullptr );
146147 QVERIFY ( !context.layer () );
147148
149+ QgsLayout l ( QgsProject::instance () );
150+ l.reportContext ().setLayer ( layer );
151+ // test that expression context created for layout contains report context layer scope
152+ QgsExpressionContext expContext = l.createExpressionContext ();
153+ QCOMPARE ( QgsExpressionUtils::getVectorLayer ( expContext.variable ( " layer" ), nullptr ), layer );
154+
148155 delete layer;
149156}
150157
You can’t perform that action at this time.
0 commit comments