Class: QgsVectorLayerEditBuffer

class qgis.core.QgsVectorLayerEditBuffer(layer: QgsVectorLayer)

Bases: PyQt5.QtCore.QObject

QgsVectorLayerEditBuffer() Constructor for QgsVectorLayerEditBuffer

Methods

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)

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.

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

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.

childEvent

commitChanges

Attempts to commit any changes to disk.

connectNotify

customEvent

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)

deletedAttributeIds

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

deletedFeatureIds

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

disconnectNotify

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.

isModified

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

isSignalConnected

receivers

renameAttribute

Renames an attribute field (but does not commit it)

rollBack

Stop editing and discard the edits

sender

senderSignalIndex

timerEvent

undoIndexChanged

param index

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

Signals

attributeAdded

attributeAdded(self, idx: int) [signal]

attributeDeleted

attributeDeleted(self, idx: int) [signal]

attributeRenamed

Emitted when an attribute has been renamed

attributeValueChanged

attributeValueChanged(self, fid: int, idx: int, a2: Any) [signal]

committedAttributeValuesChanges

committedAttributeValuesChanges(self, layerId: str, changedAttributesValues: object) [signal]

committedAttributesAdded

committedAttributesAdded(self, layerId: str, addedAttributes: object) [signal]

committedAttributesDeleted

Signals emitted after committing changes [signal]

committedAttributesRenamed

Emitted after committing an attribute rename

committedFeaturesAdded

committedFeaturesAdded(self, layerId: str, addedFeatures: Iterable[QgsFeature]) [signal]

committedFeaturesRemoved

committedFeaturesRemoved(self, layerId: str, deletedFeatureIds: object) [signal]

committedGeometriesChanges

committedGeometriesChanges(self, layerId: str, changedGeometries: object) [signal]

featureAdded

featureAdded(self, fid: int) [signal]

featureDeleted

featureDeleted(self, fid: int) [signal]

geometryChanged

Emitted when a feature’s geometry is changed.

layerModified

Emitted when modifications has been done on layer [signal]

addAttribute(self, field: QgsField) bool

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

Parameters

field (QgsField) –

Return type

bool

addFeature(self, f: QgsFeature) bool

Adds a feature

Parameters

f (QgsFeature) – feature to add

Return type

bool

Returns

True in case of success and False in case of error

addFeatures(self, features: Iterable[QgsFeature]) bool

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

Parameters

features (Iterable[QgsFeature]) –

Return type

bool

addedAttributes(self) object

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

Return type

object

addedFeatures(self) object

Returns a map of new features which are not committed.

See also

isFeatureAdded()

Return type

object

allAddedOrEditedFeatures(self) object

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

New in version 3.20.

Return type

object

attributeAdded

attributeAdded(self, idx: int) [signal]

Parameters

idx (int) –

attributeDeleted

attributeDeleted(self, idx: int) [signal]

Parameters

idx (int) –

attributeRenamed

Emitted when an attribute has been renamed

Parameters
  • idx (int) – attribute index

  • newName (str) – new attribute name

New in version 2.16: [signal]

attributeValueChanged

attributeValueChanged(self, fid: int, idx: int, a2: Any) [signal]

Parameters
  • fid (int) –

  • idx (int) –

  • a2 (Any) –

changeAttributeValue(self, fid: int, field: int, newValue: Any, oldValue: Any = None) bool

Changed an attribute value (but does not commit it)

Parameters
  • fid (int) –

  • field (int) –

  • newValue (Any) –

  • oldValue (Any = None) –

Return type

bool

changeAttributeValues(self, fid: int, newValues: Dict[int, Any], oldValues: Dict[int, Any]) bool

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

Return type

bool

Returns

True if attributes are well updated, False otherwise

New in version 3.0.

