QgsMapCanvas class

Map canvas is a class for displaying all GIS data types on a canvas.

Public types

class CanvasProperties
Deprecated to be deleted, stuff from here should be moved elsewhere.

Constructors, destructors, conversion operators

QgsMapCanvas(QWidget* parent = nullptr)
Constructor.

Public functions

auto annotationItems() const -> QList<QgsMapCanvasAnnotationItem*>
Returns a list of all annotation items in the canvas.
auto annotationsVisible() const -> bool
Returns true if annotations are visible within the map canvas.
auto antiAliasingEnabled() const -> bool
true if antialising is enabled
auto canvasColor() const -> QColor
Read property of QColor bgColor.
auto center() const -> QgsPointXY
Gets map center, in geographical coordinates.
void clearCache()
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
auto currentLayer() -> QgsMapLayer*
returns current layer (set by legend widget)
auto defaultExpressionContextScope() -> QgsExpressionContextScope*
Creates a new scope which contains default variables and functions relating to the map canvas.
void enableAntiAliasing(bool flag)
used to determine if anti-aliasing is enabled or not
void enableMapTileRendering(bool flag)
sets map tile rendering flag
auto expressionContextScope() -> QgsExpressionContextScope&
Returns a reference to the expression context scope for the map canvas.
auto expressionContextScope() const -> const QgsExpressionContextScope&
Returns a const reference to the expression context scope for the map canvas.
auto extent() const -> QgsRectangle
Returns the current zoom extent of the map canvas.
void flashFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids, const QColor& startColor = QColor(255, 0, 0, 255), const QColor& endColor = QColor(255, 0, 0, 0), int flashes = 3, int duration = 500)
Causes a set of features with matching ids from a vector layer to flash within the canvas.
void flashGeometries(const QList<QgsGeometry>& geometries, const QgsCoordinateReferenceSystem& crs = QgsCoordinateReferenceSystem(), const QColor& startColor = QColor(255, 0, 0, 255), const QColor& endColor = QColor(255, 0, 0, 0), int flashes = 3, int duration = 500)
Causes a set of geometries to flash within the canvas.
void freeze(bool frozen = true)
Freeze/thaw the map canvas.
auto fullExtent() const -> QgsRectangle
Returns the combined extent for all layers on the map canvas.
auto getCoordinateTransform() -> const QgsMapToPixel*
Gets the current coordinate transform.
auto isCachingEnabled() const -> bool
Check whether images of rendered layers are curerently being cached.
auto isDrawing() -> bool
Find out whether rendering is in progress.
auto isFrozen() const -> bool
Returns true if canvas is frozen.
auto isParallelRenderingEnabled() const -> bool
Check whether the layers are rendered in parallel or sequentially.
auto labelingEngineSettings() const -> const QgsLabelingEngineSettings&
Returns global labeling engine settings from the internal map settings.
auto labelingResults() const -> const QgsLabelingResults*
Gets access to the labeling results (may be null)
auto layer(int index) -> QgsMapLayer*
Returns the map layer at position index in the layer stack.
auto layerCount() const -> int
Returns number of layers on the map.
auto layers() const -> QList<QgsMapLayer*>
Returns the list of layers shown within the map canvas.
auto layerStyleOverrides() const -> QMap<QString, QString>
Returns the stored overrides of styles for layers.
auto magnificationFactor() const -> double
Returns the magnification factor.
auto mapSettings() const -> const QgsMapSettings&
Gets access to properties used for map rendering.
auto mapTool() -> QgsMapTool*
Returns the currently active tool.
auto mapUnits() const -> QgsUnitTypes::DistanceUnit
Convenience function for returning the current canvas map units.
auto mapUnitsPerPixel() const -> double
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
auto mapUpdateInterval() const -> int
Find out how often map preview should be updated while it is being rendered (in milliseconds)
auto mouseLastXY() -> QPoint
returns last position of mouse cursor
void panAction(QMouseEvent* event)
Called when mouse is moving and pan is activated.
void panActionEnd(QPoint releasePoint)
Ends pan action and redraws the canvas.
void panToFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids)
Centers canvas extent to feature ids.
void panToSelected(QgsVectorLayer* layer = nullptr)
Pan to the selected features of current (vector) layer keeping same extent.
auto previewJobsEnabled() const -> bool
Returns true if canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.
auto previewMode() const -> QgsPreviewEffect::PreviewMode
Returns the current preview mode for the map canvas.
auto previewModeEnabled() const -> bool
Returns whether a preview mode is enabled for the map canvas.
auto renderFlag() const -> bool
Returns true if canvas render is disabled as a result of user disabling renders via the GUI.
auto rotation() const -> double
Gets the current map canvas rotation in clockwise degrees.
auto scale() const -> double
Returns the last reported scale of the canvas.
auto scaleLocked() const -> bool
Returns whether the scale is locked, so zooming can be performed using magnication.
auto selectionColor() const -> QColor
Returns color for selected features.
void setAnnotationsVisible(bool visible)
Sets whether annotations are visible in the canvas.
void setCachingEnabled(bool enabled)
Set whether to cache images of rendered layers.
void setCanvasColor(const QColor& _newVal)
Write property of QColor bgColor.
void setCenter(const QgsPointXY& center)
Set the center of the map canvas, in geographical coordinates.
void setDestinationCrs(const QgsCoordinateReferenceSystem& crs)
sets destination coordinate reference system
void setExpressionContextScope(const QgsExpressionContextScope& scope)
Sets an expression context scope for the map canvas.
void setExtent(const QgsRectangle& r, bool magnified = false)
Sets the extent of the map canvas.
void setLabelingEngineSettings(const QgsLabelingEngineSettings& settings)
Sets global labeling engine settings in the internal map settings.
void setLayers(const QList<QgsMapLayer*>& layers)
Sets the list of layers that should be shown in the canvas.
void setLayerStyleOverrides(const QMap<QString, QString>& overrides)
Sets the stored overrides of styles for rendering layers.
void setMapSettingsFlags(QgsMapSettings::Flags flags)
Resets the flags for the canvas' map settings.
void setMapTool(QgsMapTool* mapTool, bool clean = false)
Sets the map tool currently being used on the canvas.
void setMapUpdateInterval(int timeMilliseconds)
Set how often map preview should be updated while it is being rendered (in milliseconds)
void setParallelRenderingEnabled(bool enabled)
Set whether the layers are rendered in parallel or sequentially.
void setPreviewJobsEnabled(bool enabled)
Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.
void setPreviewMode(QgsPreviewEffect::PreviewMode mode)
Sets a preview mode for the map canvas.
void setPreviewModeEnabled(bool previewEnabled)
Enables a preview mode for the map canvas.
void setRotation(double degrees)
Set the rotation of the map canvas in clockwise degrees.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
void setSelectionColor(const QColor& color)
Set color of selected vector features.
void setSnappingUtils(QgsSnappingUtils* utils)
Assign an instance of snapping utils to the map canvas.
void setTheme(const QString& theme)
Sets a map theme to show in the canvas.
void setWheelFactor(double factor)
Sets wheel zoom factor (should be greater than 1)
auto snappingUtils() const -> QgsSnappingUtils*
Returns snapping utility class that is associated with map canvas.
auto theme() const -> QString
Returns the map's theme shown in the canvas, if set.
void unsetMapTool(QgsMapTool* mapTool)
Unset the current map tool or last non zoom tool.
void updateScale()
Emits signal scaleChanged to update scale in main window.
void waitWhileRendering()
Blocks until the rendering job has finished.
void zoomByFactor(double scaleFactor, const QgsPointXY* center = nullptr)
Zoom with the factor supplied.
void zoomScale(double scale)
Zooms the canvas to a specific scale.
void zoomToFeatureExtent(QgsRectangle& rect)
Zooms to feature extent.
void zoomToFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids)
Set canvas extent to the bounding box of a set of features.
void zoomToFullExtent()
Zoom to the full extent of all layers.
void zoomToNextExtent()
Zoom to the next extent (view)
void zoomToPreviousExtent()
Zoom to the previous extent (view)
void zoomWithCenter(int x, int y, bool zoomIn)
Zooms in/out with a given center.

