Skip to content

Commit

Permalink
[layouts] Fix incorrect filename for atlas features when using
Browse files Browse the repository at this point in the history
@atlas_feature

Fixes #19552

(cherry-picked from 6920102)
  • Loading branch information
nyalldawson committed Aug 14, 2018
1 parent fc61803 commit c058a68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/layout/qgslayoutatlas.cpp
Expand Up @@ -524,6 +524,12 @@ bool QgsLayoutAtlas::prepareForFeature( const int featureI )
if ( !mCoverageLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureIds[ featureI ].first ) ).nextFeature( mCurrentFeature ) )
return false;

mLayout->reportContext().blockSignals( true ); // setFeature emits changed, we don't want 2 signals
mLayout->reportContext().setLayer( mCoverageLayer.get() );
mLayout->reportContext().blockSignals( false );
mLayout->reportContext().setFeature( mCurrentFeature );

// must come after we've set the report context feature, or the expression context will have an outdated atlas feature
QgsExpressionContext expressionContext = createExpressionContext();

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

mLayout->reportContext().blockSignals( true ); // setFeature emits changed, we don't want 2 signals
mLayout->reportContext().setLayer( mCoverageLayer.get() );
mLayout->reportContext().blockSignals( false );
mLayout->reportContext().setFeature( mCurrentFeature );

emit featureChanged( mCurrentFeature );
emit messagePushed( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );

Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_qgslayoutatlas.py
Expand Up @@ -368,6 +368,19 @@ def filename_test(self):
self.assertEqual(self.atlas.currentFilename(), expected)
self.atlas.endRender()

# using feature attribute (refs https://issues.qgis.org/issues/19552)

self.atlas.setFilenameExpression("'output_' || attribute(@atlas_feature,'NAME_1')")
expected = ['output_Basse-Normandie',
'output_Bretagne',
'output_Pays de la Loire',
'output_Centre']
self.atlas.beginRender()
for i in range(0, self.atlas.count()):
self.atlas.seekTo(i)
self.assertEqual(self.atlas.currentFilename(), expected[i])
self.atlas.endRender()

def autoscale_render_test(self):
self.atlas_map.setExtent(
QgsRectangle(332719.06221504929, 6765214.5887386119, 560957.85090677091, 6993453.3774303338))
Expand Down

0 comments on commit c058a68

Please sign in to comment.