Skip to content

Commit

Permalink
Fix division by 0
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 11, 2017
1 parent 1f04188 commit a6800e9
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions src/core/qgsvectorlayerfeaturecounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,55 @@ bool QgsVectorLayerFeatureCounter::run()
mSymbolFeatureCountMap.insert( symbolIt->first, 0 );
}

int featuresCounted = 0;
// If there are no features to be counted, we can spare us the trouble
if ( mFeatureCount > 0 )
{
int featuresCounted = 0;

// Renderer (rule based) may depend on context scale, with scale is ignored if 0
QgsRenderContext renderContext;
renderContext.setRendererScale( 0 );
renderContext.expressionContext().appendScopes( mExpressionContextScopes );
// Renderer (rule based) may depend on context scale, with scale is ignored if 0
QgsRenderContext renderContext;
renderContext.setRendererScale( 0 );
renderContext.expressionContext().appendScopes( mExpressionContextScopes );

QgsFeatureRequest request;
if ( !mRenderer->filterNeedsGeometry() )
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( mRenderer->usedAttributes( renderContext ), mSource->fields() );
QgsFeatureIterator fit = mSource->getFeatures( request );
QgsFeatureRequest request;
if ( !mRenderer->filterNeedsGeometry() )
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( mRenderer->usedAttributes( renderContext ), mSource->fields() );
QgsFeatureIterator fit = mSource->getFeatures( request );

// TODO: replace QgsInterruptionChecker with QgsFeedback
// fit.setInterruptionChecker( mFeedback );
// TODO: replace QgsInterruptionChecker with QgsFeedback
// fit.setInterruptionChecker( mFeedback );

mRenderer->startRender( renderContext, mSource->fields() );
mRenderer->startRender( renderContext, mSource->fields() );

double progress = 0;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
renderContext.expressionContext().setFeature( f );
QSet<QString> featureKeyList = mRenderer->legendKeysForFeature( f, renderContext );
Q_FOREACH ( const QString &key, featureKeyList )
double progress = 0;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
mSymbolFeatureCountMap[key] += 1;
}
++featuresCounted;
renderContext.expressionContext().setFeature( f );
QSet<QString> featureKeyList = mRenderer->legendKeysForFeature( f, renderContext );
Q_FOREACH ( const QString &key, featureKeyList )
{
mSymbolFeatureCountMap[key] += 1;
}
++featuresCounted;

double p = ( featuresCounted / mFeatureCount ) * 100;
if ( p - progress > 1 )
{
progress = p;
setProgress( progress );
}
double p = ( featuresCounted / mFeatureCount ) * 100;
if ( p - progress > 1 )
{
progress = p;
setProgress( progress );
}

if ( isCanceled() )
{
mRenderer->stopRender( renderContext );
return false;
if ( isCanceled() )
{
mRenderer->stopRender( renderContext );
return false;
}
}
mRenderer->stopRender( renderContext );
}
mRenderer->stopRender( renderContext );

setProgress( 100 );

emit symbolsCounted();
Expand All @@ -70,5 +75,5 @@ bool QgsVectorLayerFeatureCounter::run()

QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
{
return mSymbolFeatureCountMap;
return mSymbolFeatureCountMap;
}

0 comments on commit a6800e9

Please sign in to comment.