Signals

void canvasColorChanged()
Emitted when canvas background color changes.
void currentLayerChanged(QgsMapLayer* layer)
Emitted when the current layer is changed.
void destinationCrsChanged()
Emitted when map CRS has changed.
void extentsChanged()
Emitted when the extents of the map change.
void keyPressed(QKeyEvent* e)
Emit key press event.
void keyReleased(QKeyEvent* e)
Emit key release event.
void layersChanged()
Emitted when a new set of layers has been received.
void layerStyleOverridesChanged()
Emitted when the configuration of overridden layer styles changes.
void magnificationChanged(double)
Emitted when the scale of the map changes.
void mapCanvasRefreshed()
Emitted when canvas finished a refresh request.
void mapToolSet(QgsMapTool* newTool, QgsMapTool* oldTool)
Emit map tool changed with the old tool.
void messageEmitted(const QString& title, const QString& message, Qgis::MessageLevel = Qgis::Info)
emit a message (usually to be displayed in a message bar)
void renderComplete(QPainter*)
Emitted when the canvas has rendered.
void renderStarting()
Emitted when the canvas is about to be rendered.
void rotationChanged(double)
Emitted when the rotation of the map changes.
void scaleChanged(double)
Emitted when the scale of the map changes.
void selectionChanged(QgsVectorLayer* layer)
Emitted when selection in any layer gets changed.
void themeChanged(const QString& theme)
Emitted when the canvas has been assigned a different map theme.
void transformContextChanged()
Emitted when the canvas transform context is changed.
void xyCoordinates(const QgsPointXY& p)
Emits current mouse position.
void zoomLastStatusChanged(bool)
Emitted when zoom last status changed.
void zoomNextStatusChanged(bool)
Emitted when zoom next status changed.

