QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
Classes | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Properties | Friends | List of all members
QgsMapCanvas Class Reference

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

#include <qgsmapcanvas.h>

Inheritance diagram for QgsMapCanvas:
Inheritance graph
[legend]

Classes

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

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 redrawAllLayers ()
 Clears all cached images and redraws all layers.
 
void refresh ()
 Repaints the canvas map.
 
void refreshAllLayers ()
 Reload all layers (including refreshing layer properties from their data sources), clears the cache and refreshes the canvas.
 
void saveAsImage (const QString &fileName, QPixmap *QPixmap=nullptr, const QString &="PNG")
 Save the contents 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, const QgsPointXY *center=nullptr)
 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 setZoomResolutions (const QList< double > &resolutions)
 Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map.
 
void setZRange (const QgsDoubleRange &range)
 Sets the range of z-values which will be visible in the map.
 
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.
 
double zoomInFactor () const
 Returns the zoom in factor.
 
void zoomOut ()
 Zoom out with fixed factor.
 
double zoomOutFactor () const
 Returns the zoom in factor.
 
const QList< double > & zoomResolutions () const
 
void zoomToSelected (const QList< QgsMapLayer * > &layers)
 Zoom to the combined extent of the selected features of all provided (vector) layers.
 
void zoomToSelected (QgsMapLayer *layer=nullptr)
 Zoom to the extent of the selected features of provided map layer.
 
QgsDoubleRange zRange () const
 Returns the range of z-values which will be visible in the map.
 

Signals

void canvasColorChanged ()
 Emitted when canvas background color changes.
 
void contextMenuAboutToShow (QMenu *menu, QgsMapMouseEvent *event)
 Emitted before the map canvas context menu will be shown.
 
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 magnification)
 Emitted when the scale of the map changes.
 
void mapCanvasRefreshed ()
 Emitted when canvas finished a refresh request.
 
void mapRefreshCanceled ()
 Emitted when the pending map refresh has been canceled.
 
void mapToolSet (QgsMapTool *newTool, QgsMapTool *oldTool)
 Emit map tool changed with the old tool.
 
void messageEmitted (const QString &title, const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
 emit a message (usually to be displayed in a message bar)
 
void panDistanceBearingChanged (double distance, Qgis::DistanceUnit unit, double bearing)
 Emitted whenever the distance or bearing of an in-progress panning operation is changed.
 
void renderComplete (QPainter *painter)
 Emitted when the canvas has rendered.
 
void renderErrorOccurred (const QString &error, QgsMapLayer *layer)
 Emitted whenever an error is encountered during a map render operation.
 
void renderStarting ()
 Emitted when the canvas is about to be rendered.
 
void rotationChanged (double rotation)
 Emitted when the rotation of the map changes.
 
void scaleChanged (double scale)
 Emitted when the scale of the map changes.
 
void scaleLockChanged (bool locked)
 Emitted when the scale locked state of the map changes.
 
void selectionChanged (QgsMapLayer *layer)
 Emitted when selection in any layer gets changed.
 
void tapAndHoldGestureOccurred (const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
 Emitted whenever a tap and hold gesture occurs at the specified map point.
 
void temporalRangeChanged ()
 Emitted when the map canvas temporal range changes.
 
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 available)
 Emitted when zoom last status changed.
 
void zoomNextStatusChanged (bool available)
 Emitted when zoom next status changed.
 
void zRangeChanged ()
 Emitted when the map canvas z (elevation) range changes.
 

Public Member Functions

 QgsMapCanvas (QWidget *parent=nullptr)
 Constructor.
 
 ~QgsMapCanvas () override
 
void addOverlayWidget (QWidget *widget, Qt::Edge edge)
 Adds an overlay widget to the layout, which will be bound to the specified edge.
 
bool allowInteraction (QgsMapCanvasInteractionBlocker::Interaction interaction) const
 Returns true if the specified interaction is currently permitted on the canvas.
 
QList< QgsMapCanvasAnnotationItem * > annotationItems () const
 Returns a list of all annotation items in the canvas.
 
bool annotationsVisible () const
 Returns true if annotations are visible within the map canvas.
 
bool antiAliasingEnabled () const
 true if antialiasing is enabled
 
QgsMapRendererCachecache ()
 Returns the map renderer cache, if caching is enabled.
 
void cancelJobs ()
 Cancel any rendering job, in a blocking way.
 
QColor canvasColor () const
 Read property of QColor bgColor.
 
QgsPointXY center () const
 Gets map center, in geographical coordinates.
 
void clearCache ()
 Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
 
void clearExtentHistory ()
 Clears the list of extents and sets current extent as first item.
 
QgsExpressionContext createExpressionContext () const override
 This method needs to be reimplemented in all classes which implement this interface and return an expression context.
 
QgsMapLayercurrentLayer ()
 returns current layer (set by legend widget)
 
QgsExpressionContextScopedefaultExpressionContextScope () const
 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
 
QgsExpressionContextScopeexpressionContextScope ()
 Returns a reference to the expression context scope for the map canvas.
 
const QgsExpressionContextScopeexpressionContextScope () const
 Returns a const reference to the expression context scope for the map canvas.
 
QgsRectangle extent () const
 Returns the current zoom extent of the map canvas.
 
Qgis::MapCanvasFlags flags () const
 Returns flags which control how the map canvas behaves.
 
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)
 Freezes/thaws the map canvas.
 
QgsRectangle fullExtent () const
 Returns the combined extent for all layers on the map canvas.
 
const QgsMapToPixelgetCoordinateTransform ()
 Gets the current coordinate transform.
 
void installInteractionBlocker (QgsMapCanvasInteractionBlocker *blocker)
 Installs an interaction blocker onto the canvas, which may prevent certain map canvas interactions from occurring.
 
bool isCachingEnabled () const
 Check whether images of rendered layers are curerently being cached.
 
bool isDrawing ()
 Find out whether rendering is in progress.
 
bool isFrozen () const
 Returns true if canvas is frozen.
 
bool isParallelRenderingEnabled () const
 Check whether the layers are rendered in parallel or sequentially.
 
const QgsLabelingEngineSettingslabelingEngineSettings () const
 Returns global labeling engine settings from the internal map settings.
 
const QgsLabelingResultslabelingResults (bool allowOutdatedResults=true) const
 Gets access to the labeling results (may be nullptr).
 
QgsMapLayerlayer (const QString &id)
 Returns the map layer with the matching ID, or nullptr if no layers could be found.
 
QgsMapLayerlayer (int index)
 Returns the map layer at position index in the layer stack.
 
int layerCount () const
 Returns number of layers on the map.
 
template<typename T >
QVector< T > layers () const
 Returns a list of registered map layers with a specified layer type.
 
QList< QgsMapLayer * > layers (bool expandGroupLayers=false) const
 Returns the list of layers shown within the map canvas.
 
QMap< QString, QString > layerStyleOverrides () const
 Returns the stored overrides of styles for layers.
 
