Skip to content

Commit 749bc02

Browse files
committed
Fix provider for min/max updates
1 parent 6f3be9f commit 749bc02

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tests/src/python/provider_python.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
"""QGIS test python layer provider.
2+
"""QGIS python layer provider test.
3+
4+
This module is a Python implementation of (a clone of) the core memory
5+
vector layer provider, to be used for test_provider_python.py
36
47
.. note:: This program is free software; you can redistribute it and/or modify
58
it under the terms of the GNU General Public License as published by
@@ -166,8 +169,6 @@ def __init__(self, provider):
166169
self._subset_expression = None
167170

168171
def getFeatures(self, request):
169-
# QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;
170-
# NOTE: this is the same as PyProvider.getFeatures
171172
return QgsFeatureIterator(PyFeatureIterator(self, request))
172173

173174

@@ -178,18 +179,15 @@ class PyProvider(QgsVectorDataProvider):
178179
@classmethod
179180
def providerKey(cls):
180181
"""Returns the memory provider key"""
181-
#static QString providerKey();
182182
return 'pythonprovider'
183183

184184
@classmethod
185185
def description(cls):
186186
"""Returns the memory provider description"""
187-
#static QString providerDescription();
188187
return 'Python Test Provider'
189188

190189
@classmethod
191190
def createProvider(cls, uri):
192-
#static QgsMemoryProvider *createProvider( const QString &uri );
193191
return PyProvider(uri)
194192

195193
# Implementation of functions from QgsVectorDataProvider
@@ -272,9 +270,10 @@ def addFeatures(self, flist, flags=None):
272270
self._spatialindex.insertFeature(_f)
273271

274272
if len(f_added):
273+
self.clearMinMaxCache()
275274
self.updateExtents()
276275

277-
return added, flist
276+
return added, f_added
278277

279278
def deleteFeatures(self, ids):
280279
if not ids:
@@ -287,6 +286,7 @@ def deleteFeatures(self, ids):
287286
del self._features[id]
288287
removed = True
289288
if removed:
289+
self.clearMinMaxCache()
290290
self.updateExtents()
291291
return removed
292292

@@ -300,6 +300,7 @@ def addAttributes(self, attrs):
300300
old_attrs = f.attributes()
301301
old_attrs.append(None)
302302
f.setAttributes(old_attrs)
303+
self.clearMinMaxCache()
303304
return True
304305
except Exception:
305306
return False
@@ -308,26 +309,27 @@ def renameAttributes(self, renamedAttributes):
308309
result = True
309310
for key, new_name in renamedAttributes:
310311
fieldIndex = key
311-
if fieldIndex < 0 or fieldIndex >= lself._fields.count():
312-
result = false
312+
if fieldIndex < 0 or fieldIndex >= self._fields.count():
313+
result = False
313314
continue
314315
if new_name in self._fields.indexFromName(new_name) >= 0:
315316
#field name already in use
316317
result = False
317318
continue
318319
self._fields[fieldIndex].setName(new_name)
319-
return True
320+
return result
320321

321322
def deleteAttributes(self, attributes):
322-
attrIdx = sorted(attributes.toList(), reverse=True)
323+
attrIdx = sorted(attributes, reverse=True)
323324

324325
# delete attributes one-by-one with decreasing index
325326
for idx in attrIdx:
326327
self._fields.remove(idx)
327-
for f in self._features:
328+
for f in self._features.values():
328329
attr = f.attributes()
329-
attr.remove(idx)
330+
del(attr[idx])
330331
f.setAttributes(attr)
332+
self.clearMinMaxCache()
331333
return True
332334

333335
def changeAttributeValues(self, attr_map):
@@ -338,6 +340,7 @@ def changeAttributeValues(self, attr_map):
338340
continue
339341
for k, v in attrs.items():
340342
f.setAttribute(k, v)
343+
self.clearMinMaxCache()
341344
return True
342345

343346
def changeGeometryValues(self, geometry_map):
@@ -373,7 +376,7 @@ def createSpatialIndex(self):
373376
return True
374377

375378
def capabilities(self):
376-
return QgsVectorDataProvider.AddFeatures | QgsVectorDataProvider.DeleteFeatures | QgsVectorDataProvider.ChangeGeometries | QgsVectorDataProvider.ChangeAttributeValues | QgsVectorDataProvider.AddAttributes | QgsVectorDataProvider.DeleteAttributes | QgsVectorDataProvider.RenameAttributes | QgsVectorDataProvider.SelectAtId | QgsVectorDataProvider. CircularGeometries
379+
return QgsVectorDataProvider.AddFeatures | QgsVectorDataProvider.DeleteFeatures | QgsVectorDataProvider.CreateSpatialIndex | QgsVectorDataProvider.ChangeGeometries | QgsVectorDataProvider.ChangeAttributeValues | QgsVectorDataProvider.AddAttributes | QgsVectorDataProvider.DeleteAttributes | QgsVectorDataProvider.RenameAttributes | QgsVectorDataProvider.SelectAtId | QgsVectorDataProvider. CircularGeometries
377380

378381
#/* Implementation of functions from QgsDataProvider */
379382

0 commit comments

Comments
 (0)