QgsMapToolAdvancedDigitizing class

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 (

Base classes

class QgsMapToolEdit
Base class for map tools that edit vector geometry.

Constructors, destructors, conversion operators

QgsMapToolAdvancedDigitizing(QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget) explicit
Creates an advanced digitizing maptool.

Public functions

void activate() override
Registers this maptool with the cad dock widget.
void cadCanvasMoveEvent(QgsMapMouseEvent* e) virtual
Override this method when subclassing this class.
void cadCanvasPressEvent(QgsMapMouseEvent* e) virtual
Override this method when subclassing this class.
void cadCanvasReleaseEvent(QgsMapMouseEvent* e) virtual
Override this method when subclassing this class.
void canvasMoveEvent(QgsMapMouseEvent* e) override
Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method.
void canvasPressEvent(QgsMapMouseEvent* e) override
Catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual method.
void canvasReleaseEvent(QgsMapMouseEvent* e) override
Catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual method.
void deactivate() override
Unregisters this maptool from the cad dock widget.
auto isAdvancedDigitizingAllowed() const -> bool
Returns whether functionality of advanced digitizing dock widget is currently allowed.
auto isAutoSnapEnabled() const -> 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.
void setSnapToLayerGridEnabled(bool snapToLayerGridEnabled)
Enables or disables snap to grid of mouse events.
auto snapToLayerGridEnabled() const -> bool
Enables or disables snap to grid of mouse events.

Protected functions

void setAdvancedDigitizingAllowed(bool allowed)
Sets whether functionality of advanced digitizing dock widget is currently allowed.
void setAutoSnapEnabled(bool enabled)
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.

Function documentation

QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing(QgsMapCanvas* canvas, QgsAdvancedDigitizingDockWidget* cadDockWidget) explicit

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

void QgsMapToolAdvancedDigitizing::cadCanvasMoveEvent(QgsMapMouseEvent* e) virtual

Override this method when subclassing this class.

Parameters
e Mouse events prepared by the cad system

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.

void QgsMapToolAdvancedDigitizing::cadCanvasPressEvent(QgsMapMouseEvent* e) virtual

Override this method when subclassing this class.

Parameters
e Mouse events prepared by the cad system

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.

void QgsMapToolAdvancedDigitizing::cadCanvasReleaseEvent(QgsMapMouseEvent* e) virtual

Override this method when subclassing this class.

Parameters
e Mouse events prepared by the cad system

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.

bool QgsMapToolAdvancedDigitizing::isAdvancedDigitizingAllowed() const

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.

bool QgsMapToolAdvancedDigitizing::isAutoSnapEnabled() const

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.

void QgsMapToolAdvancedDigitizing::setSnapToLayerGridEnabled(bool snapToLayerGridEnabled)

Enables or disables snap to grid of mouse events.

The snapping will occur in the layer's CRS.

bool QgsMapToolAdvancedDigitizing::snapToLayerGridEnabled() const

Enables or disables snap to grid of mouse events.

The snapping will occur in the layer's CRS.

void QgsMapToolAdvancedDigitizing::setAdvancedDigitizingAllowed(bool allowed) protected

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.

void QgsMapToolAdvancedDigitizing::setAutoSnapEnabled(bool enabled) protected

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.