double magnificationFactor () const
 Returns the magnification factor.
 
QgsMapSettingsmapSettings ()
 Returns a reference to the map settings used for map rendering.
 
const QgsMapSettingsmapSettings () const
 Gets access to properties used for map rendering.
 
QgsMapToolmapTool () const
 Returns the currently active tool.
 
Qgis::DistanceUnit mapUnits () const
 Convenience function for returning the current canvas map units.
 
double mapUnitsPerPixel () const
 Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
 
int mapUpdateInterval () const
 Find out how often map preview should be updated while it is being rendered (in milliseconds)
 
QPoint mouseLastXY ()
 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 panActionStart (QPoint releasePoint)
 Starts a pan action.
 
void panToFeatureIds (QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter=true)
 Centers canvas extent to feature ids.
 
void panToSelected (const QList< QgsMapLayer * > &layers)
 Pan to the combined extent of the selected features of all provided (vector) layers.
 
void panToSelected (QgsMapLayer *layer=nullptr)
 Pan to the selected features of current ayer keeping same extent.
 
bool 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 previewMode () const
 Returns the current preview mode for the map canvas.
 
bool previewModeEnabled () const
 Returns whether a preview mode is enabled for the map canvas.
 
QgsProjectproject ()
 Returns the project linked to this canvas.
 
QgsRectangle projectExtent () const
 Returns the associated project's full extent, in the canvas' CRS.
 
void removeInteractionBlocker (QgsMapCanvasInteractionBlocker *blocker)
 Removes an interaction blocker from the canvas.
 
const QgsRenderedItemResultsrenderedItemResults (bool allowOutdatedResults=true) const
 Gets access to the rendered item results (may be nullptr), which includes the results of rendering annotation items in the canvas map.
 
bool renderFlag () const
 Returns true if canvas render is disabled as a result of user disabling renders via the GUI.
 
double rotation () const
 Gets the current map canvas rotation in clockwise degrees.
 
double scale () const
 Returns the last reported scale of the canvas.
 
bool scaleLocked () const
 Returns whether the scale is locked, so zooming can be performed using magnication.
 
QColor selectionColor () const
 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 setCurrentLayer (QgsMapLayer *layer)
 
void setCustomDropHandlers (const QVector< QPointer< QgsCustomDropHandler > > &handlers)
 Sets a list of custom drop handlers to use when drop events occur on the canvas.
 
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 to the specified rectangle.
 
void setFlags (Qgis::MapCanvasFlags flags)
 Sets flags which control how the map canvas behaves.
 
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 setMapController (QgsAbstract2DMapController *controller)
 Sets the input controller device to use for controlling the canvas.
 
void setMapSettingsFlags (Qgis::MapSettingsFlags 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 setProject (QgsProject *project)
 Sets the project linked to this canvas.
 
bool setReferencedExtent (const QgsReferencedRectangle &extent)
 Sets the canvas to the specified extent.
 
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 setTemporalController (QgsTemporalController *controller)
 Sets the temporal controller for this canvas.
 
void setTemporalRange (const QgsDateTimeRange &range)
 Set datetime range for 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)
 
QgsSnappingUtilssnappingUtils () const
 Returns snapping utility class that is associated with map canvas.
 
const QgsTemporalControllertemporalController () const
 Gets access to the temporal controller that will be used to update the canvas temporal range.
 
const QgsDateTimeRangetemporalRange () const
 Returns map canvas datetime range.
 
QString theme () const
 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, bool ignoreScaleLock=false)
 Zoom with the factor supplied.
 
void zoomScale (double scale, bool ignoreScaleLock=false)
 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 currently visible in the canvas.
 
void zoomToNextExtent ()
 Zoom to the next extent (view)
 
void zoomToPreviousExtent ()
 Zoom to the previous extent (view)
 
void zoomToProjectExtent ()
 Zoom to the full extent the project associated with this canvas.
 
void zoomWithCenter (int x, int y, bool zoomIn)
 Zooms in/out with a given center.
 
- Public Member Functions inherited from QgsExpressionContextGenerator
virtual ~QgsExpressionContextGenerator ()=default
 

Protected Slots

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

Protected Member Functions

void dragEnterEvent (QDragEnterEvent *e) override
 
void dropEvent (QDropEvent *event) override
 
void emitExtentsChanged ()
 Emits the extentsChanged signal when appropriate.
 
bool event (QEvent *e) override
 
void keyPressEvent (QKeyEvent *e) override
 
void keyReleaseEvent (QKeyEvent *e) override
 
void mouseDoubleClickEvent (QMouseEvent *e) override
 
void mouseMoveEvent (QMouseEvent *e) override
 
void mousePressEvent (QMouseEvent *e) override
 
void mouseReleaseEvent (QMouseEvent *e) override
 
void moveCanvasContents (bool reset=false)
 called when panning is in action, reset indicates end of panning
 
void paintEvent (QPaintEvent *e) override
 
void resizeEvent (QResizeEvent *e) override
 
void showEvent (QShowEvent *event) override
 
bool viewportEvent (QEvent *event) override
 
void wheelEvent (QWheelEvent *e) override
 

Protected Attributes

std::unique_ptr< CanvasPropertiesmCanvasProperties
 Handle pattern for implementation object.
 

Properties

bool previewJobsEnabled
 
QString theme
 

Friends

class TestQgsMapCanvas
 

Detailed Description

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

Definition at line 92 of file qgsmapcanvas.h.

Constructor & Destructor Documentation

◆ QgsMapCanvas()

QgsMapCanvas::QgsMapCanvas ( QWidget *  parent = nullptr)

Constructor.

Definition at line 129 of file qgsmapcanvas.cpp.

◆ ~QgsMapCanvas()

QgsMapCanvas::~QgsMapCanvas ( )
override

Definition at line 258 of file qgsmapcanvas.cpp.

Member Function Documentation

◆ addOverlayWidget()

void QgsMapCanvas::addOverlayWidget ( QWidget *  widget,
Qt::Edge  edge 
)

Adds an overlay widget to the layout, which will be bound to the specified edge.

The widget will always float above the map canvas.

Note
Widgets on the left and right edges will always be positioned first, with top and bottom edge widgets expanding to take the remaining horizontal space.
Since
QGIS 3.38

Definition at line 289 of file qgsmapcanvas.cpp.

◆ allowInteraction()

bool QgsMapCanvas::allowInteraction ( QgsMapCanvasInteractionBlocker::Interaction  interaction) const

Returns true if the specified interaction is currently permitted on the canvas.

Since
QGIS 3.14

Definition at line 1399 of file qgsmapcanvas.cpp.

◆ annotationItems()

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

Returns a list of all annotation items in the canvas.

Definition at line 3507 of file qgsmapcanvas.cpp.

◆ annotationsVisible()

bool QgsMapCanvas::annotationsVisible ( ) const
inline

Returns true if annotations are visible within the map canvas.

See also
setAnnotationsVisible()

