Class: QgsVectorLayerEditBuffer¶
Stores queued vector layer edit operations prior to committing changes to the layer’s data provider.
Class Hierarchy¶
Base classes¶
Subclasses¶
An edit buffer which directly passes commands through, used when a layer is within a transaction. |
Methods
Returns a list of added attributes fields which are not committed. |
|
Returns a map of new features which are not committed. |
|
Returns a list of the features IDs for all newly added or edited features in the buffer. |
|
Returns a map of features with changed attributes values which are not committed. |
|
Returns a map of features with changed geometries which are not committed. |
|
Returns a list of deleted attributes fields which are not committed. |
|
Returns a list of deleted feature IDs which are not committed. |
|
Returns the parent edit buffer group for this edit buffer, or None if not part of a group. |
|
Update added and changed features after addition of an attribute |
|
Update added and changed features after removal of an attribute |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Set the parent edit buffer group for this edit buffer. |
|
Updates an index in an attribute map to a new value (for updates of changed attributes) |
|
Update feature with uncommitted attribute updates |
|
Update feature with uncommitted geometry updates |
|
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsVectorLayerEditBuffer. See the FAQ for more details.
Adds an attribute field (but does not commit it) returns |
|
Adds a feature |
|
Insert a copy of the given features into the layer (but does not commit it) |
|
Changed an attribute value (but does not commit it) |
|
Changes values of attributes (but does not commit it). |
|
Change feature's geometry |
|
Attempts to commit any changes to disk. |
|
Deletes an attribute field (but does not commit it) |
|
Delete a feature from the layer (but does not commit it) |
|
Deletes a set of features from the layer (but does not commit it) |
|
Returns |
|
Renames an attribute field (but does not commit it) |
|
Stop editing and discard the edits |
Signals
Emitted when an attribute was added to the buffer. |
|
Emitted when an attribute was deleted from the buffer. |
|
Emitted when an attribute has been renamed |
|
Emitted when a feature's attribute value has been changed. |
|
Emitted after feature attribute value changes have been committed to the layer. |
|
Emitted after attribute addition has been committed to the layer. |
|
Emitted after attribute deletion has been committed to the layer. |
|
Emitted after committing an attribute rename |
|
Emitted after feature addition has been committed to the layer. |
|
Emitted after feature removal has been committed to the layer. |
|
Emitted after feature geometry changes have been committed to the layer. |
|
Emitted when a feature has been added to the buffer |
|
Emitted when a feature was deleted from the buffer |
|
Emitted when a feature's geometry is changed. |
|
Emitted when modifications has been done on layer |
- class qgis.core.QgsVectorLayerEditBuffer[source]¶
Bases:
QObject
- virtual addAttribute(self, field: QgsField) bool [source]¶
Adds an attribute field (but does not commit it) returns
True
if the field was added- Parameters:
field (QgsField)
- Return type:
bool
- virtual addFeature(self, f: QgsFeature) bool [source]¶
Adds a feature
- Parameters:
f (QgsFeature) – feature to add
- Return type:
bool
- Returns:
True
in case of success andFalse
in case of error
- virtual addFeatures(self, features: Iterable[QgsFeature]) bool [source]¶
Insert a copy of the given features into the layer (but does not commit it)
- Parameters:
features (Iterable[QgsFeature])
- Return type:
bool
- addedAttributes(self) Any ¶
Returns a list of added attributes fields which are not committed.
- Return type:
Any
- addedFeatures(self) Any [source]¶
Returns a map of new features which are not committed.
See also
- Return type:
Any
- allAddedOrEditedFeatures(self) Any [source]¶
Returns a list of the features IDs for all newly added or edited features in the buffer.
Added in version 3.20.
- Return type:
Any
- signal attributeAdded(idx: int)[source]¶
Emitted when an attribute was added to the buffer.
- Parameters:
idx (int)
- signal attributeDeleted(idx: int)[source]¶
Emitted when an attribute was deleted from the buffer.
- Parameters:
idx (int)
- signal attributeRenamed(idx: int, newName: str)[source]¶
Emitted when an attribute has been renamed
- Parameters:
idx (int) – attribute index
newName (str) – new attribute name
- signal attributeValueChanged(fid: QgsFeatureId, idx: int, value: object)[source]¶
Emitted when a feature’s attribute value has been changed.
- Parameters:
fid (QgsFeatureId)
idx (int)
value (object)
- virtual changeAttributeValue(self, fid: int, field: int, newValue: Any, oldValue: Any = None) bool [source]¶
Changed an attribute value (but does not commit it)
- Parameters:
fid (int)
field (int)
newValue (Any)
oldValue (Any = None)
- Return type:
bool
- virtual changeAttributeValues(self, fid: int, newValues: Dict[int, Any], oldValues: Dict[int, Any]) bool [source]¶
Changes values of attributes (but does not commit it).
- Return type:
bool
- Returns:
True
if attributes are well updated,False
otherwise- Parameters:
fid (int)
newValues (Dict[int, Any])
oldValues (Dict[int, Any])
- virtual changeGeometry(self, fid: int, geom: QgsGeometry) bool [source]¶
Change feature’s geometry
- Parameters:
fid (int)
geom (QgsGeometry)
- Return type:
bool
- changedAttributeValues(self) Any [source]¶
Returns a map of features with changed attributes values which are not committed.
See also
- Return type:
Any
- changedGeometries(self) Any [source]¶
Returns a map of features with changed geometries which are not committed.
See also
- Return type:
Any
- virtual commitChanges(self, commitErrors: Iterable[str | None]) bool [source]¶
Attempts to commit any changes to disk. Returns the result of the attempt. If a commit fails, the in-memory changes are left alone.
This allows editing to continue if the commit failed on e.g. a disallowed value in a Postgres database - the user can re-edit and try again.
The commits occur in distinct stages, (add attributes, add features, change attribute values, change geometries, delete features, delete attributes) so if a stage fails, it’s difficult to roll back cleanly. Therefore any error message also includes which stage failed so that the user has some chance of repairing the damage cleanly.
- Parameters:
commitErrors (Iterable[Optional[str]])
- Return type:
bool
- signal committedAttributeValuesChanges(layerId: str, changedAttributesValues: QgsChangedAttributesMap)[source]¶
Emitted after feature attribute value changes have been committed to the layer.
- Parameters:
layerId (str)
changedAttributesValues (QgsChangedAttributesMap)
- signal committedAttributesAdded(layerId: str, addedAttributes: List[QgsField])[source]¶
Emitted after attribute addition has been committed to the layer.
- Parameters:
layerId (str)
addedAttributes (List[QgsField])
- signal committedAttributesDeleted(layerId: str, deletedAttributes: QgsAttributeList)[source]¶
Emitted after attribute deletion has been committed to the layer.
- Parameters:
layerId (str)
deletedAttributes (QgsAttributeList)
- signal committedAttributesRenamed(layerId: str, renamedAttributes: QgsFieldNameMap)[source]¶
Emitted after committing an attribute rename
- Parameters:
layerId (str) – ID of layer
renamedAttributes (QgsFieldNameMap) – map of field index to new name
- signal committedFeaturesAdded(layerId: str, addedFeatures: QgsFeatureList)[source]¶
Emitted after feature addition has been committed to the layer.
- Parameters:
layerId (str)
addedFeatures (QgsFeatureList)
- signal committedFeaturesRemoved(layerId: str, deletedFeatureIds: QgsFeatureIds)[source]¶
Emitted after feature removal has been committed to the layer.
- Parameters:
layerId (str)
deletedFeatureIds (QgsFeatureIds)
- signal committedGeometriesChanges(layerId: str, changedGeometries: QgsGeometryMap)[source]¶
Emitted after feature geometry changes have been committed to the layer.
- Parameters:
layerId (str)
changedGeometries (QgsGeometryMap)
- virtual deleteAttribute(self, attr: int) bool [source]¶
Deletes an attribute field (but does not commit it)
- Parameters:
attr (int)
- Return type:
bool
- virtual deleteFeature(self, fid: int) bool [source]¶
Delete a feature from the layer (but does not commit it)
- Parameters:
fid (int)
- Return type:
bool
- virtual deleteFeatures(self, fid: Any) bool [source]¶
Deletes a set of features from the layer (but does not commit it)
- Parameters:
fid (Any)
- Return type:
bool
- deletedAttributeIds(self) List[int] [source]¶
Returns a list of deleted attributes fields which are not committed. The list is kept sorted.
See also
- Return type:
List[int]
- deletedFeatureIds(self) Any [source]¶
Returns a list of deleted feature IDs which are not committed.
See also
- Return type:
Any
- editBufferGroup(self) QgsVectorLayerEditBufferGroup | None [source]¶
Returns the parent edit buffer group for this edit buffer, or None if not part of a group.
Added in version 3.26.
- Return type:
Optional[QgsVectorLayerEditBufferGroup]
- signal featureAdded(fid: QgsFeatureId)[source]¶
Emitted when a feature has been added to the buffer
- Parameters:
fid (QgsFeatureId)
- signal featureDeleted(fid: QgsFeatureId)[source]¶
Emitted when a feature was deleted from the buffer
- Parameters:
fid (QgsFeatureId)
- signal geometryChanged(fid: QgsFeatureId, geom: QgsGeometry)[source]¶
Emitted when a feature’s geometry is changed.
- Parameters:
fid (QgsFeatureId) – feature ID
geom (QgsGeometry) – new feature geometry
- handleAttributeAdded(self, index: int, field: QgsField)[source]¶
Update added and changed features after addition of an attribute
- Parameters:
index (int)
field (QgsField)
- handleAttributeDeleted(self, index: int)[source]¶
Update added and changed features after removal of an attribute
- Parameters:
index (int)
- isAttributeDeleted(self, index: int) bool [source]¶
Returns
True
if the specified attribute has been deleted but not committed.- Parameters:
index (int) – attribute index
See also
- Return type:
bool
- isFeatureAdded(self, id: int) bool [source]¶
Returns
True
if the specified feature ID has been added but not committed.- Parameters:
id (int) – feature ID
See also
- Return type:
bool
- isFeatureAttributesChanged(self, id: int) bool [source]¶
Returns
True
if the specified feature ID has had an attribute changed but not committed.- Parameters:
id (int) – feature ID
See also
- Return type:
bool
- isFeatureDeleted(self, id: int) bool [source]¶
Returns
True
if the specified feature ID has been deleted but not committed.- Parameters:
id (int) – feature ID
See also
- Return type:
bool
- isFeatureGeometryChanged(self, id: int) bool [source]¶
Returns
True
if the specified feature ID has had its geometry changed but not committed.- Parameters:
id (int) – feature ID
See also
- Return type:
bool
- virtual isModified(self) bool [source]¶
Returns
True
if the provider has been modified since the last commit- Return type:
bool
- virtual renameAttribute(self, attr: int, newName: str | None) bool [source]¶
Renames an attribute field (but does not commit it)
- Parameters:
attr (int) – attribute index
newName (Optional[str]) – new name of field
- Return type:
bool
- setEditBufferGroup(self, editBufferGroup: QgsVectorLayerEditBufferGroup | None)[source]¶
Set the parent edit buffer group for this edit buffer.
Added in version 3.26.
- Parameters:
editBufferGroup (Optional[QgsVectorLayerEditBufferGroup])
- updateAttributeMapIndex(self, attrs: Dict[int, Any], index: int, offset: int)[source]¶
Updates an index in an attribute map to a new value (for updates of changed attributes)
- Parameters:
attrs (Dict[int, Any])
index (int)
offset (int)
- updateChangedAttributes(self, f: QgsFeature)[source]¶
Update feature with uncommitted attribute updates
- Parameters:
f (QgsFeature)
- updateFeatureGeometry(self, f: QgsFeature)[source]¶
Update feature with uncommitted geometry updates
- Parameters:
f (QgsFeature)