Public slots

void layerStateChange()
This slot is connected to the visibility change of one or more layers.
void readProject(const QDomDocument&)
called to read map canvas settings from project
void refresh()
Repaints the canvas map.
void refreshAllLayers()
Reload all layers, clear the cache and refresh the canvas.
void saveAsImage(const QString& fileName, QPixmap* QPixmap = nullptr, const QString& = "PNG")
Save the convtents of the map canvas to disk as an image.
void selectionChangedSlot()
Receives signal about selection change, and pass it on with layer info.
void setMagnificationFactor(double factor)
Sets the factor of magnification to apply to the map canvas.
void setRenderFlag(bool flag)
Sets whether a user has disabled canvas renders via the GUI.
void setScaleLocked(bool isLocked)
Lock the scale, so zooming can be performed using magnication.
void stopRendering()
stop rendering (if there is any right now)
void writeProject(QDomDocument&)
called to write map canvas settings to project
void zoomIn()
Zoom in with fixed factor.
void zoomOut()
Zoom out with fixed factor.
void zoomToSelected(QgsVectorLayer* layer = nullptr)
Zoom to the extent of the selected features of provided (vector) layer.

Protected functions

void dragEnterEvent(QDragEnterEvent* e) override
Overridden drag enter event.
auto event(QEvent* e) -> bool override
Overridden standard event to be gestures aware.
void keyPressEvent(QKeyEvent* e) override
Overridden key press event.
void keyReleaseEvent(QKeyEvent* e) override
Overridden key release event.
void mouseDoubleClickEvent(QMouseEvent* e) override
Overridden mouse double-click event.
void mouseMoveEvent(QMouseEvent* e) override
Overridden mouse move event.
void mousePressEvent(QMouseEvent* e) override
Overridden mouse press event.
void mouseReleaseEvent(QMouseEvent* e) override
Overridden mouse release event.
void moveCanvasContents(bool reset = false)
called when panning is in action, reset indicates end of panning
void paintEvent(QPaintEvent* e) override
Overridden paint event.
void resizeEvent(QResizeEvent* e) override
Overridden resize event.
void wheelEvent(QWheelEvent* e) override
Overridden mouse wheel event.

Protected slots

void updateCanvasItemPositions()
called on resize or changed extent to notify canvas items to change their rectangle

Protected variables

std::unique_ptr<CanvasProperties> mCanvasProperties
Handle pattern for implementation object.

Function documentation

QList<QgsMapCanvasAnnotationItem*> QgsMapCanvas::annotationItems() const

Returns a list of all annotation items in the canvas.

bool QgsMapCanvas::annotationsVisible() const

Returns true if annotations are visible within the map canvas.

QgsPointXY QgsMapCanvas::center() const

Gets map center, in geographical coordinates.