Definition at line 808 of file qgsmapcanvas.h.

◆ antiAliasingEnabled()

bool QgsMapCanvas::antiAliasingEnabled ( ) const

true if antialiasing is enabled

Definition at line 343 of file qgsmapcanvas.cpp.

◆ cache()

QgsMapRendererCache * QgsMapCanvas::cache ( )

Returns the map renderer cache, if caching is enabled.

See also
isCachingEnabled()
setCachingEnabled()
Since
QGIS 3.32

Definition at line 680 of file qgsmapcanvas.cpp.

◆ cancelJobs()

void QgsMapCanvas::cancelJobs ( )

Cancel any rendering job, in a blocking way.

Used for application closing.

Note
not available in Python bindings

Definition at line 294 of file qgsmapcanvas.cpp.

◆ canvasColor()

QColor QgsMapCanvas::canvasColor ( ) const

Read property of QColor bgColor.

Definition at line 2885 of file qgsmapcanvas.cpp.

◆ canvasColorChanged

void QgsMapCanvas::canvasColorChanged ( )
signal

Emitted when canvas background color changes.

◆ center()

QgsPointXY QgsMapCanvas::center ( ) const

Gets map center, in geographical coordinates.

Definition at line 1651 of file qgsmapcanvas.cpp.

◆ clearCache()

void QgsMapCanvas::clearCache ( )

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

Definition at line 669 of file qgsmapcanvas.cpp.

◆ clearExtentHistory()

void QgsMapCanvas::clearExtentHistory ( )

Clears the list of extents and sets current extent as first item.

Definition at line 1743 of file qgsmapcanvas.cpp.

◆ contextMenuAboutToShow

void QgsMapCanvas::contextMenuAboutToShow ( QMenu *  menu,
QgsMapMouseEvent event 
)
signal

Emitted before the map canvas context menu will be shown.

Can be used to extend the context menu.

Since
QGIS 3.16

◆ createExpressionContext()

QgsExpressionContext QgsMapCanvas::createExpressionContext ( ) const
overridevirtual

This method needs to be reimplemented in all classes which implement this interface and return an expression context.

Implements QgsExpressionContextGenerator.

Definition at line 718 of file qgsmapcanvas.cpp.

◆ currentLayer()

QgsMapLayer * QgsMapCanvas::currentLayer ( )

returns current layer (set by legend widget)

Definition at line 706 of file qgsmapcanvas.cpp.

◆ currentLayerChanged

void QgsMapCanvas::currentLayerChanged ( QgsMapLayer layer)
signal

Emitted when the current layer is changed.

◆ defaultExpressionContextScope()

QgsExpressionContextScope * QgsMapCanvas::defaultExpressionContextScope ( ) const

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

See also
expressionContextScope()
setExpressionContextScope()
Since
QGIS 3.4

Definition at line 711 of file qgsmapcanvas.cpp.

◆ destinationCrsChanged

void QgsMapCanvas::destinationCrsChanged ( )
signal

Emitted when map CRS has changed.

◆ dragEnterEvent()

void QgsMapCanvas::dragEnterEvent ( QDragEnterEvent *  e)
overrideprotected

Definition at line 3392 of file qgsmapcanvas.cpp.

◆ dropEvent()

void QgsMapCanvas::dropEvent ( QDropEvent *  event)
overrideprotected

Definition at line 3155 of file qgsmapcanvas.cpp.

◆ emitExtentsChanged()

void QgsMapCanvas::emitExtentsChanged ( )
protected

Emits the extentsChanged signal when appropriate.

Since
QGIS 3.30

Definition at line 3195 of file qgsmapcanvas.cpp.

◆ enableAntiAliasing()

void QgsMapCanvas::enableAntiAliasing ( bool  flag)

used to determine if anti-aliasing is enabled or not

Definition at line 337 of file qgsmapcanvas.cpp.

◆ enableMapTileRendering()

void QgsMapCanvas::enableMapTileRendering ( bool  flag)

sets map tile rendering flag

Definition at line 348 of file qgsmapcanvas.cpp.

◆ event()

bool QgsMapCanvas::event ( QEvent *  e)
overrideprotected

Definition at line 3445 of file qgsmapcanvas.cpp.

◆ expressionContextScope() [1/2]

QgsExpressionContextScope & QgsMapCanvas::expressionContextScope ( )
inline

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.

See also
setExpressionContextScope()
defaultExpressionContextScope()

Definition at line 767 of file qgsmapcanvas.h.

◆ expressionContextScope() [2/2]

const QgsExpressionContextScope & QgsMapCanvas::expressionContextScope ( ) const
inline

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

See also
setExpressionContextScope()
defaultExpressionContextScope()
Note
not available in Python bindings

Definition at line 775 of file qgsmapcanvas.h.

◆ extent()

QgsRectangle QgsMapCanvas::extent ( ) const

Returns the current zoom extent of the map canvas.

Definition at line 1520 of file qgsmapcanvas.cpp.

◆ extentsChanged

void QgsMapCanvas::extentsChanged ( )
signal

Emitted when the extents of the map change.

◆ flags()

Qgis::MapCanvasFlags QgsMapCanvas::flags ( ) const

Returns flags which control how the map canvas behaves.

See also
setFlags()
Since
QGIS 3.40

Definition at line 417 of file qgsmapcanvas.cpp.

◆ flashFeatureIds()

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).

Note
If the features or geometries are already available, flashGeometries() is much more efficient.
See also
flashGeometries()

Definition at line 2204 of file qgsmapcanvas.cpp.

◆ flashGeometries()

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).

See also
flashFeatureIds()

Definition at line 2227 of file qgsmapcanvas.cpp.

◆ freeze()

void QgsMapCanvas::freeze ( bool  frozen = true)

Freezes/thaws the map canvas.

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

Parameters
frozenBoolean specifying if the canvas should be frozen (true) or thawed (false). Default is true.
See also
isFrozen()
setRenderFlag()
Note
freeze() should be used to programmatically halt map updates, while setRenderFlag() should only be used when users disable rendering via GUI.

Definition at line 2940 of file qgsmapcanvas.cpp.

◆ fullExtent()

QgsRectangle QgsMapCanvas::fullExtent ( ) const

Returns the combined extent for all layers on the map canvas.

This method returns the combined extent for all layers which are currently visible in the map canvas. The returned extent will be in the same CRS as the map canvas.

See also
projectExtent()

Definition at line 1525 of file qgsmapcanvas.cpp.

◆ getCoordinateTransform()

const QgsMapToPixel * QgsMapCanvas::getCoordinateTransform ( )

Gets the current coordinate transform.

Definition at line 398 of file qgsmapcanvas.cpp.

◆ installInteractionBlocker()

void QgsMapCanvas::installInteractionBlocker ( QgsMapCanvasInteractionBlocker blocker)

Installs an interaction blocker onto the canvas, which may prevent certain map canvas interactions from occurring.

The caller retains ownership of blocker, and must correctly call removeInteractionBlocker() before deleting the object.

