Skip to content
Permalink
Browse files

[composer] Use feature requests to filter atlas features, rather

than fetching all features and then filtering while iterating.
  • Loading branch information
nyalldawson committed Aug 3, 2015
1 parent 69ac677 commit 8088e3541594b28790025ef0ae5e6487da675d1d
Showing with 6 additions and 16 deletions.
  1. +6 −16 src/core/composer/qgsatlascomposition.cpp
@@ -221,7 +221,7 @@ int QgsAtlasComposition::updateFeatures()
updateFilenameExpression();

// select all features with all attributes
QgsFeatureIterator fit = mCoverageLayer->getFeatures();
QgsFeatureRequest req;

QScopedPointer<QgsExpression> filterExpression;
if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
@@ -232,9 +232,14 @@ int QgsAtlasComposition::updateFeatures()
mFilterParserError = filterExpression->parserErrorString();
return 0;
}

//filter good to go
req.setFilterExpression( mFeatureFilter );
}
mFilterParserError = QString();

QgsFeatureIterator fit = mCoverageLayer->getFeatures( req );

QScopedPointer<QgsExpression> nameExpression;
if ( !mPageNameExpression.isEmpty() )
{
@@ -266,21 +271,6 @@ int QgsAtlasComposition::updateFeatures()
pageName = result.toString();
}

if ( !filterExpression.isNull() )
{
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
if ( filterExpression->hasEvalError() )
{
QgsMessageLog::logMessage( tr( "Atlas filter eval error: %1" ).arg( filterExpression->evalErrorString() ), tr( "Composer" ) );
}

// skip this feature if the filter evaluation if false
if ( !result.toBool() )
{
continue;
}
}

mFeatureIds.push_back( qMakePair( feat.id(), pageName ) );

if ( mSortFeatures && sortIdx != -1 )

0 comments on commit 8088e35

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