mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
parent
3e0766b628
commit
d11f7f5583
@ -40,6 +40,9 @@ geometry and a list of field/values attributes.
|
||||
QgsAttributes attributes = sipCpp->attributes();
|
||||
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
|
||||
sipRes = PyObject_GetIter( attrs );
|
||||
// PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
|
||||
// so that the garbage collector will delete attrs when the iterator is deleted
|
||||
Py_DECREF( attrs );
|
||||
%End
|
||||
|
||||
|
||||
|
@ -40,6 +40,9 @@ geometry and a list of field/values attributes.
|
||||
QgsAttributes attributes = sipCpp->attributes();
|
||||
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
|
||||
sipRes = PyObject_GetIter( attrs );
|
||||
// PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
|
||||
// so that the garbage collector will delete attrs when the iterator is deleted
|
||||
Py_DECREF( attrs );
|
||||
%End
|
||||
|
||||
SIP_PYOBJECT __getitem__( int key ) /HoldGIL/;
|
||||
|
@ -76,6 +76,9 @@ class CORE_EXPORT QgsFeature
|
||||
QgsAttributes attributes = sipCpp->attributes();
|
||||
PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None );
|
||||
sipRes = PyObject_GetIter( attrs );
|
||||
// PyObject_GetIter has added a ref to attrs - we need to decrement the ref from sipConvertFromType,
|
||||
// so that the garbage collector will delete attrs when the iterator is deleted
|
||||
Py_DECREF( attrs );
|
||||
% End
|
||||
#endif
|
||||
|
||||
|
@ -320,6 +320,39 @@ class TestQgsVectorLayer(QgisTestCase, FeatureSourceTestCase):
|
||||
myCount = myLayer.featureCount()
|
||||
self.assertEqual(myCount, 6)
|
||||
|
||||
def test_attribute_iteration(self):
|
||||
layer = QgsVectorLayer(
|
||||
self.get_test_data_path("lines.shp").as_posix(), "Lines", "ogr"
|
||||
)
|
||||
self.assertTrue(layer.isValid())
|
||||
all_attrs = [
|
||||
[attr for attr in feat.attributes()] for feat in layer.getFeatures()
|
||||
]
|
||||
self.assertCountEqual(
|
||||
all_attrs,
|
||||
[
|
||||
["Highway", 1.0],
|
||||
["Highway", 1.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
],
|
||||
)
|
||||
|
||||
all_attrs = [[attr for attr in feat] for feat in layer.getFeatures()]
|
||||
self.assertCountEqual(
|
||||
all_attrs,
|
||||
[
|
||||
["Highway", 1.0],
|
||||
["Highway", 1.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
["Arterial", 2.0],
|
||||
],
|
||||
)
|
||||
|
||||
# undo stack
|
||||
def testUndoStack(self):
|
||||
layer = createLayerWithOnePoint()
|
||||
|
Loading…
x
Reference in New Issue
Block a user