See also
allowInteraction()
removeInteractionBlocker()
Since
QGIS 3.14

Definition at line 1389 of file qgsmapcanvas.cpp.

◆ isCachingEnabled()

bool QgsMapCanvas::isCachingEnabled ( ) const

Check whether images of rendered layers are curerently being cached.

See also
setCachingEnabled()
cache()

Definition at line 664 of file qgsmapcanvas.cpp.

◆ isDrawing()

bool QgsMapCanvas::isDrawing ( )

Find out whether rendering is in progress.

Definition at line 391 of file qgsmapcanvas.cpp.

◆ isFrozen()

bool QgsMapCanvas::isFrozen ( ) const

Returns true if canvas is frozen.

See also
freeze()
renderFlag()
Note
isFrozen() should be used to determine whether map updates have been halted programmatically, while renderFlag() should be used to determine whether a user has disabled rendering via GUI.

Definition at line 2945 of file qgsmapcanvas.cpp.

◆ isParallelRenderingEnabled()

bool QgsMapCanvas::isParallelRenderingEnabled ( ) const

Check whether the layers are rendered in parallel or sequentially.

Definition at line 690 of file qgsmapcanvas.cpp.

◆ keyPressed

void QgsMapCanvas::keyPressed ( QKeyEvent *  e)
signal

Emit key press event.

◆ keyPressEvent()

void QgsMapCanvas::keyPressEvent ( QKeyEvent *  e)
overrideprotected

Definition at line 2306 of file qgsmapcanvas.cpp.

◆ keyReleased

void QgsMapCanvas::keyReleased ( QKeyEvent *  e)
signal

Emit key release event.

◆ keyReleaseEvent()

void QgsMapCanvas::keyReleaseEvent ( QKeyEvent *  e)
overrideprotected

Definition at line 2406 of file qgsmapcanvas.cpp.

◆ labelingEngineSettings()

const QgsLabelingEngineSettings & QgsMapCanvas::labelingEngineSettings ( ) const

Returns global labeling engine settings from the internal map settings.

Definition at line 3538 of file qgsmapcanvas.cpp.

◆ labelingResults()

const QgsLabelingResults * QgsMapCanvas::labelingResults ( bool  allowOutdatedResults = true) const

Gets access to the labeling results (may be nullptr).

Since QGIS 3.20, if the allowOutdatedResults flag is false then outdated labeling results (e.g. as a result of an ongoing canvas render) will not be returned, and instead nullptr will be returned.

Definition at line 625 of file qgsmapcanvas.cpp.

◆ layer() [1/2]

QgsMapLayer * QgsMapCanvas::layer ( const QString &  id)

Returns the map layer with the matching ID, or nullptr if no layers could be found.

This method searches both layers associated with the map canvas (see layers()) and layers from the QgsProject associated with the canvas (which is current the QgsProject::instance()). It can be used to resolve layer IDs to layers which may be visible in the canvas, but not associated with a QgsProject.

Since
QGIS 3.22

Definition at line 362 of file qgsmapcanvas.cpp.

◆ layer() [2/2]

QgsMapLayer * QgsMapCanvas::layer ( int  index)

Returns the map layer at position index in the layer stack.

Definition at line 353 of file qgsmapcanvas.cpp.

◆ layerCount()

int QgsMapCanvas::layerCount ( ) const

Returns number of layers on the map.

Definition at line 2924 of file qgsmapcanvas.cpp.

◆ layers() [1/2]

template<typename T >
QVector< T > QgsMapCanvas::layers ( ) const
inline

Returns a list of registered map layers with a specified layer type.

Note
not available in Python bindings
Since
QGIS 3.40

Definition at line 534 of file qgsmapcanvas.h.

◆ layers() [2/2]

QList< QgsMapLayer * > QgsMapCanvas::layers ( bool  expandGroupLayers = false) const

Returns the list of layers shown within the map canvas.

Since QGIS 3.24, if the expandGroupLayers option is true then group layers will be converted to all their child layers.

See also
setLayers()

Definition at line 2929 of file qgsmapcanvas.cpp.

◆ layersChanged

void QgsMapCanvas::layersChanged ( )
signal

Emitted when a new set of layers has been received.

◆ layerStateChange

void QgsMapCanvas::layerStateChange ( )
slot

This slot is connected to the visibility change of one or more layers.

Definition at line 2934 of file qgsmapcanvas.cpp.

◆ layerStyleOverrides()

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

Returns the stored overrides of styles for layers.

See also
setLayerStyleOverrides().

Definition at line 2960 of file qgsmapcanvas.cpp.

◆ layerStyleOverridesChanged

void QgsMapCanvas::layerStyleOverridesChanged ( )
signal

Emitted when the configuration of overridden layer styles changes.

◆ magnificationChanged

void QgsMapCanvas::magnificationChanged ( double  magnification)
signal

Emitted when the scale of the map changes.

◆ magnificationFactor()

double QgsMapCanvas::magnificationFactor ( ) const

Returns the magnification factor.

Definition at line 332 of file qgsmapcanvas.cpp.

◆ mapCanvasRefreshed

void QgsMapCanvas::mapCanvasRefreshed ( )
signal

Emitted when canvas finished a refresh request.

◆ mapRefreshCanceled

void QgsMapCanvas::mapRefreshCanceled ( )
signal

Emitted when the pending map refresh has been canceled.

Since
QGIS 3.18

◆ mapSettings() [1/2]

QgsMapSettings & QgsMapCanvas::mapSettings ( )

Returns a reference to the map settings used for map rendering.

Note
Not available in Python bindings.
Since
QGIS 3.34

Definition at line 512 of file qgsmapcanvas.cpp.

◆ mapSettings() [2/2]

const QgsMapSettings & QgsMapCanvas::mapSettings ( ) const

Gets access to properties used for map rendering.

Definition at line 507 of file qgsmapcanvas.cpp.

◆ mapTool()

QgsMapTool * QgsMapCanvas::mapTool ( ) const

Returns the currently active tool.

Definition at line 3091 of file qgsmapcanvas.cpp.

◆ mapToolSet

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

Emit map tool changed with the old tool.

◆ mapUnits()

Qgis::DistanceUnit QgsMapCanvas::mapUnits ( ) const

Convenience function for returning the current canvas map units.

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

Definition at line 2955 of file qgsmapcanvas.cpp.

◆ mapUnitsPerPixel()

double QgsMapCanvas::mapUnitsPerPixel ( ) const

Returns the mapUnitsPerPixel (map units per pixel) for the canvas.

Definition at line 2950 of file qgsmapcanvas.cpp.

◆ mapUpdateInterval()

int QgsMapCanvas::mapUpdateInterval ( ) const

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

Definition at line 700 of file qgsmapcanvas.cpp.

◆ messageEmitted

void QgsMapCanvas::messageEmitted ( const QString &  title,
const QString &  message,
Qgis::MessageLevel  level = Qgis::MessageLevel::Info 
)
signal

