Class: QgsMapToolAdvancedDigitizing

class qgis.gui.QgsMapToolAdvancedDigitizing(canvas: QgsMapCanvas, cadDockWidget: QgsAdvancedDigitizingDockWidget)

Bases: QgsMapToolEdit

Creates an advanced digitizing maptool

Parameters
  • canvas – The map canvas on which the tool works

  • cadDockWidget – The cad dock widget which will be used to adjust mouse events

The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates and allows filtering its events. Events from QgsMapTool are caught and their QMouseEvent are transformed into QgsMapMouseEvent (with map coordinates). Events are then forwarded to corresponding virtual methods which can be reimplemented in subclasses. An event filter can be set on the map tool to filter and modify the events in map coordinates (QgsMapToolMapEventFilter).

Note

at the moment, the event filter is used by the CAD tools (QgsCadDocWidget).

Note

the event filter definition is not exposed in Python API to avoid any unexpected behavior.

Methods

activate

Registers this maptool with the cad dock widget

addTopologicalPoints

Adds a list of vertices to other features to keep topology up to date, e.g.

cadCanvasMoveEvent

Override this method when subclassing this class.

cadCanvasPressEvent

Override this method when subclassing this class.

cadCanvasReleaseEvent

Override this method when subclassing this class.

cadDockWidget

rtype

QgsAdvancedDigitizingDockWidget

canvasMoveEvent

Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method

canvasPressEvent

Catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual method

canvasReleaseEvent

Catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual method

childEvent

connectNotify

createGeometryRubberBand

createRubberBand

Creates a rubber band with the color/line width from the QGIS settings.

currentVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent

deactivate

Unregisters this maptool from the cad dock widget

digitizingFillColor

Returns fill color for rubber bands (from global settings)

digitizingStrokeColor

Returns stroke color for rubber bands (from global settings)

digitizingStrokeWidth

Returns stroke width for rubber bands (from global settings)

disconnectNotify

isAdvancedDigitizingAllowed

Returns whether functionality of advanced digitizing dock widget is currently allowed.

isAutoSnapEnabled

Returns whether mouse events (press/move/release) should automatically try to snap mouse position (according to the snapping configuration of map canvas) before passing the mouse coordinates to the tool.

isSignalConnected

notifyNotEditableLayer

Display a timed message bar noting the active vector layer is not editable.

notifyNotVectorLayer

Display a timed message bar noting the active layer is not vector.

receivers

sender

senderSignalIndex

setAdvancedDigitizingAllowed

Sets whether functionality of advanced digitizing dock widget is currently allowed.

setAutoSnapEnabled

Sets whether mouse events (press/move/release) should automatically try to snap mouse position This method is protected because it should be a decision of the map tool and not from elsewhere.

setSnapToLayerGridEnabled

Enables or disables snap to grid of mouse events.

snapToLayerGridEnabled

Enables or disables snap to grid of mouse events.

timerEvent

toCanvasCoordinates

transformation from map coordinates to screen coordinates

toLayerCoordinates

transformation from screen coordinates to layer's coordinates

toMapCoordinates

transformation from screen coordinates to map coordinates

toMapCoordinatesV2

transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)

activate(self)

Registers this maptool with the cad dock widget

addTopologicalPoints(self, vertices: Iterable[QgsPointXY]) QgsMapToolEdit.TopologicalResult

Adds a list of vertices to other features to keep topology up to date, e.g. to neighbouring polygons. The vertices list specifies a set of topological points to add, in the layer’s coordinate reference system.

Deprecated since version QGIS: 3.12 - will be removed in QGIS 4.0. Use the variant which accepts QgsPoint objects instead of QgsPointXY.

addTopologicalPoints(self, vertices: Iterable[QgsPoint]) -> QgsMapToolEdit.TopologicalResult Adds a list of vertices to other features to keep topology up to date, e.g. to neighbouring polygons. The vertices list specifies a set of topological points to add, in the layer’s coordinate reference system.

New in version 3.10.

cadCanvasMoveEvent(self, e: QgsMapMouseEvent)

Override this method when subclassing this class. This will receive adapted events from the cad system whenever a canvasMoveEvent is triggered and it’s not hidden by the cad’s construction mode.

Parameters

e (QgsMapMouseEvent) – Mouse events prepared by the cad system

cadCanvasPressEvent(self, e: QgsMapMouseEvent)

Override this method when subclassing this class. This will receive adapted events from the cad system whenever a canvasPressEvent is triggered and it’s not hidden by the cad’s construction mode.

Parameters

e (QgsMapMouseEvent) – Mouse events prepared by the cad system

cadCanvasReleaseEvent(self, e: QgsMapMouseEvent)

Override this method when subclassing this class. This will receive adapted events from the cad system whenever a canvasReleaseEvent is triggered and it’s not hidden by the cad’s construction mode.

Parameters

e (QgsMapMouseEvent) – Mouse events prepared by the cad system

cadDockWidget(self) QgsAdvancedDigitizingDockWidget
Return type

