Skip to content

Commit

Permalink
Fix the atlas composer: use the stored number of features, instead of…
Browse files Browse the repository at this point in the history
… featureCount()
  • Loading branch information
Hugo Mercier committed Dec 11, 2012
1 parent 227401d commit 6e8bf84
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/core/composer/qgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
{
mCoverageLayer = layer;

if ( mCoverageLayer != 0 )
{
// update the number of features
QgsVectorDataProvider* provider = mCoverageLayer->dataProvider();
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)provider->featureCount() ) );
}
// update the number of features
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)mFeatureIds.size() ) );
}

void QgsAtlasComposition::beginRender()
Expand Down Expand Up @@ -93,6 +89,7 @@ void QgsAtlasComposition::beginRender()
// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
// We thus store the feature ids for future extraction
QgsFeature feat;
mFeatureIds.clear();
while ( provider->nextFeature( feat ) )
{
mFeatureIds.push_back( feat.id() );
Expand All @@ -115,7 +112,7 @@ void QgsAtlasComposition::beginRender()

// special columns for expressions
QgsExpression::setSpecialColumn( "$numpages", QVariant( mComposition->numPages() ) );
QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )provider->featureCount() ) );
QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
}

void QgsAtlasComposition::endRender()
Expand Down Expand Up @@ -147,11 +144,7 @@ void QgsAtlasComposition::endRender()

size_t QgsAtlasComposition::numFeatures() const
{
if ( mCoverageLayer )
{
return mCoverageLayer->dataProvider()->featureCount();
}
return 0;
return mFeatureIds.size();
}

void QgsAtlasComposition::prepareForFeature( size_t featureI )
Expand Down

0 comments on commit 6e8bf84

Please sign in to comment.