emit a message (usually to be displayed in a message bar)

◆ mouseDoubleClickEvent()

void QgsMapCanvas::mouseDoubleClickEvent ( QMouseEvent *  e)
overrideprotected

Definition at line 2438 of file qgsmapcanvas.cpp.

◆ mouseLastXY()

QPoint QgsMapCanvas::mouseLastXY ( )

returns last position of mouse cursor

Definition at line 3201 of file qgsmapcanvas.cpp.

◆ mouseMoveEvent()

void QgsMapCanvas::mouseMoveEvent ( QMouseEvent *  e)
overrideprotected

Definition at line 2771 of file qgsmapcanvas.cpp.

◆ mousePressEvent()

void QgsMapCanvas::mousePressEvent ( QMouseEvent *  e)
overrideprotected

Definition at line 2521 of file qgsmapcanvas.cpp.

◆ mouseReleaseEvent()

void QgsMapCanvas::mouseReleaseEvent ( QMouseEvent *  e)
overrideprotected

Definition at line 2574 of file qgsmapcanvas.cpp.

◆ moveCanvasContents()

void QgsMapCanvas::moveCanvasContents ( bool  reset = false)
protected

called when panning is in action, reset indicates end of panning

Definition at line 3146 of file qgsmapcanvas.cpp.

◆ paintEvent()

void QgsMapCanvas::paintEvent ( QPaintEvent *  e)
overrideprotected

Definition at line 2651 of file qgsmapcanvas.cpp.

◆ panAction()

void QgsMapCanvas::panAction ( QMouseEvent *  event)

Called when mouse is moving and pan is activated.

Definition at line 3129 of file qgsmapcanvas.cpp.

◆ panActionEnd()

void QgsMapCanvas::panActionEnd ( QPoint  releasePoint)

Ends pan action and redraws the canvas.

Definition at line 3101 of file qgsmapcanvas.cpp.

◆ panActionStart()

void QgsMapCanvas::panActionStart ( QPoint  releasePoint)

Starts a pan action.

Note
Not available in Python bindings
Since
QGIS 3.12

Definition at line 3120 of file qgsmapcanvas.cpp.

◆ panDistanceBearingChanged

void QgsMapCanvas::panDistanceBearingChanged ( double  distance,
Qgis::DistanceUnit  unit,
double  bearing 
)
signal

Emitted whenever the distance or bearing of an in-progress panning operation is changed.

This signal will be emitted during a pan operation as the user moves the map, giving the total distance and bearing between the map position at the start of the pan and the current pan position.

Since
QGIS 3.12

◆ panToFeatureIds()

void QgsMapCanvas::panToFeatureIds ( QgsVectorLayer layer,
const QgsFeatureIds ids,
bool  alwaysRecenter = true 
)

Centers canvas extent to feature ids.

Parameters
layerthe vector layer
idsthe feature ids
alwaysRecenterif false, the canvas is recentered only if the bounding box is not contained within the current extent

Definition at line 2013 of file qgsmapcanvas.cpp.

◆ panToSelected() [1/2]

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

Pan to the combined extent of the selected features of all provided (vector) layers.

Parameters
layersA list of layers
Since
QGIS 3.18

Definition at line 2131 of file qgsmapcanvas.cpp.

◆ panToSelected() [2/2]

void QgsMapCanvas::panToSelected ( QgsMapLayer layer = nullptr)

Pan to the selected features of current ayer keeping same extent.

Definition at line 2071 of file qgsmapcanvas.cpp.

◆ previewJobsEnabled()

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.

See also
setPreviewJobsEnabled()

Definition at line 1051 of file qgsmapcanvas.cpp.

◆ previewMode()

QgsPreviewEffect::PreviewMode QgsMapCanvas::previewMode ( ) const

Returns the current preview mode for the map canvas.

This setting only has an effect if previewModeEnabled is true.

Returns
preview mode for map canvas
See also
setPreviewMode
previewModeEnabled

Definition at line 3236 of file qgsmapcanvas.cpp.

◆ previewModeEnabled()

bool QgsMapCanvas::previewModeEnabled ( ) const

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

Returns
true if a preview mode is currently enabled
See also
setPreviewModeEnabled
previewMode

Definition at line 3216 of file qgsmapcanvas.cpp.

◆ project()

QgsProject * QgsMapCanvas::project ( )

Returns the project linked to this canvas.

The returned value may be nullptr.

Since
QGIS 3.14

Definition at line 3096 of file qgsmapcanvas.cpp.

◆ projectExtent()

QgsRectangle QgsMapCanvas::projectExtent ( ) const

Returns the associated project's full extent, in the canvas' CRS.

This method returns the full extent for the project associated with this canvas. Unlike fullExtent(), this method does NOT consider which layers are actually visible in the map canvas.

See also
fullExtent()
Since
QGIS 3.20

Definition at line 1530 of file qgsmapcanvas.cpp.

◆ readProject

void QgsMapCanvas::readProject ( const QDomDocument &  doc)
slot

called to read map canvas settings from project

Definition at line 3262 of file qgsmapcanvas.cpp.

◆ redrawAllLayers

void QgsMapCanvas::redrawAllLayers ( )
slot

Clears all cached images and redraws all layers.

Note
Unlike refreshAllLayers(), this does NOT reload layers themselves, and accordingly is more "lightweight". Use this method when only an update of the layer's renderers is required.
Since
QGIS 3.10

Definition at line 3480 of file qgsmapcanvas.cpp.

◆ refresh

void QgsMapCanvas::refresh ( )
slot

Repaints the canvas map.

Definition at line 735 of file qgsmapcanvas.cpp.

◆ refreshAllLayers

void QgsMapCanvas::refreshAllLayers ( )
slot

Reload all layers (including refreshing layer properties from their data sources), clears the cache and refreshes the canvas.

Note
Consider using the less expensive redrawAllLayers() method if a layer reload from the data provider is not required.

Definition at line 3468 of file qgsmapcanvas.cpp.

◆ removeInteractionBlocker()

void QgsMapCanvas::removeInteractionBlocker ( QgsMapCanvasInteractionBlocker blocker)

Removes an interaction blocker from the canvas.

See also
allowInteraction()
installInteractionBlocker()
Since
QGIS 3.14

Definition at line 1394 of file qgsmapcanvas.cpp.

◆ renderComplete

void QgsMapCanvas::renderComplete ( QPainter *  painter)
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.

  • 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

◆ renderedItemResults()

const QgsRenderedItemResults * QgsMapCanvas::renderedItemResults ( bool  allowOutdatedResults = true) const

Gets access to the rendered item results (may be nullptr), which includes the results of rendering annotation items in the canvas map.

If the allowOutdatedResults flag is false then outdated rendered item results (e.g. as a result of an ongoing canvas render) will not be returned, and instead nullptr will be returned.

Since
QGIS 3.22

Definition at line 633 of file qgsmapcanvas.cpp.

◆ renderErrorOccurred

