Class: QgsMapToolAdvancedDigitizing

A QgsMapTool which gives events directly in map coordinates and allows filtering of 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.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsMapToolAdvancedDigitizing

Base classes

QgsMapToolEdit

Base class for map tools that edit vector geometry.

QgsMapTool

Abstract base class for all map tools.

QObject

Subclasses

QgsMapToolCapture

Base class for map tools capable of capturing point, lines and polygons.

Methods

cadDockWidget

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.

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.

setUseSnappingIndicator

Sets whether a snapping indicator should automatically be used.

snapToLayerGridEnabled

Enables or disables snap to grid of mouse events.

useSnappingIndicator

Returns whether the snapping indicator should automatically be used.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsMapToolAdvancedDigitizing. See the FAQ for more details.

activate

Registers this maptool with the cad dock widget

cadCanvasMoveEvent

Override this method when subclassing this class.

cadCanvasPressEvent

Override this method when subclassing this class.

cadCanvasReleaseEvent

Override this method when subclassing this class.

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

deactivate

Unregisters this maptool from the cad dock widget

layer

Returns the layer associated with the map tool.

class qgis.gui.QgsMapToolAdvancedDigitizing[source]

Bases: QgsMapToolEdit

__init__(canvas: QgsMapCanvas | None, cadDockWidget: QgsAdvancedDigitizingDockWidget | None)

Creates an advanced digitizing maptool

Parameters:
virtual activate(self)[source]

Registers this maptool with the cad dock widget

virtual cadCanvasMoveEvent(self, e: QgsMapMouseEvent | None)[source]

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 (Optional[QgsMapMouseEvent]) – Mouse events prepared by the cad system

virtual cadCanvasPressEvent(self, e: QgsMapMouseEvent | None)[source]

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 (Optional[QgsMapMouseEvent]) – Mouse events prepared by the cad system

virtual cadCanvasReleaseEvent(self, e: QgsMapMouseEvent | None)[source]

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 (Optional[QgsMapMouseEvent]) – Mouse events prepared by the cad system

cadDockWidget(self) QgsAdvancedDigitizingDockWidget | None[source]
Return type:

Optional[QgsAdvancedDigitizingDockWidget]

virtual canvasMoveEvent(self, e: QgsMapMouseEvent | None)[source]

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

Parameters:

e (Optional[QgsMapMouseEvent])

virtual canvasPressEvent(self, e: QgsMapMouseEvent | None)[source]

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

Parameters:

e (Optional[QgsMapMouseEvent])

virtual canvasReleaseEvent(self, e: QgsMapMouseEvent | None)[source]

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

Parameters:

e (Optional[QgsMapMouseEvent])

virtual deactivate(self)[source]

Unregisters this maptool from the cad dock widget

isAdvancedDigitizingAllowed(self) bool[source]

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.

The default is that advanced digitizing is allowed.

Return type:

bool

isAutoSnapEnabled(self) bool[source]

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.

The default is that auto snapping is enabled.

Return type:

bool

virtual layer(self) QgsMapLayer | None[source]

Returns the layer associated with the map tool.

By default this returns the map canvas’ QgsMapCanvas.currentLayer().

Added in version 3.22.

Return type:

Optional[QgsMapLayer]

setAdvancedDigitizingAllowed(self, allowed: bool)[source]

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.

The default is that advanced digitizing is allowed.

Parameters:

allowed (bool)

setAutoSnapEnabled(self, enabled: bool)[source]

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.

The default is that auto snapping is enabled.

Parameters:

enabled (bool)

setSnapToLayerGridEnabled(self, snapToLayerGridEnabled: bool)[source]

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

Added in version 3.4.

Parameters:

snapToLayerGridEnabled (bool)

setUseSnappingIndicator(self, enabled: bool)[source]

Sets whether a snapping indicator should automatically be used.

The default is that a snap indicator is not used.

Added in version 3.40.

Parameters:

enabled (bool)

snapToLayerGridEnabled(self) bool[source]

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

Added in version 3.4.

Return type:

bool

useSnappingIndicator(self) bool[source]

Returns whether the snapping indicator should automatically be used.

The default is that a snap indicator is not used.

Added in version 3.40.

Return type:

bool