Class: QgsMapCanvasTracer

Extension of QgsTracer that provides extra functionality:

  • automatic updates of own configuration based on canvas settings

  • reporting of issues to the user via message bar

  • determines whether tracing is currently enabled by the user

A simple registry of tracer instances associated to map canvas instances is kept for convenience. (Map tools do not need to create their local tracer instances and map canvas API is not “polluted” by this optional functionality).

Class Hierarchy

Inheritance diagram of qgis.gui.QgsMapCanvasTracer

Base classes

QgsTracer

Utility class that construct a planar graph from the input vector layers and provides shortest path search for tracing of existing features.

QObject

Methods

actionEnableSnapping

Access to action that user may use to toggle snapping on/off.

actionEnableTracing

Access to action that user may use to toggle tracing on/off.

configure

Sets configuration from current snapping settings and canvas settings

reportError

Report a path finding error to the user

setActionEnableSnapping

Assign "enable snapping" checkable action to the tracer.

setActionEnableTracing

Assign "enable tracing" checkable action to the tracer.

Static Methods

tracerForCanvas

Retrieve instance of this class associated with given canvas (if any).

class qgis.gui.QgsMapCanvasTracer[source]

Bases: QgsTracer

__init__(canvas: QgsMapCanvas | None, messageBar: QgsMessageBar | None = None)

Create tracer associated with a particular map canvas, optionally message bar for reporting

Parameters:
actionEnableSnapping(self) QAction | None[source]

Access to action that user may use to toggle snapping on/off. May be None if no action was associated.

Return type:

Optional[QAction]

actionEnableTracing(self) QAction | None[source]

Access to action that user may use to toggle tracing on/off. May be None if no action was associated

Return type:

Optional[QAction]

configure(self)[source]

Sets configuration from current snapping settings and canvas settings

reportError(self, err: QgsTracer.PathError, addingVertex: bool)[source]

Report a path finding error to the user

Parameters:
setActionEnableSnapping(self, action: QAction | None)[source]

Assign “enable snapping” checkable action to the tracer. The action is used to determine whether snapping is currently enabled by the user.

Parameters:

action (Optional[QAction])

setActionEnableTracing(self, action: QAction | None)[source]

Assign “enable tracing” checkable action to the tracer. The action is used to determine whether tracing is currently enabled by the user

Parameters:

action (Optional[QAction])

static tracerForCanvas(canvas: QgsMapCanvas | None) QgsMapCanvasTracer | None[source]

Retrieve instance of this class associated with given canvas (if any). The class keeps a simple registry of tracers associated with map canvas instances for easier access to the common tracer by various map tools

Parameters:

canvas (Optional[QgsMapCanvas])

Return type:

Optional[QgsMapCanvasTracer]