void QgsMapCanvas::renderErrorOccurred ( const QString &  error,
QgsMapLayer layer 
)
signal

Emitted whenever an error is encountered during a map render operation.

The layer argument indicates the associated map layer, if available.

Since
QGIS 3.10.0

◆ renderFlag()

bool QgsMapCanvas::renderFlag ( ) const
inline

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

See also
setRenderFlag()
isFrozen()
Note
isFrozen() should be used to determine whether map updates have been halted programmatically, while renderFlag() should be used to determine whether a user has disabled rendering via GUI.

Definition at line 571 of file qgsmapcanvas.h.

◆ renderStarting

void QgsMapCanvas::renderStarting ( )
signal

Emitted when the canvas is about to be rendered.

◆ resizeEvent()

void QgsMapCanvas::resizeEvent ( QResizeEvent *  e)
overrideprotected

Definition at line 2622 of file qgsmapcanvas.cpp.

◆ rotation()

double QgsMapCanvas::rotation ( ) const

Gets the current map canvas rotation in clockwise degrees.

Definition at line 1662 of file qgsmapcanvas.cpp.

◆ rotationChanged

void QgsMapCanvas::rotationChanged ( double  rotation)
signal

Emitted when the rotation of the map changes.

◆ saveAsImage

void QgsMapCanvas::saveAsImage ( const QString &  fileName,
QPixmap *  QPixmap = nullptr,
const QString &  format = "PNG" 
)
slot

Save the contents of the map canvas to disk as an image.

Definition at line 1454 of file qgsmapcanvas.cpp.

◆ scale()

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.

Definition at line 386 of file qgsmapcanvas.cpp.

◆ scaleChanged

void QgsMapCanvas::scaleChanged ( double  scale)
signal

Emitted when the scale of the map changes.

◆ scaleLockChanged

void QgsMapCanvas::scaleLockChanged ( bool  locked)
signal

Emitted when the scale locked state of the map changes.

Parameters
lockedtrue if the scale is locked
See also
setScaleLocked
Since
QGIS 3.18

◆ scaleLocked()

bool QgsMapCanvas::scaleLocked ( ) const
inline

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

See also
setScaleLocked()

Definition at line 665 of file qgsmapcanvas.h.

◆ selectionChanged

void QgsMapCanvas::selectionChanged ( QgsMapLayer layer)
signal

Emitted when selection in any layer gets changed.

Note
Since QGIS 3.28 this signal is emitted for multiple layer types, including QgsVectorLayer and QgsVectorTileLayer

◆ selectionChangedSlot

void QgsMapCanvas::selectionChangedSlot ( )
slot

Receives signal about selection change, and pass it on with layer info.

Definition at line 3381 of file qgsmapcanvas.cpp.

◆ selectionColor()

QColor QgsMapCanvas::selectionColor ( ) const

Returns color for selected features.

Definition at line 2919 of file qgsmapcanvas.cpp.

◆ setAnnotationsVisible()

void QgsMapCanvas::setAnnotationsVisible ( bool  visible)

Sets whether annotations are visible in the canvas.

See also
annotationsVisible()

Definition at line 3523 of file qgsmapcanvas.cpp.

◆ setCachingEnabled()

void QgsMapCanvas::setCachingEnabled ( bool  enabled)

Set whether to cache images of rendered layers.

See also
isCachingEnabled()
cache()

Definition at line 641 of file qgsmapcanvas.cpp.

◆ setCanvasColor()

void QgsMapCanvas::setCanvasColor ( const QColor &  _newVal)

Write property of QColor bgColor.

Definition at line 2860 of file qgsmapcanvas.cpp.

◆ setCenter()

void QgsMapCanvas::setCenter ( const QgsPointXY center)

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

Definition at line 1636 of file qgsmapcanvas.cpp.

◆ setCurrentLayer()

void QgsMapCanvas::setCurrentLayer ( QgsMapLayer layer)

Definition at line 377 of file qgsmapcanvas.cpp.

◆ setCustomDropHandlers()

void QgsMapCanvas::setCustomDropHandlers ( const QVector< QPointer< QgsCustomDropHandler > > &  handlers)

Sets a list of custom drop handlers to use when drop events occur on the canvas.

Note
Not available in Python bindings
Since
QGIS 3.10

Definition at line 1061 of file qgsmapcanvas.cpp.

◆ setDestinationCrs()

void QgsMapCanvas::setDestinationCrs ( const QgsCoordinateReferenceSystem crs)

Sets destination coordinate reference system.

Definition at line 517 of file qgsmapcanvas.cpp.

◆ setExpressionContextScope()

void QgsMapCanvas::setExpressionContextScope ( const QgsExpressionContextScope scope)
inline

Sets an 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. This method will overwrite the existing expression context scope for the canvas.

Parameters
scopenew expression context scope
See also
expressionContextScope()
defaultExpressionContextScope()

Definition at line 758 of file qgsmapcanvas.h.

◆ setExtent()

void QgsMapCanvas::setExtent ( const QgsRectangle r,
bool  magnified = false 
)

Sets the extent of the map canvas to the specified rectangle.

The magnified argument dictates whether existing canvas constraints such as a scale lock should be respected or not during the operation. If magnified is true then an existing scale lock constraint will be applied. This means that the final visible canvas extent may not match the specified extent.

If magnified is false then scale lock settings will be ignored, and the specified rectangle will ALWAYS be visible in the canvas.

Definition at line 1548 of file qgsmapcanvas.cpp.

◆ setFlags()

void QgsMapCanvas::setFlags ( Qgis::MapCanvasFlags  flags)

Sets flags which control how the map canvas behaves.

See also
flags()
Since
QGIS 3.40

Definition at line 412 of file qgsmapcanvas.cpp.

◆ setLabelingEngineSettings()

void QgsMapCanvas::setLabelingEngineSettings ( const QgsLabelingEngineSettings settings)

Sets global labeling engine settings in the internal map settings.

Definition at line 3533 of file qgsmapcanvas.cpp.

◆ setLayers()

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.

See also
layers()

Definition at line 403 of file qgsmapcanvas.cpp.

◆ setLayerStyleOverrides()

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.

See also
layerStyleOverrides()

Definition at line 2965 of file qgsmapcanvas.cpp.

◆ setMagnificationFactor

void QgsMapCanvas::setMagnificationFactor ( double  factor,
const QgsPointXY center = nullptr 
)
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.

Parameters
factorThe factor of magnification
centerOptional point to re-center the map

Definition at line 316 of file qgsmapcanvas.cpp.

◆ setMapController()

void QgsMapCanvas::setMapController ( QgsAbstract2DMapController controller)

Sets the input controller device to use for controlling the canvas.

Ownership of controller is transferred to the canvas.

Since
QGIS 3.34

Definition at line 1409 of file qgsmapcanvas.cpp.

◆ setMapSettingsFlags()

void QgsMapCanvas::setMapSettingsFlags ( Qgis::MapSettingsFlags  flags)