void QgsMapCanvas::clearCache()

Make sure to remove any rendered images from cache (does nothing if cache is not enabled)

QgsExpressionContextScope* QgsMapCanvas::defaultExpressionContextScope()

Creates a new scope which contains default variables and functions relating to the map canvas.

QgsExpressionContextScope& QgsMapCanvas::expressionContextScope()

Returns a reference to the expression context scope for the map canvas.

This scope is injected into the expression context used for rendering the map, and can be used to apply specific variable overrides for expression evaluation for the map canvas render.

const QgsExpressionContextScope& QgsMapCanvas::expressionContextScope() const

Returns a const reference to the expression context scope for the map canvas.

void QgsMapCanvas::flashFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids, const QColor& startColor = QColor(255, 0, 0, 255), const QColor& endColor = QColor(255, 0, 0, 0), int flashes = 3, int duration = 500)

Causes a set of features with matching ids from a vector layer to flash within the canvas.

The startColor and endColor can be specified, along with the number of flashes and duration of each flash (in milliseconds).

void QgsMapCanvas::flashGeometries(const QList<QgsGeometry>& geometries, const QgsCoordinateReferenceSystem& crs = QgsCoordinateReferenceSystem(), const QColor& startColor = QColor(255, 0, 0, 255), const QColor& endColor = QColor(255, 0, 0, 0), int flashes = 3, int duration = 500)

Causes a set of geometries to flash within the canvas.

If crs is a valid coordinate reference system, the geometries will be automatically transformed from this CRS to the canvas CRS.

The startColor and endColor can be specified, along with the number of flashes and duration of each flash (in milliseconds).

void QgsMapCanvas::freeze(bool frozen = true)

Freeze/thaw the map canvas.

Parameters
frozen Boolean specifying if the canvas should be frozen (true) or thawed (false). Default is true.

This is used to prevent the canvas from responding to events while layers are being added/removed etc.

bool QgsMapCanvas::isCachingEnabled() const

Check whether images of rendered layers are curerently being cached.

bool QgsMapCanvas::isFrozen() const

Returns true if canvas is frozen.

bool QgsMapCanvas::isParallelRenderingEnabled() const

Check whether the layers are rendered in parallel or sequentially.

const QgsLabelingEngineSettings& QgsMapCanvas::labelingEngineSettings() const

Returns global labeling engine settings from the internal map settings.

const QgsLabelingResults* QgsMapCanvas::labelingResults() const

Gets access to the labeling results (may be null)

QList<QgsMapLayer*> QgsMapCanvas::layers() const

Returns the list of layers shown within the map canvas.

QMap<QString, QString> QgsMapCanvas::layerStyleOverrides() const

Returns the stored overrides of styles for layers.

double QgsMapCanvas::magnificationFactor() const

Returns the magnification factor.

const QgsMapSettings& QgsMapCanvas::mapSettings() const

Gets access to properties used for map rendering.

QgsUnitTypes::DistanceUnit QgsMapCanvas::mapUnits() const

Convenience function for returning the current canvas map units.

The map units are dictated by the canvas' destinationCrs() map units.

int QgsMapCanvas::mapUpdateInterval() const

Find out how often map preview should be updated while it is being rendered (in milliseconds)

void QgsMapCanvas::panToFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids)

Centers canvas extent to feature ids.

Parameters
layer the vector layer
ids the feature ids

bool QgsMapCanvas::previewJobsEnabled() const

Returns true if canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.

QgsPreviewEffect::PreviewMode QgsMapCanvas::previewMode() const

Returns the current preview mode for the map canvas.

Returns preview mode for map canvas

This setting only has an effect if previewModeEnabled is true.

bool QgsMapCanvas::previewModeEnabled() const

Returns whether a preview mode is enabled for the map canvas.

Returns true if a preview mode is currently enabled

bool QgsMapCanvas::renderFlag() const

Returns true if canvas render is disabled as a result of user disabling renders via the GUI.

double QgsMapCanvas::rotation() const

Gets the current map canvas rotation in clockwise degrees.

double QgsMapCanvas::scale() const

Returns the last reported scale of the canvas.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

bool QgsMapCanvas::scaleLocked() const

Returns whether the scale is locked, so zooming can be performed using magnication.

QColor QgsMapCanvas::selectionColor() const

