Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 8088e35
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -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() )
Expand All @@ -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() )
{
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 8088e35

Please sign in to comment.