Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
readd lines lost during merge
  • Loading branch information
domi4484 committed Aug 17, 2021
1 parent d94bcbc commit d6df531
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/core/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -527,7 +527,7 @@ bool QgsMemoryProvider::deleteFeatures( const QgsFeatureIds &id )

bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
{
for ( QList<QgsField>::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
for ( QgsField field : attributes )
{
if ( !supportedType( field ) )
continue;
Expand All @@ -538,6 +538,12 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
const QList<QgsVectorDataProvider::NativeType> nativeTypesList( nativeTypes() );
for ( const NativeType &nativeType : nativeTypesList )
{
if ( nativeType.mTypeName.toLower() == field.typeName().toLower() )
{
isNativeTypeName = true;
break;
}

if ( nativeType.mType == field.type()
&& nativeTypeCandidate.mType == QVariant::Invalid )
nativeTypeCandidate = nativeType;
Expand All @@ -555,7 +561,7 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
}

// add new field as a last one
mFields.append( *it );
mFields.append( field );

for ( QgsFeatureMap::iterator fit = mFeatures.begin(); fit != mFeatures.end(); ++fit )
{
Expand Down
14 changes: 1 addition & 13 deletions tests/src/python/test_provider_memory.py
Expand Up @@ -841,10 +841,7 @@ def testAddAttributes(self):
QgsField("short", QVariant.Int, "int2"),
QgsField("lessshort", QVariant.Int, "int4"),
QgsField("numericfield", QVariant.Double, "numeric"),
QgsField("decimalfield", QVariant.Double, "decimal"),
QgsField("stringlistfield", QVariant.StringList, "stringlist"),
QgsField("integerlistfield", QVariant.List, "integerlist"),
QgsField("doublelistfield", QVariant.List, "doublelist")])
QgsField("decimalfield", QVariant.Double, "decimal")])

self.assertEqual(pr.fields()[0].typeName(), "string")
self.assertEqual(pr.fields()[1].typeName(), "integer")
Expand All @@ -855,9 +852,6 @@ def testAddAttributes(self):
self.assertEqual(pr.fields()[6].typeName(), "int4")
self.assertEqual(pr.fields()[7].typeName(), "numeric")
self.assertEqual(pr.fields()[8].typeName(), "decimal")
self.assertEqual(pr.fields()[9].typeName(), "stringlist")
self.assertEqual(pr.fields()[10].typeName(), "integerlist")
self.assertEqual(pr.fields()[11].typeName(), "doublelist")

vl2 = vl.clone()

Expand All @@ -870,9 +864,6 @@ def testAddAttributes(self):
self.assertEqual(pr.fields()[6].name(), vl2.fields()[6].name())
self.assertEqual(pr.fields()[7].name(), vl2.fields()[7].name())
self.assertEqual(pr.fields()[8].name(), vl2.fields()[8].name())
self.assertEqual(pr.fields()[9].name(), vl2.fields()[9].name())
self.assertEqual(pr.fields()[10].name(), vl2.fields()[10].name())
self.assertEqual(pr.fields()[11].name(), vl2.fields()[11].name())

self.assertEqual(pr.fields()[0].typeName(), vl2.fields()[0].typeName())
self.assertEqual(pr.fields()[1].typeName(), vl2.fields()[1].typeName())
Expand All @@ -883,9 +874,6 @@ def testAddAttributes(self):
self.assertEqual(pr.fields()[6].typeName(), vl2.fields()[6].typeName())
self.assertEqual(pr.fields()[7].typeName(), vl2.fields()[7].typeName())
self.assertEqual(pr.fields()[8].typeName(), vl2.fields()[8].typeName())
self.assertEqual(pr.fields()[9].typeName(), vl2.fields()[9].typeName())
self.assertEqual(pr.fields()[10].typeName(), vl2.fields()[10].typeName())
self.assertEqual(pr.fields()[11].typeName(), vl2.fields()[11].typeName())


class TestPyQgsMemoryProviderIndexed(unittest.TestCase, ProviderTestCase):
Expand Down

0 comments on commit d6df531

Please sign in to comment.