Skip to content

Commit

Permalink
filter features when exporting atlas image and filter is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and github-actions[bot] committed Aug 2, 2021
1 parent 8d8b247 commit 13515ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/analysis/processing/qgsalgorithmlayoutatlastoimage.cpp
Expand Up @@ -141,10 +141,13 @@ QVariantMap QgsLayoutAtlasToImageAlgorithm::processAlgorithm( const QVariantMap

expression = parameterAsString( parameters, QStringLiteral( "FILTER_EXPRESSION" ), context );
atlas->setFilterExpression( expression, error );
atlas->setFilterFeatures( !expression.isEmpty() && error.isEmpty() );

if ( !expression.isEmpty() && !error.isEmpty() )
{
throw QgsProcessingException( QObject::tr( "Error setting atlas filter expression" ) );
}

error.clear();

expression = parameterAsString( parameters, QStringLiteral( "SORTBY_EXPRESSION" ), context );
Expand Down
7 changes: 6 additions & 1 deletion src/core/layout/qgslayoutatlas.cpp
Expand Up @@ -297,7 +297,7 @@ int QgsLayoutAtlas::updateFeatures()

QgsFeatureIterator fit = mCoverageLayer->getFeatures( req );

std::unique_ptr<QgsExpression> nameExpression;
std::unique_ptr<QgsExpression> nameExpression;
if ( !mPageNameExpression.isEmpty() )
{
nameExpression = std::make_unique< QgsExpression >( mPageNameExpression );
Expand Down Expand Up @@ -384,12 +384,17 @@ bool QgsLayoutAtlas::beginRender()
//no matching features found
return false;
}
if ( !mFilterExpression.isEmpty() )
mCoverageLayer->setSubsetString( mFilterExpression );

return true;
}

bool QgsLayoutAtlas::endRender()
{
if ( mCoverageLayer && !mFilterExpression.isEmpty() )
mCoverageLayer->setSubsetString( QString() );

emit featureChanged( QgsFeature() );
emit renderEnded();
return true;
Expand Down

0 comments on commit 13515ec

Please sign in to comment.