Resets the flags for the canvas' map settings.

Definition at line 618 of file qgsmapcanvas.cpp.

◆ setMapTool()

void QgsMapCanvas::setMapTool ( QgsMapTool mapTool,
bool  clean = false 
)

Sets the map tool currently being used on the canvas.

Definition at line 2803 of file qgsmapcanvas.cpp.

◆ setMapUpdateInterval()

void QgsMapCanvas::setMapUpdateInterval ( int  timeMilliseconds)

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

Definition at line 695 of file qgsmapcanvas.cpp.

◆ setParallelRenderingEnabled()

void QgsMapCanvas::setParallelRenderingEnabled ( bool  enabled)

Set whether the layers are rendered in parallel or sequentially.

Definition at line 685 of file qgsmapcanvas.cpp.

◆ setPreviewJobsEnabled()

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.

See also
previewJobsEnabled()

Definition at line 1056 of file qgsmapcanvas.cpp.

◆ setPreviewMode()

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

Sets a preview mode for the map canvas.

This setting only has an effect if previewModeEnabled is true.

Parameters
modepreview mode for the canvas
See also
previewMode
setPreviewModeEnabled
previewModeEnabled

Definition at line 3226 of file qgsmapcanvas.cpp.

◆ setPreviewModeEnabled()

void QgsMapCanvas::setPreviewModeEnabled ( bool  previewEnabled)

Enables a preview mode for the map canvas.

Parameters
previewEnabledset to true to enable a preview mode
See also
setPreviewMode

Definition at line 3206 of file qgsmapcanvas.cpp.

◆ setProject()

void QgsMapCanvas::setProject ( QgsProject project)

Sets the project linked to this canvas.

Since
QGIS 3.14

Definition at line 2849 of file qgsmapcanvas.cpp.

◆ setReferencedExtent()

bool QgsMapCanvas::setReferencedExtent ( const QgsReferencedRectangle extent)

Sets the canvas to the specified extent.

Returns
true if the zoom was successful.
Exceptions
QgsCsExceptionif a transformation error occurred.
Since
QGIS 3.10

Definition at line 1617 of file qgsmapcanvas.cpp.

◆ setRenderFlag

void QgsMapCanvas::setRenderFlag ( bool  flag)
slot

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

Parameters
flagset to false to indicate that user has disabled renders
See also
renderFlag()
freeze()
Note
freeze() should be used to programmatically halt map updates, while setRenderFlag() should only be used when users disable rendering via GUI.

Definition at line 2996 of file qgsmapcanvas.cpp.

◆ setRotation()

void QgsMapCanvas::setRotation ( double  degrees)

Set the rotation of the map canvas in clockwise degrees.

Definition at line 1667 of file qgsmapcanvas.cpp.

◆ setScaleLocked

void QgsMapCanvas::setScaleLocked ( bool  isLocked)
slot

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

See also
scaleLocked()

Definition at line 2762 of file qgsmapcanvas.cpp.

◆ setSegmentationTolerance()

void QgsMapCanvas::setSegmentationTolerance ( double  tolerance)

Sets the segmentation tolerance applied when rendering curved geometries.

Parameters
tolerancethe segmentation tolerance

Definition at line 3497 of file qgsmapcanvas.cpp.

◆ setSegmentationToleranceType()

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

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

Parameters
typethe segmentation tolerance typename

Definition at line 3502 of file qgsmapcanvas.cpp.

◆ setSelectionColor()

void QgsMapCanvas::setSelectionColor ( const QColor &  color)

Set color of selected vector features.

Definition at line 2890 of file qgsmapcanvas.cpp.

◆ setSnappingUtils()

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).

Definition at line 3257 of file qgsmapcanvas.cpp.

◆ setTemporalController()

void QgsMapCanvas::setTemporalController ( QgsTemporalController controller)

Sets the temporal controller for this canvas.

The controller will be used to update the canvas' temporal range.

Since
QGIS 3.14

Definition at line 570 of file qgsmapcanvas.cpp.

◆ setTemporalRange()

void QgsMapCanvas::setTemporalRange ( const QgsDateTimeRange range)

Set datetime range for the map canvas.

The temporalRangeChanged() signal will be emitted if the temporal range has been changed.

Note
Calling setTemporalRange() does not automatically trigger a map refresh.
See also
temporalRange()
Since
QGIS 3.14

Definition at line 1367 of file qgsmapcanvas.cpp.

◆ setTheme()

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.

See also
theme()

Definition at line 2975 of file qgsmapcanvas.cpp.

◆ setWheelFactor()

void QgsMapCanvas::setWheelFactor ( double  factor)

Sets wheel zoom factor (should be greater than 1)

Definition at line 2722 of file qgsmapcanvas.cpp.

◆ setZoomResolutions

void QgsMapCanvas::setZoomResolutions ( const QList< double > &  resolutions)
inlineslot

Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map.

Parameters
resolutionsA list of resolutions
Since
QGIS 3.12

Definition at line 1004 of file qgsmapcanvas.h.

◆ setZRange

void QgsMapCanvas::setZRange ( const QgsDoubleRange range)
slot

Sets the range of z-values which will be visible in the map.

See also
zRange()
zRangeChanged()
Since
QGIS 3.18

Definition at line 1949 of file qgsmapcanvas.cpp.

◆ showEvent()

void QgsMapCanvas::showEvent ( QShowEvent *  event)
overrideprotected

Definition at line 3189 of file qgsmapcanvas.cpp.

◆ snappingUtils()

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.

Definition at line 3246 of file qgsmapcanvas.cpp.

◆ stopRendering

void QgsMapCanvas::stopRendering ( )
slot

stop rendering (if there is any right now)

Definition at line 1438 of file qgsmapcanvas.cpp.

◆ tapAndHoldGestureOccurred

void QgsMapCanvas::tapAndHoldGestureOccurred ( const QgsPointXY mapPoint,
QTapAndHoldGesture *  gesture 
)
signal

Emitted whenever a tap and hold gesture occurs at the specified map point.

Since
QGIS 3.12

◆ temporalController()

const QgsTemporalController * QgsMapCanvas::temporalController ( ) const

Gets access to the temporal controller that will be used to update the canvas temporal range.

Since
QGIS 3.14

Definition at line 613 of file qgsmapcanvas.cpp.

◆ temporalRange()

const QgsDateTimeRange & QgsMapCanvas::temporalRange ( ) const

Returns map canvas datetime range.

See also
setTemporalRange()
Since
QGIS 3.14

Definition at line 1384 of file qgsmapcanvas.cpp.

◆ temporalRangeChanged

void QgsMapCanvas::temporalRangeChanged ( )
signal

Emitted when the map canvas temporal range changes.

Since
QGIS 3.14

◆ theme()

QString QgsMapCanvas::theme ( ) const
inline

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

See also
setTheme()

Definition at line 620 of file qgsmapcanvas.h.

◆ themeChanged

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

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

See also
setTheme()

◆ transformContextChanged

