Class: QgsVectorLayerTools

class qgis.core.QgsVectorLayerTools

Bases: PyQt5.QtCore.QObject

Methods in this class are used to handle basic operations on vector layers. With an implementation of this class, parts of the application can ask for an operation to be done and the implementation will then take care of it.

Reimplement this class, if you need to have custom checks or GUI elements in your application.

Methods

addFeature

This method should/will be called, whenever a new feature will be added to the layer

childEvent

connectNotify

copyMoveFeatures

Copy and move features with defined translation.

customEvent

disconnectNotify

forceSuppressFormPopup

Returns force suppress form popup status.

isSignalConnected

receivers

saveEdits

Should be called, when the features should be committed but the editing session is not ended.

sender

senderSignalIndex

setForceSuppressFormPopup

Sets force suppress form popup status to forceSuppressFormPopup.

startEditing

This will be called, whenever a vector layer should be switched to edit mode.

stopEditing

Will be called, when an editing session is ended and the features should be committed.

timerEvent

addFeature(self, layer: QgsVectorLayer, defaultValues: Dict[int, Any] = {}, defaultGeometry: QgsGeometry = QgsGeometry(), parentWidget: QWidget = None, showModal: bool = True, hideParent: bool = False) Tuple[bool, QgsFeature]

This method should/will be called, whenever a new feature will be added to the layer

Parameters
  • layer (QgsVectorLayer) – The layer to which the feature should be added

  • defaultValues (Dict[int) – Default values for the feature to add

  • defaultGeometry (QgsGeometry = QgsGeometry()) – A default geometry to add to the feature

  • parentWidget (QWidget = None) – The widget calling this function to be passed to the used dialog

  • showModal (bool = True) – If the used dialog should be modal or not

  • hideParent (bool = False) – If the parent widget should be hidden, when the used dialog is opened

Return type

Tuple[bool, QgsFeature]

Returns

  • True in case of success, False if the operation failed/was aborted

  • feature: Updated feature after adding will be written back to this

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
copyMoveFeatures(self, layer: QgsVectorLayer, request: QgsFeatureRequest, dx: float = 0, dy: float = 0, topologicalEditing: bool = False, topologicalLayer: QgsVectorLayer = None) Tuple[bool, QgsFeatureRequest, str]

Copy and move features with defined translation.

Parameters
  • layer (QgsVectorLayer) – The layer

  • request (QgsFeatureRequest) – The request for the features to be moved. It will be assigned to a new feature request with the newly copied features.

  • dx (float = 0) – The translation on x

  • dy (float = 0) – The translation on y

  • topologicalEditing (bool = False) – If True, the function will perform topological editing of the vertices of layer on layer and topologicalLayer

  • topologicalLayer (QgsVectorLayer = None) – The layer where vertices from the moved features of layer will be added

Return type

Tuple[bool, QgsFeatureRequest, str]

Returns

  • True if all features could be copied.

  • errorMsg: If given, it will contain the error message

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
forceSuppressFormPopup(self) bool

Returns force suppress form popup status.

Return type

bool

Returns

True if force suppress form popup is set.

New in version 3.14.

isSignalConnected(self, QMetaMethod) bool
receivers(self, PYQT_SIGNAL) int
saveEdits(self, layer: QgsVectorLayer) bool

Should be called, when the features should be committed but the editing session is not ended.

Parameters

layer (QgsVectorLayer) – The layer to commit

Return type

bool

Returns

True if successful

sender(self) QObject
senderSignalIndex(self) int
setForceSuppressFormPopup(self, forceSuppressFormPopup: bool)

Sets force suppress form popup status to forceSuppressFormPopup.

This flag will override the layer and general settings regarding the automatic opening of the attribute form dialog when digitizing is completed.

New in version 3.14.

Parameters

forceSuppressFormPopup (bool) –

startEditing(self, layer: QgsVectorLayer) bool

This will be called, whenever a vector layer should be switched to edit mode. Check the providers capability to edit in here. If successful layer->:py:func:~QgsVectorLayerTools.startEditing will be called and True returned.

Parameters

layer (QgsVectorLayer) – The layer on which to start an edit session

Return type

bool

Returns

True, if the editing session was started

stopEditing(self, layer: QgsVectorLayer, allowCancel: bool = True) bool

Will be called, when an editing session is ended and the features should be committed. Appropriate dialogs should be shown like

Parameters
  • layer (QgsVectorLayer) – The layer to commit

  • allowCancel (bool = True) – True if a cancel button should be offered

Return type

bool

Returns

True if successful

timerEvent(self, QTimerEvent)