Skip to content

Commit c058a68

Browse files
committed
[layouts] Fix incorrect filename for atlas features when using
@atlas_feature Fixes #19552 (cherry-picked from 6920102)
1 parent fc61803 commit c058a68

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/core/layout/qgslayoutatlas.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ bool QgsLayoutAtlas::prepareForFeature( const int featureI )
524524
if ( !mCoverageLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureIds[ featureI ].first ) ).nextFeature( mCurrentFeature ) )
525525
return false;
526526

527+
mLayout->reportContext().blockSignals( true ); // setFeature emits changed, we don't want 2 signals
528+
mLayout->reportContext().setLayer( mCoverageLayer.get() );
529+
mLayout->reportContext().blockSignals( false );
530+
mLayout->reportContext().setFeature( mCurrentFeature );
531+
532+
// must come after we've set the report context feature, or the expression context will have an outdated atlas feature
527533
QgsExpressionContext expressionContext = createExpressionContext();
528534

529535
// generate filename for current feature
@@ -533,11 +539,6 @@ bool QgsLayoutAtlas::prepareForFeature( const int featureI )
533539
return false;
534540
}
535541

536-
mLayout->reportContext().blockSignals( true ); // setFeature emits changed, we don't want 2 signals
537-
mLayout->reportContext().setLayer( mCoverageLayer.get() );
538-
mLayout->reportContext().blockSignals( false );
539-
mLayout->reportContext().setFeature( mCurrentFeature );
540-
541542
emit featureChanged( mCurrentFeature );
542543
emit messagePushed( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );
543544

tests/src/python/test_qgslayoutatlas.py

+13
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,19 @@ def filename_test(self):
368368
self.assertEqual(self.atlas.currentFilename(), expected)
369369
self.atlas.endRender()
370370

371+
# using feature attribute (refs https://issues.qgis.org/issues/19552)
372+
373+
self.atlas.setFilenameExpression("'output_' || attribute(@atlas_feature,'NAME_1')")
374+
expected = ['output_Basse-Normandie',
375+
'output_Bretagne',
376+
'output_Pays de la Loire',
377+
'output_Centre']
378+
self.atlas.beginRender()
379+
for i in range(0, self.atlas.count()):
380+
self.atlas.seekTo(i)
381+
self.assertEqual(self.atlas.currentFilename(), expected[i])
382+
self.atlas.endRender()
383+
371384
def autoscale_render_test(self):
372385
self.atlas_map.setExtent(
373386
QgsRectangle(332719.06221504929, 6765214.5887386119, 560957.85090677091, 6993453.3774303338))

0 commit comments

Comments
 (0)