Returns color for selected features.

void QgsMapCanvas::setAnnotationsVisible(bool visible)

Sets whether annotations are visible in the canvas.

void QgsMapCanvas::setCachingEnabled(bool enabled)

Set whether to cache images of rendered layers.

void QgsMapCanvas::setCenter(const QgsPointXY& center)

Set the center of the map canvas, in geographical coordinates.

void QgsMapCanvas::setDestinationCrs(const QgsCoordinateReferenceSystem& crs)

sets destination coordinate reference system

void QgsMapCanvas::setExpressionContextScope(const QgsExpressionContextScope& scope)

Sets an expression context scope for the map canvas.

Parameters
scope new expression context scope

This scope is injected into the expression context used for rendering the map, and can be used to apply specific variable overrides for expression evaluation for the map canvas render. This method will overwrite the existing expression context scope for the canvas.

void QgsMapCanvas::setLabelingEngineSettings(const QgsLabelingEngineSettings& settings)

Sets global labeling engine settings in the internal map settings.

void QgsMapCanvas::setLayers(const QList<QgsMapLayer*>& layers)

Sets the list of layers that should be shown in the canvas.

If the map canvas has been associated with a map theme via a call to setTheme(), then any calls to setLayers() are ignored. It is necessary to first clear the theme association by calling setTheme() with an empty string before setLayers() calls can be made.

void QgsMapCanvas::setLayerStyleOverrides(const QMap<QString, QString>& overrides)

Sets the stored overrides of styles for rendering layers.

If the map canvas has been associated with a map theme via a call to setTheme(), then any calls to setLayerStyleOverrides() are ignored. It is necessary to first clear the theme association by calling setTheme() with an empty string before setLayerStyleOverrides() calls can be made.

void QgsMapCanvas::setMapSettingsFlags(QgsMapSettings::Flags flags)

Resets the flags for the canvas' map settings.

void QgsMapCanvas::setMapUpdateInterval(int timeMilliseconds)

Set how often map preview should be updated while it is being rendered (in milliseconds)

void QgsMapCanvas::setParallelRenderingEnabled(bool enabled)

Set whether the layers are rendered in parallel or sequentially.

void QgsMapCanvas::setPreviewJobsEnabled(bool enabled)

Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just outside of the canvas extent, to allow preview of these out-of-canvas areas when panning or zooming out the map) are enabled for the canvas.

void QgsMapCanvas::setPreviewMode(QgsPreviewEffect::PreviewMode mode)

Sets a preview mode for the map canvas.

Parameters
mode preview mode for the canvas

This setting only has an effect if previewModeEnabled is true.

void QgsMapCanvas::setPreviewModeEnabled(bool previewEnabled)

Enables a preview mode for the map canvas.

Parameters
previewEnabled set to true to enable a preview mode

void QgsMapCanvas::setRotation(double degrees)

Set the rotation of the map canvas in clockwise degrees.

void QgsMapCanvas::setSegmentationTolerance(double tolerance)

Sets the segmentation tolerance applied when rendering curved geometries.

Parameters
tolerance the segmentation tolerance

void QgsMapCanvas::setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)

Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

Parameters
type the segmentation tolerance typename

void QgsMapCanvas::setSelectionColor(const QColor& color)

Set color of selected vector features.

void QgsMapCanvas::setSnappingUtils(QgsSnappingUtils* utils)

Assign an instance of snapping utils to the map canvas.

The instance is not owned by the canvas, so it is possible to use one instance in multiple canvases.

