Skip to content
Permalink
Browse files

Fix some providers did not respect layer's subset when calculating

min/max/uniqueValues

Providers included delimited text, memory, virtual layer, and WFS

Add unit test to provider test

(cherry-picked from 16d8da3)
  • Loading branch information
nyalldawson committed Apr 15, 2016
1 parent 46860cb commit e8dc831909b13171950b18109ca0bae02c5c1638
@@ -1078,6 +1078,7 @@ bool QgsDelimitedTextProvider::setSubsetString( const QString& subset, bool upda
}
}

mCacheMinMaxDirty = true;
emit dataChanged();
return valid;
}
@@ -481,6 +481,7 @@ bool QgsMemoryProvider::setSubsetString( const QString& theSQL, bool updateFeatu
}

mSubsetString = theSQL;
mCacheMinMaxDirty = true;

emit dataChanged();
return true;
@@ -493,6 +493,7 @@ QString QgsVirtualLayerProvider::subsetString()
bool QgsVirtualLayerProvider::setSubsetString( const QString& subset, bool updateFeatureCount )
{
mSubset = subset;
mCacheMinMaxDirty = true;
if ( updateFeatureCount )
updateStatistics();
return true;
@@ -165,6 +165,10 @@ def getSubsetString(self):
"""Individual providers may need to override this depending on their subset string formats"""
return '"cnt" > 100 and "cnt" < 410'

def getSubsetString2(self):
"""Individual providers may need to override this depending on their subset string formats"""
return '"cnt" > 100 and "cnt" < 400'

def testOrderByUncompiled(self):
try:
self.disableCompiler()
@@ -349,10 +353,22 @@ def testMinValue(self):
self.assertEqual(self.provider.minimumValue(1), -200)
self.assertEqual(self.provider.minimumValue(2), 'Apple')

subset = self.getSubsetString()
self.provider.setSubsetString(subset)
min_value = self.provider.minimumValue(1)
self.provider.setSubsetString(None)
self.assertEqual(min_value, 200)

def testMaxValue(self):
self.assertEqual(self.provider.maximumValue(1), 400)
self.assertEqual(self.provider.maximumValue(2), 'Pear')

subset = self.getSubsetString2()
self.provider.setSubsetString(subset)
max_value = self.provider.maximumValue(1)
self.provider.setSubsetString(None)
self.assertEqual(max_value, 300)

def testExtent(self):
reference = QgsGeometry.fromRect(
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
@@ -364,6 +380,12 @@ def testUnique(self):
self.assertEqual(set(self.provider.uniqueValues(1)), set([-200, 100, 200, 300, 400]))
assert set([u'Apple', u'Honey', u'Orange', u'Pear', NULL]) == set(self.provider.uniqueValues(2)), 'Got {}'.format(set(self.provider.uniqueValues(2)))

subset = self.getSubsetString2()
self.provider.setSubsetString(subset)
values = self.provider.uniqueValues(1)
self.provider.setSubsetString(None)
self.assertEqual(set(values), set([200, 300]))

def testFeatureCount(self):
assert self.provider.featureCount() == 5, 'Got {}'.format(self.provider.featureCount())

0 comments on commit e8dc831

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