QgsAdvancedDigitizingDockWidget

canvasMoveEvent(self, e: QgsMapMouseEvent)

Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method

Parameters

e (QgsMapMouseEvent) –

canvasPressEvent(self, e: QgsMapMouseEvent)

Catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual method

Parameters

e (QgsMapMouseEvent) –

canvasReleaseEvent(self, e: QgsMapMouseEvent)

Catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual method

Parameters

e (QgsMapMouseEvent) –

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
createGeometryRubberBand(self, geometryType: QgsWkbTypes.GeometryType = QgsWkbTypes.LineGeometry, alternativeBand: bool = False) QgsGeometryRubberBand
createRubberBand(self, geometryType: QgsWkbTypes.GeometryType = QgsWkbTypes.LineGeometry, alternativeBand: bool = False) QgsRubberBand

Creates a rubber band with the color/line width from the QGIS settings. The caller takes ownership of the returned object

Parameters
  • geometryType

  • alternativeBand – if True, rubber band will be set with more transparency and a dash pattern. default is False.

currentVectorLayer(self) QgsVectorLayer

Returns the current vector layer of the map canvas or 0

customEvent(self, QEvent)
deactivate(self)

Unregisters this maptool from the cad dock widget

digitizingFillColor() QColor

Returns fill color for rubber bands (from global settings)

digitizingStrokeColor() QColor

Returns stroke color for rubber bands (from global settings)

digitizingStrokeWidth() int

Returns stroke width for rubber bands (from global settings)

disconnectNotify(self, QMetaMethod)
isAdvancedDigitizingAllowed(self) bool

Returns whether functionality of advanced digitizing dock widget is currently allowed.

Tools may decide to switch this support on/off based on the current state of the map tool. For example, in vertex tool before user picks a vertex to move, advanced digitizing dock widget should be disabled and only enabled once a vertex is being moved. Other map tools may keep advanced digitizing allowed all the time.

If True is returned, that does not mean that advanced digitizing is actually active, because it is up to the user to enable/disable it when it is allowed. sa setAdvancedDigitizingAllowed()

New in version 3.0.

Return type

bool

isAutoSnapEnabled(self) bool

Returns whether mouse events (press/move/release) should automatically try to snap mouse position (according to the snapping configuration of map canvas) before passing the mouse coordinates to the tool. This may be desirable default behavior for some map tools, but not for other map tools. It is therefore possible to configure the behavior by the map tool. sa isAutoSnapEnabled()

New in version 3.0.

Return type

bool

isSignalConnected(self, QMetaMethod) bool
notifyNotEditableLayer(self)

Display a timed message bar noting the active vector layer is not editable.

notifyNotVectorLayer(self)

Display a timed message bar noting the active layer is not vector.

receivers(self, PYQT_SIGNAL) int
sender(self) QObject
senderSignalIndex(self) int
setAdvancedDigitizingAllowed(self, allowed: bool)

Sets whether functionality of advanced digitizing dock widget is currently allowed. This method is protected because it should be a decision of the map tool and not from elsewhere. sa isAdvancedDigitizingAllowed()

New in version 3.0.

Parameters

allowed (bool) –

setAutoSnapEnabled(self, enabled: bool)

Sets whether mouse events (press/move/release) should automatically try to snap mouse position This method is protected because it should be a decision of the map tool and not from elsewhere. sa isAutoSnapEnabled()

New in version 3.0.

Parameters

enabled (bool) –

setSnapToLayerGridEnabled(self, snapToLayerGridEnabled: bool)

Enables or disables snap to grid of mouse events. The snapping will occur in the layer’s CRS.

New in version 3.4.

Parameters

snapToLayerGridEnabled (bool) –

snapToLayerGridEnabled(self) bool

Enables or disables snap to grid of mouse events. The snapping will occur in the layer’s CRS.

New in version 3.4.

Return type

bool

timerEvent(self, QTimerEvent)
toCanvasCoordinates(self, point: QgsPointXY) QPoint

transformation from map coordinates to screen coordinates

toLayerCoordinates(self, layer: QgsMapLayer, point: QPoint) QgsPointXY

transformation from screen coordinates to layer’s coordinates

toLayerCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY transformation from map coordinates to layer’s coordinates

toLayerCoordinates(self, layer: QgsMapLayer, rect: QgsRectangle) -> QgsRectangle trnasformation of the rect from map coordinates to layer’s coordinates

toMapCoordinates(self, point: QPoint) QgsPointXY

transformation from screen coordinates to map coordinates

toMapCoordinates(self, layer: QgsMapLayer, point: QgsPointXY) -> QgsPointXY transformation from layer’s coordinates to map coordinates (which is different in case reprojection is used)

toMapCoordinatesV2(self, layer: QgsMapLayer, point: QgsPoint) QgsPoint

transformation from layer’s coordinates to map coordinates (which is different in case reprojection is used)

Note

available in Python bindings as toMapCoordinatesV2