Class: QgsVectorLayerEditBuffer

Stores queued vector layer edit operations prior to committing changes to the layer’s data provider.

Class Hierarchy

Inheritance diagram of qgis.core.QgsVectorLayerEditBuffer

Base classes

QObject

Subclasses

QgsVectorLayerEditPassthrough

An edit buffer which directly passes commands through, used when a layer is within a transaction.

Methods

addedAttributes

Returns a list of added attributes fields which are not committed.

addedFeatures

Returns a map of new features which are not committed.

allAddedOrEditedFeatures

Returns a list of the features IDs for all newly added or edited features in the buffer.

changedAttributeValues

Returns a map of features with changed attributes values which are not committed.

changedGeometries

Returns a map of features with changed geometries which are not committed.

deletedAttributeIds

Returns a list of deleted attributes fields which are not committed.

deletedFeatureIds

Returns a list of deleted feature IDs which are not committed.

editBufferGroup

Returns the parent edit buffer group for this edit buffer, or None if not part of a group.

handleAttributeAdded

Update added and changed features after addition of an attribute

handleAttributeDeleted

Update added and changed features after removal of an attribute

isAttributeDeleted

Returns True if the specified attribute has been deleted but not committed.

isFeatureAdded

Returns True if the specified feature ID has been added but not committed.

isFeatureAttributesChanged

Returns True if the specified feature ID has had an attribute changed but not committed.

isFeatureDeleted

Returns True if the specified feature ID has been deleted but not committed.

isFeatureGeometryChanged

Returns True if the specified feature ID has had its geometry changed but not committed.

setEditBufferGroup

Set the parent edit buffer group for this edit buffer.

undoIndexChanged

updateAttributeMapIndex

Updates an index in an attribute map to a new value (for updates of changed attributes)

updateChangedAttributes

Update feature with uncommitted attribute updates

updateFeatureGeometry

Update feature with uncommitted geometry updates

updateLayerFields

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.

addAttribute

Adds an attribute field (but does not commit it) returns True if the field was added

addFeature

Adds a feature

addFeatures

Insert a copy of the given features into the layer (but does not commit it)

changeAttributeValue

Changed an attribute value (but does not commit it)

changeAttributeValues

Changes values of attributes (but does not commit it).

changeGeometry

Change feature's geometry

commitChanges

Attempts to commit any changes to disk.

deleteAttribute

Deletes an attribute field (but does not commit it)

deleteFeature

Delete a feature from the layer (but does not commit it)

deleteFeatures

Deletes a set of features from the layer (but does not commit it)

isModified

Returns True if the provider has been modified since the last commit

renameAttribute

Renames an attribute field (but does not commit it)

rollBack

Stop editing and discard the edits

Signals

attributeAdded

Emitted when an attribute was added to the buffer.

attributeDeleted

Emitted when an attribute was deleted from the buffer.

attributeRenamed

Emitted when an attribute has been renamed

attributeValueChanged

Emitted when a feature's attribute value has been changed.

committedAttributeValuesChanges

Emitted after feature attribute value changes have been committed to the layer.

committedAttributesAdded

Emitted after attribute addition has been committed to the layer.

committedAttributesDeleted

Emitted after attribute deletion has been committed to the layer.

committedAttributesRenamed

Emitted after committing an attribute rename

committedFeaturesAdded

Emitted after feature addition has been committed to the layer.

committedFeaturesRemoved

Emitted after feature removal has been committed to the layer.

committedGeometriesChanges

Emitted after feature geometry changes have been committed to the layer.

featureAdded

Emitted when a feature has been added to the buffer

featureDeleted

Emitted when a feature was deleted from the buffer

geometryChanged

Emitted when a feature's geometry is changed.

layerModified

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 and False 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

isFeatureAdded()

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:
Return type:

bool

changedAttributeValues(self) Any[source]

Returns a map of features with changed attributes values which are not committed.

Return type:

Any

changedGeometries(self) Any[source]

Returns a map of features with changed geometries which are not committed.

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.

Return type:

List[int]

deletedFeatureIds(self) Any[source]

Returns a list of deleted feature IDs which are not committed.

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:
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

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

addedFeatures()

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

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

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

Return type:

bool

virtual isModified(self) bool[source]

Returns True if the provider has been modified since the last commit

Return type:

bool

signal layerModified[source]

Emitted when modifications has been done on layer

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

virtual rollBack(self)[source]

Stop editing and discard the edits

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])

undoIndexChanged(self, index: int)[source]
Parameters:

index (int)

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)

updateLayerFields(self)[source]