Skip to content

Commit

Permalink
Make QgsVectorDataProvider::fillMinMaxCache() handle LongLong
Browse files Browse the repository at this point in the history
The code currently fallbacks to dealing with LongLong fields as
strings, which breaks the ProviderTestCase testMinValue() and
testMaxValue() tests, if we change the definition of the tests
of the memory provider to use a int8 field for the cnt field.

======================================================================
FAIL: testMaxValue (__main__.TestPyQgsMemoryProviderIndexed)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/even/qgis-git/Quantum-GIS.clean/tests/src/python/providertestbase.py", line 349, in testMaxValue
    self.assertEqual(self.provider.maximumValue(1), 400)
AssertionError: u'400' != 400

======================================================================
FAIL: testMinValue (__main__.TestPyQgsMemoryProviderIndexed)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/even/qgis-git/Quantum-GIS.clean/tests/src/python/providertestbase.py", line 345, in testMinValue
    self.assertEqual(self.provider.minimumValue(1), -200)
AssertionError: u'-200' != -200
  • Loading branch information
rouault authored and m-kuhn committed Mar 27, 2016
1 parent 5dc9551 commit 332552e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cfloat> // for DBL_MAX
#include <climits>
#include <limits>

#include "qgsvectordataprovider.h"
#include "qgsfeature.h"
Expand Down Expand Up @@ -402,6 +403,11 @@ void QgsVectorDataProvider::fillMinMaxCache()
mCacheMinValues[i] = QVariant( INT_MAX );
mCacheMaxValues[i] = QVariant( INT_MIN );
}
else if ( flds[i].type() == QVariant::LongLong )
{
mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::min() );
}
else if ( flds[i].type() == QVariant::Double )
{
mCacheMinValues[i] = QVariant( DBL_MAX );
Expand Down Expand Up @@ -436,6 +442,14 @@ void QgsVectorDataProvider::fillMinMaxCache()
if ( value > mCacheMaxValues[*it].toInt() )
mCacheMaxValues[*it] = value;
}
else if ( flds[*it].type() == QVariant::LongLong )
{
qlonglong value = varValue.toLongLong();
if ( value < mCacheMinValues[*it].toLongLong() )
mCacheMinValues[*it] = value;
if ( value > mCacheMaxValues[*it].toLongLong() )
mCacheMaxValues[*it] = value;
}
else if ( flds[*it].type() == QVariant::Double )
{
double value = varValue.toDouble();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class TestPyQgsMemoryProviderIndexed(unittest.TestCase, ProviderTestCase):
def setUpClass(cls):
"""Run before all tests"""
# Create test layer
cls.vl = QgsVectorLayer(u'Point?crs=epsg:4326&index=yes&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
cls.vl = QgsVectorLayer(u'Point?crs=epsg:4326&index=yes&field=pk:integer&field=cnt:int8&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
u'test', u'memory')
assert (cls.vl.isValid())
cls.provider = cls.vl.dataProvider()
Expand Down

0 comments on commit 332552e

Please sign in to comment.