Skip to content

Commit

Permalink
Add provider test for getting feature count with subset string set,
Browse files Browse the repository at this point in the history
fix memory provider invalid count when subset set
  • Loading branch information
nyalldawson committed Feb 4, 2016
1 parent 9c91dd2 commit 27f1637
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -289,7 +289,18 @@ QGis::WkbType QgsMemoryProvider::geometryType() const

long QgsMemoryProvider::featureCount() const
{
return mFeatures.count();
if ( mSubsetString.isEmpty() )
return mFeatures.count();

// subset string set, no alternative but testing each feature
QgsFeatureIterator fit = QgsFeatureIterator( new QgsMemoryFeatureIterator( new QgsMemoryFeatureSource( this ), true, QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) ) );
int count = 0;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
count++;
}
return count;
}

const QgsFields & QgsMemoryProvider::fields() const
Expand Down
7 changes: 7 additions & 0 deletions tests/src/python/providertestbase.py
Expand Up @@ -363,6 +363,13 @@ def testUnique(self):
def testFeatureCount(self):
assert self.provider.featureCount() == 5, 'Got {}'.format(self.provider.featureCount())

#Add a subset string and test feature count
subset = self.getSubsetString()
self.provider.setSubsetString(subset)
count = self.provider.featureCount()
self.provider.setSubsetString(None)
assert count == 3, 'Got {}'.format(count)

def testClosedIterators(self):
""" Test behaviour of closed iterators """

Expand Down

0 comments on commit 27f1637

Please sign in to comment.