void QgsMapCanvas::transformContextChanged ( )
signal

Emitted when the canvas transform context is changed.

◆ unsetMapTool()

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.

Definition at line 2836 of file qgsmapcanvas.cpp.

◆ updateCanvasItemPositions

void QgsMapCanvas::updateCanvasItemPositions ( )
protectedslot

called on resize or changed extent to notify canvas items to change their rectangle

Definition at line 2658 of file qgsmapcanvas.cpp.

◆ updateScale()

void QgsMapCanvas::updateScale ( )

Emits signal scaleChanged to update scale in main window.

Definition at line 1679 of file qgsmapcanvas.cpp.

◆ viewportEvent()

bool QgsMapCanvas::viewportEvent ( QEvent *  event)
overrideprotected

Definition at line 3430 of file qgsmapcanvas.cpp.

◆ waitWhileRendering()

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.

Definition at line 3489 of file qgsmapcanvas.cpp.

◆ wheelEvent()

void QgsMapCanvas::wheelEvent ( QWheelEvent *  e)
overrideprotected

Definition at line 2676 of file qgsmapcanvas.cpp.

◆ writeProject

void QgsMapCanvas::writeProject ( QDomDocument &  doc)
slot

called to write map canvas settings to project

Definition at line 3330 of file qgsmapcanvas.cpp.

◆ xyCoordinates

void QgsMapCanvas::xyCoordinates ( const QgsPointXY p)
signal

Emits current mouse position.

Note
changed in 1.3

◆ zoomByFactor()

void QgsMapCanvas::zoomByFactor ( double  scaleFactor,
const QgsPointXY center = nullptr,
bool  ignoreScaleLock = false 
)

Zoom with the factor supplied.

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

If ignoreScaleLock is set to true, then any existing constraint on the map scale of the canvas will be ignored during the zoom operation.

Definition at line 3365 of file qgsmapcanvas.cpp.

◆ zoomIn

void QgsMapCanvas::zoomIn ( )
slot

Zoom in with fixed factor.

Definition at line 2727 of file qgsmapcanvas.cpp.

◆ zoomInFactor

double QgsMapCanvas::zoomInFactor ( ) const
slot

Returns the zoom in factor.

Definition at line 3698 of file qgsmapcanvas.cpp.

◆ zoomLastStatusChanged

void QgsMapCanvas::zoomLastStatusChanged ( bool  available)
signal

Emitted when zoom last status changed.

◆ zoomNextStatusChanged

void QgsMapCanvas::zoomNextStatusChanged ( bool  available)
signal

Emitted when zoom next status changed.

◆ zoomOut

void QgsMapCanvas::zoomOut ( )
slot

Zoom out with fixed factor.

Definition at line 2733 of file qgsmapcanvas.cpp.

◆ zoomOutFactor

double QgsMapCanvas::zoomOutFactor ( ) const
slot

Returns the zoom in factor.

Definition at line 3711 of file qgsmapcanvas.cpp.

◆ zoomResolutions

const QList< double > & QgsMapCanvas::zoomResolutions ( ) const
inlineslot
Returns
List of resolutions to which to "snap to" when zooming the map
See also
setZoomResolutions()
Since
QGIS 3.12

Definition at line 1021 of file qgsmapcanvas.h.

◆ zoomScale()

void QgsMapCanvas::zoomScale ( double  scale,
bool  ignoreScaleLock = false 
)

Zooms the canvas to a specific scale.

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

If ignoreScaleLock is set to true, then any existing constraint on the map scale of the canvas will be ignored during the zoom operation.

Definition at line 2739 of file qgsmapcanvas.cpp.

◆ zoomToFeatureExtent()

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)

Definition at line 1965 of file qgsmapcanvas.cpp.

◆ zoomToFeatureIds()

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

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

Parameters
layerthe vector layer
idsthe feature ids

Definition at line 1989 of file qgsmapcanvas.cpp.

◆ zoomToFullExtent()

void QgsMapCanvas::zoomToFullExtent ( )

Zoom to the full extent of all layers currently visible in the canvas.

See also
zoomToProjectExtent()

Definition at line 1685 of file qgsmapcanvas.cpp.

◆ zoomToNextExtent()

void QgsMapCanvas::zoomToNextExtent ( )

Zoom to the next extent (view)

Definition at line 1728 of file qgsmapcanvas.cpp.

◆ zoomToPreviousExtent()

void QgsMapCanvas::zoomToPreviousExtent ( )

Zoom to the previous extent (view)

Definition at line 1712 of file qgsmapcanvas.cpp.

◆ zoomToProjectExtent()

void QgsMapCanvas::zoomToProjectExtent ( )

Zoom to the full extent the project associated with this canvas.

This method zooms to the full extent for the project associated with this canvas. Unlike zoomToFullExtent(), this method does NOT consider which layers are actually visible in the map canvas.

Since
QGIS 3.20

Definition at line 1698 of file qgsmapcanvas.cpp.

◆ zoomToSelected [1/2]

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

Zoom to the combined extent of the selected features of all provided (vector) layers.

Parameters
layersA list of layers
Since
QGIS 3.18

Definition at line 1868 of file qgsmapcanvas.cpp.

◆ zoomToSelected [2/2]

void QgsMapCanvas::zoomToSelected ( QgsMapLayer layer = nullptr)
slot

Zoom to the extent of the selected features of provided map layer.

Parameters
layeroptionally specify different than current layer

Definition at line 1787 of file qgsmapcanvas.cpp.

◆ zoomWithCenter()

void QgsMapCanvas::zoomWithCenter ( int  x,
int  y,
bool  zoomIn 
)

Zooms in/out with a given center.

Definition at line 2744 of file qgsmapcanvas.cpp.

◆ zRange

QgsDoubleRange QgsMapCanvas::zRange ( ) const
slot

Returns the range of z-values which will be visible in the map.

See also
setZRange()
zRangeChanged()
Since
QGIS 3.18

Definition at line 1944 of file qgsmapcanvas.cpp.

◆ zRangeChanged

void QgsMapCanvas::zRangeChanged ( )
signal

Emitted when the map canvas z (elevation) range changes.

See also
zRange()
setZRange()
Since
QGIS 3.18

Friends And Related Symbol Documentation

◆ TestQgsMapCanvas

friend class TestQgsMapCanvas
friend

Definition at line 1574 of file qgsmapcanvas.h.

Member Data Documentation

◆ mCanvasProperties

std::unique_ptr<CanvasProperties> QgsMapCanvas::mCanvasProperties
protected

Handle pattern for implementation object.

Definition at line 1272 of file qgsmapcanvas.h.

Property Documentation

◆ previewJobsEnabled

bool QgsMapCanvas::previewJobsEnabled
readwrite

Definition at line 106 of file qgsmapcanvas.h.

◆ theme

QString QgsMapCanvas::theme
readwrite

Definition at line 105 of file qgsmapcanvas.h.


The documentation for this class was generated from the following files: