QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsmapcanvas.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmapcanvas.h - description
3 -------------------
4 begin : Sun Jun 30 2002
5 copyright : (C) 2002 by Gary E.Sherman
6 email : sherman at mrcc.com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSMAPCANVAS_H
19#define QGSMAPCANVAS_H
20
21#include "qgsconfig.h"
22
23#include "qgis_gui.h"
24#include "qgis_sip.h"
26#include "qgsdistancearea.h"
28#include "qgsfeatureid.h"
29#include "qgsgeometry.h"
31#include "qgsmaprendererjob.h"
32#include "qgsmapsettings.h"
33#include "qgsprevieweffect.h"
34#include "qgsproject.h"
35#include "qgsrectangle.h"
36
37#include <QDomDocument>
38#include <QGestureEvent>
39#include <QGraphicsView>
40#include <QTimer>
41
42class QWheelEvent;
43class QPixmap;
44class QPaintEvent;
45class QKeyEvent;
46class ResizeEvent;
47
48class QColor;
49class QDomDocument;
50class QPaintDevice;
51class QMouseEvent;
52class QRubberBand;
53class QGraphicsScene;
54
55class QgsMapToPixel;
56class QgsMapLayer;
57class QgsHighlight;
58class QgsVectorLayer;
59
61
64class QgsMapSettings;
65class QgsMapCanvasMap;
67class QgsMapTool;
69class QgsRubberBand;
75
77class QgsScreenHelper;
78
80
81class QMenu;
83
84
89
90class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContextGenerator
91{
92#ifdef SIP_RUN
94 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
95 sipType = sipType_QgsMapCanvas;
96 else
97 sipType = nullptr;
99#endif
100
101 Q_OBJECT
102 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
104
105 public:
107 QgsMapCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
108
109 ~QgsMapCanvas() override;
110
121 void addOverlayWidget( QWidget *widget SIP_TRANSFER, Qt::Edge edge );
122
126 double magnificationFactor() const;
127
138 void setLayers( const QList<QgsMapLayer *> &layers );
139
146 void setFlags( Qgis::MapCanvasFlags flags );
147
154 Qgis::MapCanvasFlags flags() const;
155
157
162
170
178
186
191
195 void setMapSettingsFlags( Qgis::MapSettingsFlags flags );
196
204 const QgsLabelingResults *labelingResults( bool allowOutdatedResults = true ) const;
205
215 const QgsRenderedItemResults *renderedItemResults( bool allowOutdatedResults = true ) const;
216
224 void setCachingEnabled( bool enabled );
225
233 bool isCachingEnabled() const;
234
238 void clearCache();
239
249
254 void cancelJobs() SIP_SKIP;
255
264 void waitWhileRendering();
265
269 void setParallelRenderingEnabled( bool enabled );
270
274 bool isParallelRenderingEnabled() const;
275
279 void setMapUpdateInterval( int timeMilliseconds );
280
284 int mapUpdateInterval() const;
285
290 double scale() const;
291
293 double mapUnitsPerPixel() const;
294
296 QgsRectangle extent() const;
297
306 QgsRectangle fullExtent() const;
307
318
330 void setExtent( const QgsRectangle &r, bool magnified = false );
331
341
345 double rotation() const;
346
350 void setRotation( double degrees );
351
355 void setCenter( const QgsPointXY &center );
356
360 QgsPointXY center() const;
361
367 void zoomToFullExtent();
368
377 void zoomToProjectExtent();
378
381
383 void zoomToNextExtent();
384
386 void clearExtentHistory();
387
388
395
402 void panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter = true );
403
405 void panToSelected( QgsMapLayer *layer = nullptr );
406
412 void panToSelected( const QList<QgsMapLayer *> &layers );
413
425 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 );
426
438 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 );
439
441 void setMapTool( QgsMapTool *mapTool, bool clean = false );
442
451
453 QgsMapTool *mapTool() const;
454
461
469
471 void setCanvasColor( const QColor &_newVal );
473 QColor canvasColor() const;
474
478 void setSelectionColor( const QColor &color );
479
483 QColor selectionColor() const;
484
486 void updateScale();
487
489 QgsMapLayer *layer( int index );
490
501 QgsMapLayer *layer( const QString &id );
502
506 int layerCount() const;
507
516 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
517
518#ifndef SIP_RUN
525 template<typename T>
526 QVector<T> layers() const { return mapSettings().layers<T>(); }
527#endif
528
540 void freeze( bool frozen = true );
541
551 bool isFrozen() const;
552
563 bool renderFlag() const { return mRenderFlag; }
564
569 Qgis::DistanceUnit mapUnits() const;
570
575 QMap<QString, QString> layerStyleOverrides() const;
576
587 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
588
609 void setTheme( const QString &theme );
610
615 QString theme() const { return mTheme; }
616
618 const QgsMapToPixel *getCoordinateTransform();
619
621 bool isDrawing();
622
624 QgsMapLayer *currentLayer();
625
627 void setWheelFactor( double factor );
628
636 void zoomScale( double scale, bool ignoreScaleLock = false );
637
645 void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr, bool ignoreScaleLock = false );
646
648 void zoomWithCenter( int x, int y, bool zoomIn );
649
654 void zoomToFeatureExtent( QgsRectangle &rect );
655
660 bool scaleLocked() const { return mScaleLocked; }
661
663 void enableAntiAliasing( bool flag );
664
666 bool antiAliasingEnabled() const;
667
669 void enableMapTileRendering( bool flag );
670
671 // following 2 methods should be moved elsewhere or changed to private
672 // currently used by pan map tool
674 void panActionEnd( QPoint releasePoint );
675
676#ifndef SIP_RUN
677
683 void panActionStart( QPoint releasePoint );
684#endif
685
687 void panAction( QMouseEvent *event );
688
690 QPoint mouseLastXY();
691
697 void setPreviewModeEnabled( bool previewEnabled );
698
705 bool previewModeEnabled() const;
706
715 void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
716
724 QgsPreviewEffect::PreviewMode previewMode() const;
725
733 QgsSnappingUtils *snappingUtils() const;
734
742 void setSnappingUtils( QgsSnappingUtils *utils );
743
753 void setExpressionContextScope( const QgsExpressionContextScope &scope ) { mExpressionContextScope = scope; }
754
762 QgsExpressionContextScope &expressionContextScope() { return mExpressionContextScope; }
763
771 {
772 return mExpressionContextScope;
773 }
774
781 QgsExpressionContextScope *defaultExpressionContextScope() const SIP_FACTORY;
782
783 QgsExpressionContext createExpressionContext() const override;
784
789 void setSegmentationTolerance( double tolerance );
790
795 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
796
800 QList<QgsMapCanvasAnnotationItem *> annotationItems() const;
801
806 bool annotationsVisible() const { return mAnnotationsVisible; }
807
812 void setAnnotationsVisible( bool visible );
813
817 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
818
822 const QgsLabelingEngineSettings &labelingEngineSettings() const;
823
831 bool previewJobsEnabled() const;
832
840 void setPreviewJobsEnabled( bool enabled );
841
847 void setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHandler>> &handlers ) SIP_SKIP;
848
859 void setTemporalRange( const QgsDateTimeRange &range );
860
867 const QgsDateTimeRange &temporalRange() const;
868
880 void installInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
881
889 void removeInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
890
896 bool allowInteraction( QgsMapCanvasInteractionBlocker::Interaction interaction ) const;
897
905 void setMapController( QgsAbstract2DMapController *controller SIP_TRANSFER );
906
907 public slots:
908
910 void refresh();
911
920 void refreshAllLayers();
921
930 void redrawAllLayers();
931
933 void selectionChangedSlot();
934
936 void saveAsImage( const QString &fileName, QPixmap *QPixmap = nullptr, const QString & = "PNG" );
937
939 void layerStateChange();
940
950 void setRenderFlag( bool flag );
951
955 void stopRendering();
956
958 void readProject( const QDomDocument & );
959
961 void writeProject( QDomDocument & );
962
970 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
971
976 void setScaleLocked( bool isLocked );
977
979 void zoomIn();
980
982 void zoomOut();
983
988 void zoomToSelected( QgsMapLayer *layer = nullptr );
989
995 void zoomToSelected( const QList<QgsMapLayer *> &layers );
996
1002 void setZoomResolutions( const QList<double> &resolutions ) { mZoomResolutions = resolutions; }
1003
1007 double zoomInFactor() const;
1008
1012 double zoomOutFactor() const;
1013
1020 const QList<double> &zoomResolutions() const { return mZoomResolutions; }
1021
1030 QgsDoubleRange zRange() const;
1031
1040 void setZRange( const QgsDoubleRange &range );
1041
1042 private slots:
1044 void mapToolDestroyed();
1045
1047 void rendererJobFinished();
1048
1050 void previewJobFinished();
1051
1052 void mapUpdateTimeout();
1053
1054 void refreshMap();
1055
1056 void mapThemeChanged( const QString &theme );
1058 void mapThemeRenamed( const QString &theme, const QString &newTheme );
1059
1060 void updateDevicePixelFromScreen();
1061
1062 void onElevationShadingRendererChanged();
1063
1064 signals:
1065
1070 void xyCoordinates( const QgsPointXY &p );
1071
1073 void scaleChanged( double scale );
1074
1081 void scaleLockChanged( bool locked );
1082
1083
1086
1091
1095 void magnificationChanged( double magnification );
1096
1101
1102 // TODO: deprecate when decorations are reimplemented as map canvas items
1103
1114 void renderComplete( QPainter *painter );
1115
1116 // ### QGIS 3: renamte to mapRefreshFinished()
1119
1120 // ### QGIS 3: rename to mapRefreshStarted()
1123
1129
1132
1134 void keyPressed( QKeyEvent *e );
1135
1137 void keyReleased( QKeyEvent *e );
1138
1142 void mapToolSet( QgsMapTool *newTool, QgsMapTool *oldTool );
1143
1150
1152 void zoomLastStatusChanged( bool available );
1153
1155 void zoomNextStatusChanged( bool available );
1156
1161
1166
1171
1176
1181 void themeChanged( const QString &theme );
1182
1184 void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
1185
1193 void renderErrorOccurred( const QString &error, QgsMapLayer *layer );
1194
1205 void panDistanceBearingChanged( double distance, Qgis::DistanceUnit unit, double bearing );
1206
1211 void tapAndHoldGestureOccurred( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
1212
1219
1229
1237
1238 protected:
1239 bool event( QEvent *e ) override;
1240 void keyPressEvent( QKeyEvent *e ) override;
1241 void keyReleaseEvent( QKeyEvent *e ) override;
1242 void mouseDoubleClickEvent( QMouseEvent *e ) override;
1243 void mouseMoveEvent( QMouseEvent *e ) override;
1244 void mousePressEvent( QMouseEvent *e ) override;
1245 void mouseReleaseEvent( QMouseEvent *e ) override;
1246 void wheelEvent( QWheelEvent *e ) override;
1247 void resizeEvent( QResizeEvent *e ) override;
1248 void paintEvent( QPaintEvent *e ) override;
1249 void dragEnterEvent( QDragEnterEvent *e ) override;
1250 bool viewportEvent( QEvent *event ) override;
1251
1253 void moveCanvasContents( bool reset = false );
1254
1255 void dropEvent( QDropEvent *event ) override;
1256
1257 void showEvent( QShowEvent *event ) override;
1258
1264 void emitExtentsChanged();
1265
1267 class CanvasProperties;
1268
1270 std::unique_ptr<CanvasProperties> mCanvasProperties;
1271
1272#if 0
1273
1278 void connectNotify( const char *signal ) override;
1279#endif
1280
1281 protected slots:
1284
1285 private slots:
1286
1287 void layerRepaintRequested( bool deferred );
1288
1289 void autoRefreshTriggered();
1290
1291 void updateAutoRefreshTimer();
1292
1293 void projectThemesChanged();
1294
1295 void startPreviewJob( int number );
1296
1297 void temporalControllerModeChanged();
1298
1299 private:
1300 // Restore scale RAII
1301 class ScaleRestorer
1302 {
1303 public:
1304 ScaleRestorer( QgsMapCanvas *canvas )
1305 : mCanvas( canvas )
1306 {
1307 mLockedScale = mCanvas->mapSettings().scale();
1308 };
1309
1310 ~ScaleRestorer()
1311 {
1312 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1313 newExtent.scale( mLockedScale / mCanvas->mapSettings().scale() );
1314 mCanvas->mSettings.setExtent( newExtent );
1315 };
1316
1317 private:
1318 QgsMapCanvas *mCanvas;
1319 double mLockedScale;
1320 };
1321
1322 enum class CacheInvalidationType
1323 {
1324 Temporal = 1 << 0,
1325 Elevation = 1 << 1,
1326 };
1327
1328 QgsOverlayWidgetLayout *mLayout = nullptr;
1329
1330 Qgis::MapCanvasFlags mFlags;
1331
1333 QgsMapSettings mSettings;
1334
1336 QgsMapCanvasMap *mMap = nullptr;
1337
1338 QgsScreenHelper *mScreenHelper = nullptr;
1339
1344 QgsTemporalController *mController = nullptr;
1345
1347 bool mFrozen = false;
1348
1350 bool mRefreshScheduled = false;
1351
1353 bool mRefreshAfterJob = false;
1354
1356 bool mRenderFlag = true;
1357
1358 QFlags<CacheInvalidationType> mCacheInvalidations;
1359
1361 QPointer<QgsMapLayer> mCurrentLayer;
1362
1364 QGraphicsScene *mScene = nullptr;
1365
1367 QgsMapTool *mMapTool = nullptr;
1368
1370 QgsProject *mProject = nullptr;
1371
1373 QList<QgsRectangle> mLastExtent;
1374 int mLastExtentIndex = -1;
1375
1377 double mWheelZoomFactor = 2.0;
1378
1380 QTimer mMapUpdateTimer;
1381
1383 QgsMapRendererQImageJob *mJob = nullptr;
1384
1386 bool mJobCanceled = false;
1387
1389 std::unique_ptr<QgsLabelingResults> mLabelingResults;
1390
1392 bool mLabelingResultsOutdated = false;
1393
1398 std::unique_ptr<QgsRenderedItemResults> mRenderedItemResults;
1399
1404 std::unique_ptr<QgsRenderedItemResults> mPreviousRenderedItemResults;
1405
1411 bool mRenderedItemResultsOutdated = false;
1412
1414 bool mUseParallelRendering = false;
1415
1417 bool mDrawRenderingStats = false;
1418
1420 QgsMapRendererCache *mCache = nullptr;
1421
1422 QTimer *mResizeTimer = nullptr;
1423 QTimer *mRefreshTimer = nullptr;
1424
1425 QgsPreviewEffect *mPreviewEffect = nullptr;
1426
1427 QgsRectangle imageRect( const QImage &img, const QgsMapSettings &mapSettings );
1428
1429 QgsSnappingUtils *mSnappingUtils = nullptr;
1430
1431 QList<QgsMapRendererQImageJob *> mPreviewJobs;
1432
1434 bool mScaleLocked = false;
1435
1436 QgsExpressionContextScope mExpressionContextScope;
1437
1439 QRect mZoomRect;
1440
1442 bool mZoomDragging = false;
1443
1445 std::unique_ptr<QgsRubberBand> mZoomRubberBand;
1446
1447 QCursor mZoomCursor;
1448
1449 QTimer mAutoRefreshTimer;
1450
1451 QTimer mPreviewTimer;
1452 QMetaObject::Connection mPreviewTimerConnection;
1453
1454 QString mTheme;
1455
1456 QgsPointXY mCursorPoint;
1457
1458 bool mAnnotationsVisible = true;
1459
1460 bool mUsePreviewJobs = false;
1461
1462 QHash<QString, int> mLastLayerRenderTime;
1463
1464 QVector<QPointer<QgsCustomDropHandler>> mDropHandlers;
1465
1466 QgsDistanceArea mDa;
1467 QList<double> mZoomResolutions;
1468
1469 QList<QgsMapCanvasInteractionBlocker *> mInteractionBlockers;
1470
1471 int mBlockItemPositionUpdates = 0;
1472 int mBlockExtentChangedSignal = 0;
1473 int mBlockScaleChangedSignal = 0;
1474
1475 std::unique_ptr<QgsTemporaryCursorOverride> mTemporaryCursorOverride;
1476
1484 QMap<QString, QDateTime> mRendererErrors;
1485
1486
1487 QPointer<QgsAbstract2DMapController> mMapController;
1488
1493 QgsPointXY cursorPoint() const;
1494
1498 void updateMapSize();
1499
1504 void beginZoomRect( QPoint pos );
1505
1510 void endZoomRect( QPoint pos );
1511
1513 void stopZoomRect();
1514
1516 void startPan();
1517
1519 void stopPan();
1520
1529 bool boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorLayer *layer, QgsRectangle &bbox, QString &errorMsg ) const;
1530
1537 QgsRectangle optimalExtentForPointLayer( QgsVectorLayer *layer, const QgsPointXY &center, int scaleFactor = 5 );
1538
1539 void setLayersPrivate( const QList<QgsMapLayer *> &layers );
1540
1541 void startPreviewJobs();
1542 void stopPreviewJobs();
1543 void schedulePreviewJob( int number );
1544
1548 bool panOperationInProgress();
1549
1550 int nextZoomLevel( const QList<double> &resolutions, bool zoomIn = true ) const;
1551
1556 void clearTemporalCache();
1557
1561 void clearElevationCache();
1562
1563 void showContextMenu( QgsMapMouseEvent *event );
1564
1569 void notifyRendererErrors( const QgsMapRendererJob::Errors &errors );
1570
1571 friend class TestQgsMapCanvas;
1572
1573}; // class QgsMapCanvas
1574
1575// clazy:excludeall=qstring-allocations
1576
1577#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
DistanceUnit
Units of distance.
Definition qgis.h:5013
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
@ Info
Information message.
Definition qgis.h:157
QFlags< MapCanvasFlag > MapCanvasFlags
Flags controlling behavior of map canvases.
Definition qgis.h:3468
Abstract base class for all 2D map controllers.
Abstract base class for all geometries.
Represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
QgsRange which stores a range of double values.
Definition qgsrange.h:233
Abstract interface for generating an expression context.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
Highlights features on the map.
Stores global configuration for labeling engine.
Stores computed placement from labeling engine.
An interactive map canvas item which displays a QgsAnnotation.
An interface for objects which block interactions with a QgsMapCanvas.
Interaction
Available interactions to block.
Deprecated to be deleted, stuff from here should be moved elsewhere.
void setCurrentLayer(QgsMapLayer *layer)
void contextMenuAboutToShow(QMenu *menu, QgsMapMouseEvent *event)
Emitted before the map canvas context menu will be shown.
void zoomToProjectExtent()
Zoom to the full extent the project associated with this canvas.
void panToSelected(QgsMapLayer *layer=nullptr)
Pan to the selected features of current ayer keeping same extent.
bool isCachingEnabled() const
Check whether images of rendered layers are curerently being cached.
void zoomToFullExtent()
Zoom to the full extent of all layers currently visible in the canvas.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers that should be shown in the canvas.
void setProject(QgsProject *project)
Sets the project linked to this canvas.
const QgsRenderedItemResults * renderedItemResults(bool allowOutdatedResults=true) const
Gets access to the rendered item results (may be nullptr), which includes the results of rendering an...
QColor selectionColor() const
Returns color for selected features.
bool event(QEvent *e) override
void setCachingEnabled(bool enabled)
Set whether to cache images of rendered layers.
void mouseReleaseEvent(QMouseEvent *e) override
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
void selectionChanged(QgsMapLayer *layer)
Emitted when selection in any layer gets changed.
void updateCanvasItemPositions()
called on resize or changed extent to notify canvas items to change their rectangle
void extentsChanged()
Emitted when the extents of the map change.
void xyCoordinates(const QgsPointXY &p)
Emits current mouse position.
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
void setFlags(Qgis::MapCanvasFlags flags)
Sets flags which control how the map canvas behaves.
bool previewJobsEnabled
QgsPointXY center() const
Gets map center, in geographical coordinates.
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 showEvent(QShowEvent *event) override
int layerCount() const
Returns number of layers on the map.
void emitExtentsChanged()
Emits the extentsChanged signal when appropriate.
QString theme() const
Returns the map's theme shown in the canvas, if set.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
void clearCache()
Make sure to remove any rendered images from cache (does nothing if cache is not enabled).
void tapAndHoldGestureOccurred(const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
Emitted whenever a tap and hold gesture occurs at the specified map point.
void setCanvasColor(const QColor &_newVal)
Write property of QColor bgColor.
const QList< double > & zoomResolutions() const
Returns the list of resolutions to which to "snap to" when zooming the map.
void panDistanceBearingChanged(double distance, Qgis::DistanceUnit unit, double bearing)
Emitted whenever the distance or bearing of an in-progress panning operation is changed.
const QgsTemporalController * temporalController() const
Gets access to the temporal controller that will be used to update the canvas temporal range.
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 setMapUpdateInterval(int timeMilliseconds)
Set how often map preview should be updated while it is being rendered (in milliseconds).
bool scaleLocked() const
Returns whether the scale is locked, so zooming can be performed using magnication.
bool setReferencedExtent(const QgsReferencedRectangle &extent)
Sets the canvas to the specified extent.
void dragEnterEvent(QDragEnterEvent *e) override
QgsMapRendererCache * cache()
Returns the map renderer cache, if caching is enabled.
void zRangeChanged()
Emitted when the map canvas z (elevation) range changes.
void keyPressEvent(QKeyEvent *e) override
void clearExtentHistory()
Clears the list of extents and sets current extent as first item.
void zoomToPreviousExtent()
Zoom to the previous extent (view).
friend class TestQgsMapCanvas
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers shown within the map canvas.
void scaleChanged(double scale)
Emitted when the scale of the map changes.
void mapToolSet(QgsMapTool *newTool, QgsMapTool *oldTool)
Emit map tool changed with the old tool.
void canvasColorChanged()
Emitted when canvas background color changes.
void moveCanvasContents(bool reset=false)
called when panning is in action, reset indicates end of panning
void magnificationChanged(double magnification)
Emitted when the scale of the map changes.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
void setTemporalController(QgsTemporalController *controller)
Sets the temporal controller for this canvas.
void renderErrorOccurred(const QString &error, QgsMapLayer *layer)
Emitted whenever an error is encountered during a map render operation.
void addOverlayWidget(QWidget *widget, Qt::Edge edge)
Adds an overlay widget to the layout, which will be bound to the specified edge.
void waitWhileRendering()
Blocks until the rendering job has finished.
void mapRefreshCanceled()
Emitted when the pending map refresh has been canceled.
double magnificationFactor() const
Returns the magnification factor.
void mousePressEvent(QMouseEvent *e) override
void updateScale()
Emits signal scaleChanged to update scale in main window.
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
void resizeEvent(QResizeEvent *e) override
void renderStarting()
Emitted when the canvas is about to be rendered.
void setMapSettingsFlags(Qgis::MapSettingsFlags flags)
Resets the flags for the canvas' map settings.
std::unique_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
void keyReleased(QKeyEvent *e)
Emit key release event.
QgsMapTool * mapTool() const
Returns the currently active tool.
const QgsExpressionContextScope & expressionContextScope() const
Returns a const reference to the expression context scope for the map canvas.
void layerStyleOverridesChanged()
Emitted when the configuration of overridden layer styles changes.
QgsMapCanvas(QWidget *parent=nullptr)
Constructor.
void zoomNextStatusChanged(bool available)
Emitted when zoom next status changed.
void setPreviewJobsEnabled(bool enabled)
Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just...
QgsRectangle fullExtent() const
Returns the combined extent for all layers on the map canvas.
void keyReleaseEvent(QKeyEvent *e) override
void rotationChanged(double rotation)
Emitted when the rotation of the map changes.
void panToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter=true)
Centers canvas extent to feature ids.
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 scaleLockChanged(bool locked)
Emitted when the scale locked state of the map changes.
const QgsLabelingResults * labelingResults(bool allowOutdatedResults=true) const
Gets access to the labeling results (may be nullptr).
void mouseMoveEvent(QMouseEvent *e) override
bool renderFlag() const
Returns true if canvas render is disabled as a result of user disabling renders via the GUI.
QgsRectangle projectExtent() const
Returns the associated project's full extent, in the canvas' CRS.
void setCenter(const QgsPointXY &center)
Set the center of the map canvas, in geographical coordinates.
void setParallelRenderingEnabled(bool enabled)
Set whether the layers are rendered in parallel or sequentially.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets destination coordinate reference system.
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.
bool isParallelRenderingEnabled() const
Check whether the layers are rendered in parallel or sequentially.
double scale() const
Returns the last reported scale of the canvas.
double rotation() const
Gets the current map canvas rotation in clockwise degrees.
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
void paintEvent(QPaintEvent *e) override
void zoomLastStatusChanged(bool available)
Emitted when zoom last status changed.
void themeChanged(const QString &theme)
Emitted when the canvas has been assigned a different map theme.
void destinationCrsChanged()
Emitted when map CRS has changed.
void transformContextChanged()
Emitted when the canvas transform context is changed.
void keyPressed(QKeyEvent *e)
Emit key press event.
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
QColor canvasColor() const
Read property of QColor bgColor.
void mapCanvasRefreshed()
Emitted when canvas finished a refresh request.
int mapUpdateInterval() const
Find out how often map preview should be updated while it is being rendered (in milliseconds).
void setSelectionColor(const QColor &color)
Set color of selected vector features.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
void mouseDoubleClickEvent(QMouseEvent *e) override
bool viewportEvent(QEvent *event) override
void zoomToNextExtent()
Zoom to the next extent (view).
void layersChanged()
Emitted when a new set of layers has been received.
void zoomToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids)
Set canvas extent to the bounding box of a set of features.
void renderComplete(QPainter *painter)
Emitted when the canvas has rendered.
QgsMapLayer * layer(int index)
Returns the map layer at position index in the layer stack.
bool annotationsVisible() const
Returns true if annotations are visible within the map canvas.
void cancelJobs()
Cancel any rendering job, in a blocking way.
Qgis::MapCanvasFlags flags() const
Returns flags which control how the map canvas behaves.
void wheelEvent(QWheelEvent *e) override
void dropEvent(QDropEvent *event) override
QgsProject * project()
Returns the project linked to this canvas.
void setRotation(double degrees)
Set the rotation of the map canvas in clockwise degrees.
void setTheme(const QString &theme)
Sets a map theme to show in the canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope for the map canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:80
A mouse event which is the result of a user interaction with a QgsMapCanvas.
A widget that displays an overview map.
Responsible for keeping a cache of rendered images resulting from a map rendering job.
QList< QgsMapRendererJob::Error > Errors
Intermediate base class adding functionality that allows a client to query the rendered image.
Contains configuration for rendering maps.
Perform transforms between map coordinates and device coordinates.
Abstract base class for all map tools.
Definition qgsmaptool.h:72
A custom layout which can be used to overlay child widgets over a parent widget.
Represents a 2D point.
Definition qgspointxy.h:60
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
A rectangle specified with double values.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
A QgsRectangle with associated coordinate reference system.
Stores collated details of rendered items during a map rendering operation.
Responsible for drawing transient features (e.g.
A utility class for dynamic handling of changes to screen properties.
Contains configuration of snapping and can return answers to snapping queries.
A controller base class for temporal objects, contains a signal for notifying updates of the objects ...
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Represents a vector layer which manages a vector based dataset.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:94
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
#define SIP_END
Definition qgis_sip.h:216
QSet< QgsFeatureId > QgsFeatureIds
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761