Parameters
  • fid (int) –

  • newValues (Dict[int) –

  • oldValues (Dict[int) –

changeGeometry(self, fid: int, geom: QgsGeometry) bool

Change feature’s geometry

Parameters
Return type

bool

changedAttributeValues(self) object

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

Return type

object

changedGeometries(self) object

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

Return type

object

childEvent(self, QChildEvent)
commitChanges(self, commitErrors: Iterable[str]) bool

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[str]) –

Return type

bool

committedAttributeValuesChanges

committedAttributeValuesChanges(self, layerId: str, changedAttributesValues: object) [signal]

Parameters
  • layerId (str) –

  • changedAttributesValues (object) –

committedAttributesAdded

committedAttributesAdded(self, layerId: str, addedAttributes: object) [signal]

Parameters
  • layerId (str) –

  • addedAttributes (object) –

committedAttributesDeleted

Signals emitted after committing changes [signal]

Parameters
  • layerId (str) –

  • deletedAttributes (Iterable[int]) –

committedAttributesRenamed

Emitted after committing an attribute rename

Parameters
  • layerId (str) – ID of layer

  • renamedAttributes (Dict[int) – map of field index to new name

New in version 2.16: [signal]

committedFeaturesAdded

committedFeaturesAdded(self, layerId: str, addedFeatures: Iterable[QgsFeature]) [signal]

Parameters
  • layerId (str) –

  • addedFeatures (Iterable[QgsFeature]) –

committedFeaturesRemoved

committedFeaturesRemoved(self, layerId: str, deletedFeatureIds: object) [signal]

Parameters
  • layerId (str) –

  • deletedFeatureIds (object) –

committedGeometriesChanges

committedGeometriesChanges(self, layerId: str, changedGeometries: object) [signal]

Parameters
  • layerId (str) –

  • changedGeometries (object) –

connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
deleteAttribute(self, attr: int) bool

Deletes an attribute field (but does not commit it)

Parameters

attr (int) –

Return type

bool

deleteFeature(self, fid: int) bool

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

Parameters

fid (int) –

Return type

bool

deleteFeatures(self, fid: object) bool

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

Parameters

fid (object) –

Return type

bool

deletedAttributeIds(self) List[int]

Returns a list of deleted attributes fields which are not committed. The list is kept sorted.

Return type

List[int]

deletedFeatureIds(self) object

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

Return type

object

disconnectNotify(self, QMetaMethod)
featureAdded

featureAdded(self, fid: int) [signal]

Parameters

fid (int) –

featureDeleted

featureDeleted(self, fid: int) [signal]

Parameters

fid (int) –

geometryChanged

Emitted when a feature’s geometry is changed.

Parameters
  • fid (int) – feature ID

  • geom (QgsGeometry) – new feature geometry [signal]

handleAttributeAdded(self, index: int)

Update added and changed features after addition of an attribute

Parameters

index (int) –

handleAttributeDeleted(self, index: int)

Update added and changed features after removal of an attribute

Parameters

index (int) –

isAttributeDeleted(self, index: int) bool

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

Parameters

index (int) – attribute index

New in version 3.0.

Return type

bool

isFeatureAdded(self, id: int) bool

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

Parameters

id (int) – feature ID

See also

addedFeatures()

New in version 3.0.

Return type

bool

isFeatureAttributesChanged(self, id: int) bool

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

Parameters

id (int) – feature ID

New in version 3.0.

Return type

bool

isFeatureDeleted(self, id: int) bool

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

Parameters

id (int) – feature ID

New in version 3.0.

Return type

bool

isFeatureGeometryChanged(self, id: int) bool

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

Parameters

id (int) – feature ID

New in version 3.0.

Return type

bool

isModified(self) bool

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

Return type

bool

isSignalConnected(self, QMetaMethod) bool
layerModified

Emitted when modifications has been done on layer [signal]

receivers(self, PYQT_SIGNAL) int
renameAttribute(self, attr: int, newName: str) bool

Renames an attribute field (but does not commit it)

Parameters
  • attr (int) – attribute index

  • newName (str) – new name of field

New in version 2.16.

Return type

bool

rollBack(self)

Stop editing and discard the edits

sender(self) QObject
senderSignalIndex(self) int
timerEvent(self, QTimerEvent)
undoIndexChanged(self, index: int)
Parameters

index (int) –

updateAttributeMapIndex(self, attrs: Dict[int, Any], index: int, offset: int)

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

Parameters
  • attrs (Dict[int) –

  • index (int) –

  • offset (int) –

updateChangedAttributes(self, f: QgsFeature)

Update feature with uncommitted attribute updates

Parameters

f (QgsFeature) –

updateFeatureGeometry(self, f: QgsFeature)

Update feature with uncommitted geometry updates

Parameters

f (QgsFeature) –

updateLayerFields(self)