For main canvas in QGIS, do not associate a different instance from the existing one (it is updated from the project's snapping configuration).

void QgsMapCanvas::setTheme(const QString& theme)

Sets a map theme to show in the canvas.

The theme name must match a theme present in the associated project's QgsMapThemeCollection.

When the canvas is associated to a map theme, it will automatically follow the layer selection and layer styles from that theme. Calls to setLayers() or setLayerStyleOverrides() will have no effect, and canvases associated with a QgsLayerTreeMapCanvasBridge will no longer synchronize their state with the layer tree. In these cases it is necessary to call setTheme() with an empty string to clear the theme association and allow map updates with setLayers(), setLayerStyleOverrides(), or via QgsLayerTreeMapCanvasBridge.

If an empty string is passed then the current theme association will be cleared.

QgsSnappingUtils* QgsMapCanvas::snappingUtils() const

Returns snapping utility class that is associated with map canvas.

If no snapping utils instance has been associated previously, an internal will be created for convenience (so map tools do not need to test for existence of the instance).

Main canvas in QGIS returns an instance which is always up-to-date with the project's snapping configuration.

QString QgsMapCanvas::theme() const

Returns the map's theme shown in the canvas, if set.

void QgsMapCanvas::unsetMapTool(QgsMapTool* mapTool)

Unset the current map tool or last non zoom tool.

This is called from destructor of map tools to make sure that this map tool won't be used any more. You don't have to call it manually, QgsMapTool takes care of it.

void QgsMapCanvas::waitWhileRendering()

Blocks until the rendering job has finished.

In almost all cases you do NOT want to call this, as it will hang the UI until the rendering job is complete. It's included in API solely for unit testing and standalone Python scripts.

void QgsMapCanvas::zoomByFactor(double scaleFactor, const QgsPointXY* center = nullptr)

Zoom with the factor supplied.

Factor > 1 zooms out, interval (0,1) zooms in If point is given, re-center on it

void QgsMapCanvas::zoomScale(double scale)

Zooms the canvas to a specific scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

void QgsMapCanvas::zoomToFeatureExtent(QgsRectangle& rect)

Zooms to feature extent.

Adds a small margin around the extent and does a pan if rect is empty (point extent)

void QgsMapCanvas::zoomToFeatureIds(QgsVectorLayer* layer, const QgsFeatureIds& ids)

Set canvas extent to the bounding box of a set of features.

Parameters
layer the vector layer
ids the feature ids

void QgsMapCanvas::canvasColorChanged() signal

Emitted when canvas background color changes.

void QgsMapCanvas::currentLayerChanged(QgsMapLayer* layer) signal

Emitted when the current layer is changed.

void QgsMapCanvas::destinationCrsChanged() signal

Emitted when map CRS has changed.

void QgsMapCanvas::layerStyleOverridesChanged() signal

Emitted when the configuration of overridden layer styles changes.

void QgsMapCanvas::magnificationChanged(double) signal

Emitted when the scale of the map changes.

void QgsMapCanvas::mapToolSet(QgsMapTool* newTool, QgsMapTool* oldTool) signal

Emit map tool changed with the old tool.

void QgsMapCanvas::renderComplete(QPainter*) signal

Emitted when the canvas has rendered.

Passes a pointer to the painter on which the map was drawn. This is useful for plugins that wish to draw on the map after it has been rendered. Passing the painter allows plugins to work when the map is being rendered onto a pixmap other than the mapCanvas own pixmap member. TODO: deprecate when decorations are reimplemented as map canvas items

  • anything related to rendering progress is not visible outside of map canvas
  • additional drawing shall be done directly within the renderer job or independently as a map canvas item

void QgsMapCanvas::rotationChanged(double) signal

Emitted when the rotation of the map changes.

void QgsMapCanvas::themeChanged(const QString& theme) signal

Emitted when the canvas has been assigned a different map theme.

void QgsMapCanvas::transformContextChanged() signal

Emitted when the canvas transform context is changed.

void QgsMapCanvas::xyCoordinates(const QgsPointXY& p) signal

Emits current mouse position.

void QgsMapCanvas::refreshAllLayers() public slot

Reload all layers, clear the cache and refresh the canvas.

void QgsMapCanvas::setMagnificationFactor(double factor) public slot

Sets the factor of magnification to apply to the map canvas.

Indeed, we increase/decrease the DPI of the map settings according to this factor in order to render marker point, labels, ... bigger.

void QgsMapCanvas::setRenderFlag(bool flag) public slot

Sets whether a user has disabled canvas renders via the GUI.

Parameters
flag set to false to indicate that user has disabled renders

void QgsMapCanvas::setScaleLocked(bool isLocked) public slot

Lock the scale, so zooming can be performed using magnication.

void QgsMapCanvas::stopRendering() public slot

stop rendering (if there is any right now)

void QgsMapCanvas::zoomToSelected(QgsVectorLayer* layer = nullptr) public slot

Zoom to the extent of the selected features of provided (vector) layer.

Parameters
layer optionally specify different than current layer