QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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;
75class QgsStatusBar;
76
78class QgsScreenHelper;
79
81
82class QMenu;
84
85
90
91class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContextGenerator
92{
93#ifdef SIP_RUN
95 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
96 sipType = sipType_QgsMapCanvas;
97 else
98 sipType = nullptr;
100#endif
101
102 Q_OBJECT
103 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
105
106 public:
108 QgsMapCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
109
110 ~QgsMapCanvas() override;
111
122 void addOverlayWidget( QWidget *widget SIP_TRANSFER, Qt::Edge edge );
123
127 double magnificationFactor() const;
128
139 void setLayers( const QList<QgsMapLayer *> &layers );
140
147 void setFlags( Qgis::MapCanvasFlags flags );
148
155 Qgis::MapCanvasFlags flags() const;
156
158
163
171
179
187
192
196 void setMapSettingsFlags( Qgis::MapSettingsFlags flags );
197
205 const QgsLabelingResults *labelingResults( bool allowOutdatedResults = true ) const;
206
216 const QgsRenderedItemResults *renderedItemResults( bool allowOutdatedResults = true ) const;
217
225 void setCachingEnabled( bool enabled );
226
234 bool isCachingEnabled() const;
235
239 void clearCache();
240
250
255 void cancelJobs() SIP_SKIP;
256
265 void waitWhileRendering();
266
270 void setParallelRenderingEnabled( bool enabled );
271
275 bool isParallelRenderingEnabled() const;
276
280 void setMapUpdateInterval( int timeMilliseconds );
281
285 int mapUpdateInterval() const;
286
291 double scale() const;
292
294 double mapUnitsPerPixel() const;
295
297 QgsRectangle extent() const;
298
307 QgsRectangle fullExtent() const;
308
319
331 void setExtent( const QgsRectangle &r, bool magnified = false );
332
342
346 double rotation() const;
347
351 void setRotation( double degrees );
352
356 void setCenter( const QgsPointXY &center );
357
361 QgsPointXY center() const;
362
368 void zoomToFullExtent();
369
378 void zoomToProjectExtent();
379
382
384 void zoomToNextExtent();
385
387 void clearExtentHistory();
388
389
396
403 void panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter = true );
404
406 void panToSelected( QgsMapLayer *layer = nullptr );
407
413 void panToSelected( const QList<QgsMapLayer *> &layers );
414
426 void flashFeatureIds(
427 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
428 );
429
441 void flashGeometries(
442 const QList<QgsGeometry> &geometries,
444 const QColor &startColor = QColor( 255, 0, 0, 255 ),
445 const QColor &endColor = QColor( 255, 0, 0, 0 ),
446 int flashes = 3,
447 int duration = 500
448 );
449
451 void setMapTool( QgsMapTool *mapTool, bool clean = false );
452
461
463 QgsMapTool *mapTool() const;
464
471
479
481 void setCanvasColor( const QColor &_newVal );
483 QColor canvasColor() const;
484
488 void setSelectionColor( const QColor &color );
489
493 QColor selectionColor() const;
494
496 void updateScale();
497
499 QgsMapLayer *layer( int index );
500
511 QgsMapLayer *layer( const QString &id );
512
516 int layerCount() const;
517
526 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
527
528#ifndef SIP_RUN
535 template<typename T> QVector<T> layers() const { return mapSettings().layers<T>(); }
536#endif
537
549 void freeze( bool frozen = true );
550
560 bool isFrozen() const;
561
572 bool renderFlag() const { return mRenderFlag; }
573
578 Qgis::DistanceUnit mapUnits() const;
579
584 QMap<QString, QString> layerStyleOverrides() const;
585
596 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
597
618 void setTheme( const QString &theme );
619
624 QString theme() const { return mTheme; }
625
627 const QgsMapToPixel *getCoordinateTransform();
628
630 bool isDrawing();
631
633 QgsMapLayer *currentLayer();
634
636 void setWheelFactor( double factor );
637
645 void zoomScale( double scale, bool ignoreScaleLock = false );
646
654 void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr, bool ignoreScaleLock = false );
655
657 void zoomWithCenter( int x, int y, bool zoomIn );
658
663 void zoomToFeatureExtent( QgsRectangle &rect );
664
669 bool scaleLocked() const { return mScaleLocked; }
670
672 void enableAntiAliasing( bool flag );
673
675 bool antiAliasingEnabled() const;
676
678 void enableMapTileRendering( bool flag );
679
680 // following 2 methods should be moved elsewhere or changed to private
681 // currently used by pan map tool
683 void panActionEnd( QPoint releasePoint );
684
685#ifndef SIP_RUN
686
692 void panActionStart( QPoint releasePoint );
693#endif
694
696 void panAction( QMouseEvent *event );
697
699 QPoint mouseLastXY();
700
706 void setPreviewModeEnabled( bool previewEnabled );
707
714 bool previewModeEnabled() const;
715
724 void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
725
733 QgsPreviewEffect::PreviewMode previewMode() const;
734
742 QgsSnappingUtils *snappingUtils() const;
743
751 void setSnappingUtils( QgsSnappingUtils *utils );
752
762 void setExpressionContextScope( const QgsExpressionContextScope &scope ) { mExpressionContextScope = scope; }
763
771 QgsExpressionContextScope &expressionContextScope() { return mExpressionContextScope; }
772
779 const QgsExpressionContextScope &expressionContextScope() const SIP_SKIP { return mExpressionContextScope; }
780
787 QgsExpressionContextScope *defaultExpressionContextScope() const SIP_FACTORY;
788
789 QgsExpressionContext createExpressionContext() const override;
790
795 void setSegmentationTolerance( double tolerance );
796
801 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
802
806 QList<QgsMapCanvasAnnotationItem *> annotationItems() const;
807
812 bool annotationsVisible() const { return mAnnotationsVisible; }
813
818 void setAnnotationsVisible( bool visible );
819
823 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
824
828 const QgsLabelingEngineSettings &labelingEngineSettings() const;
829
835 void setSelectiveMaskingSourceSets( const QVector< QgsSelectiveMaskingSourceSet > &sets );
836
844 bool previewJobsEnabled() const;
845
853 void setPreviewJobsEnabled( bool enabled );
854
860 void setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHandler>> &handlers ) SIP_SKIP;
861
872 void setTemporalRange( const QgsDateTimeRange &range );
873
880 const QgsDateTimeRange &temporalRange() const;
881
893 void installInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
894
902 void removeInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
903
909 bool allowInteraction( QgsMapCanvasInteractionBlocker::Interaction interaction ) const;
910
918 void setMapController( QgsAbstract2DMapController *controller SIP_TRANSFER );
919
928 QgsStatusBar *statusBar();
929
936 void setStatusBar( QgsStatusBar *bar );
937
938 public slots:
939
941 void refresh();
942
951 void refreshAllLayers();
952
961 void redrawAllLayers();
962
964 void selectionChangedSlot();
965
967 void saveAsImage( const QString &fileName, QPixmap *QPixmap = nullptr, const QString & = "PNG" );
968
970 void layerStateChange();
971
981 void setRenderFlag( bool flag );
982
986 void stopRendering();
987
989 void readProject( const QDomDocument & );
990
992 void writeProject( QDomDocument & );
993
1001 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
1002
1007 void setScaleLocked( bool isLocked );
1008
1010 void zoomIn();
1011
1013 void zoomOut();
1014
1019 void zoomToSelected( QgsMapLayer *layer = nullptr );
1020
1026 void zoomToSelected( const QList<QgsMapLayer *> &layers );
1027
1033 void setZoomResolutions( const QList<double> &resolutions ) { mZoomResolutions = resolutions; }
1034
1038 double zoomInFactor() const;
1039
1043 double zoomOutFactor() const;
1044
1051 const QList<double> &zoomResolutions() const { return mZoomResolutions; }
1052
1061 QgsDoubleRange zRange() const;
1062
1071 void setZRange( const QgsDoubleRange &range );
1072
1073 private slots:
1075 void mapToolDestroyed();
1076
1078 void rendererJobFinished();
1079
1081 void previewJobFinished();
1082
1083 void mapUpdateTimeout();
1084
1085 void refreshMap();
1086
1087 void mapThemeChanged( const QString &theme );
1089 void mapThemeRenamed( const QString &theme, const QString &newTheme );
1090
1091 void updateDevicePixelFromScreen();
1092
1093 void onElevationShadingRendererChanged();
1094
1095 signals:
1096
1101 void xyCoordinates( const QgsPointXY &p );
1102
1104 void scaleChanged( double scale );
1105
1112 void scaleLockChanged( bool locked );
1113
1114
1117
1122
1126 void magnificationChanged( double magnification );
1127
1132
1133 // TODO: deprecate when decorations are reimplemented as map canvas items
1134
1145 void renderComplete( QPainter *painter );
1146
1147 // ### QGIS 3: renamte to mapRefreshFinished()
1150
1151 // ### QGIS 3: rename to mapRefreshStarted()
1154
1160
1163
1165 void keyPressed( QKeyEvent *e );
1166
1168 void keyReleased( QKeyEvent *e );
1169
1173 void mapToolSet( QgsMapTool *newTool, QgsMapTool *oldTool );
1174
1181
1183 void zoomLastStatusChanged( bool available );
1184
1186 void zoomNextStatusChanged( bool available );
1187
1192
1197
1202
1207
1212 void themeChanged( const QString &theme );
1213
1215 void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
1216
1224 void renderErrorOccurred( const QString &error, QgsMapLayer *layer );
1225
1236 void panDistanceBearingChanged( double distance, Qgis::DistanceUnit unit, double bearing );
1237
1242 void tapAndHoldGestureOccurred( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
1243
1250
1260
1268
1269 protected:
1270 bool event( QEvent *e ) override;
1271 void keyPressEvent( QKeyEvent *e ) override;
1272 void keyReleaseEvent( QKeyEvent *e ) override;
1273 void mouseDoubleClickEvent( QMouseEvent *e ) override;
1274 void mouseMoveEvent( QMouseEvent *e ) override;
1275 void mousePressEvent( QMouseEvent *e ) override;
1276 void mouseReleaseEvent( QMouseEvent *e ) override;
1277 void wheelEvent( QWheelEvent *e ) override;
1278 void resizeEvent( QResizeEvent *e ) override;
1279 void paintEvent( QPaintEvent *e ) override;
1280 void dragEnterEvent( QDragEnterEvent *e ) override;
1281 bool viewportEvent( QEvent *event ) override;
1282
1284 void moveCanvasContents( bool reset = false );
1285
1286 void dropEvent( QDropEvent *event ) override;
1287
1288 void showEvent( QShowEvent *event ) override;
1289
1295 void emitExtentsChanged();
1296
1298 class CanvasProperties;
1299
1301 std::unique_ptr<CanvasProperties> mCanvasProperties;
1302
1303#if 0
1304
1309 void connectNotify( const char *signal ) override;
1310#endif
1311
1312 protected slots:
1315
1316 private slots:
1317
1318 void layerRepaintRequested( bool deferred );
1319
1320 void autoRefreshTriggered();
1321
1322 void updateAutoRefreshTimer();
1323
1324 void projectThemesChanged();
1325
1326 void startPreviewJob( int number );
1327
1328 void temporalControllerModeChanged();
1329
1330 private:
1331 // Restore scale RAII
1332 class ScaleRestorer
1333 {
1334 public:
1335 ScaleRestorer( QgsMapCanvas *canvas )
1336 : mCanvas( canvas )
1337 {
1338 mLockedScale = mCanvas->mapSettings().scale();
1339 };
1340
1341 ~ScaleRestorer()
1342 {
1343 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1344 newExtent.scale( mLockedScale / mCanvas->mapSettings().scale() );
1345 mCanvas->mSettings.setExtent( newExtent );
1346 };
1347
1348 private:
1349 QgsMapCanvas *mCanvas;
1350 double mLockedScale;
1351 };
1352
1353 enum class CacheInvalidationType
1354 {
1355 Temporal = 1 << 0,
1356 Elevation = 1 << 1,
1357 };
1358
1359 QgsOverlayWidgetLayout *mLayout = nullptr;
1360
1361 Qgis::MapCanvasFlags mFlags;
1362
1364 QgsMapSettings mSettings;
1365
1367 QgsMapCanvasMap *mMap = nullptr;
1368
1369 QgsScreenHelper *mScreenHelper = nullptr;
1370
1375 QgsTemporalController *mController = nullptr;
1376
1378 bool mFrozen = false;
1379
1381 bool mRefreshScheduled = false;
1382
1384 bool mRefreshAfterJob = false;
1385
1387 bool mRenderFlag = true;
1388
1389 QFlags<CacheInvalidationType> mCacheInvalidations;
1390
1392 QPointer<QgsMapLayer> mCurrentLayer;
1393
1395 QGraphicsScene *mScene = nullptr;
1396
1398 QgsMapTool *mMapTool = nullptr;
1399
1401 QgsProject *mProject = nullptr;
1402
1404 QList<QgsRectangle> mLastExtent;
1405 int mLastExtentIndex = -1;
1406
1408 double mWheelZoomFactor = 2.0;
1409
1411 QTimer mMapUpdateTimer;
1412
1414 QgsMapRendererQImageJob *mJob = nullptr;
1415
1417 bool mJobCanceled = false;
1418
1420 std::unique_ptr<QgsLabelingResults> mLabelingResults;
1421
1423 bool mLabelingResultsOutdated = false;
1424
1429 std::unique_ptr<QgsRenderedItemResults> mRenderedItemResults;
1430
1435 std::unique_ptr<QgsRenderedItemResults> mPreviousRenderedItemResults;
1436
1442 bool mRenderedItemResultsOutdated = false;
1443
1445 bool mUseParallelRendering = false;
1446
1448 bool mDrawRenderingStats = false;
1449
1451 QgsMapRendererCache *mCache = nullptr;
1452
1453 QTimer *mResizeTimer = nullptr;
1454 QTimer *mRefreshTimer = nullptr;
1455
1456 QgsPreviewEffect *mPreviewEffect = nullptr;
1457
1458 QgsRectangle imageRect( const QImage &img, const QgsMapSettings &mapSettings );
1459
1460 QgsSnappingUtils *mSnappingUtils = nullptr;
1461
1462 QList<QgsMapRendererQImageJob *> mPreviewJobs;
1463
1465 bool mScaleLocked = false;
1466
1467 QgsExpressionContextScope mExpressionContextScope;
1468
1470 QRect mZoomRect;
1471
1473 bool mZoomDragging = false;
1474
1476 std::unique_ptr<QgsRubberBand> mZoomRubberBand;
1477
1478 QCursor mZoomCursor;
1479
1480 QTimer mAutoRefreshTimer;
1481
1482 QTimer mPreviewTimer;
1483 QMetaObject::Connection mPreviewTimerConnection;
1484
1485 QString mTheme;
1486
1487 QgsPointXY mCursorPoint;
1488
1489 bool mAnnotationsVisible = true;
1490
1491 bool mUsePreviewJobs = false;
1492
1493 QHash<QString, int> mLastLayerRenderTime;
1494
1495 QVector<QPointer<QgsCustomDropHandler>> mDropHandlers;
1496
1497 QgsDistanceArea mDa;
1498 QList<double> mZoomResolutions;
1499
1500 QList<QgsMapCanvasInteractionBlocker *> mInteractionBlockers;
1501
1502 int mBlockItemPositionUpdates = 0;
1503 int mBlockExtentChangedSignal = 0;
1504 int mBlockScaleChangedSignal = 0;
1505
1506 std::unique_ptr<QgsTemporaryCursorOverride> mTemporaryCursorOverride;
1507
1515 QMap<QString, QDateTime> mRendererErrors;
1516
1517
1518 QPointer<QgsAbstract2DMapController> mMapController;
1519
1520 QPointer< QgsStatusBar > mStatusBar;
1521
1526 QgsPointXY cursorPoint() const;
1527
1531 void updateMapSize();
1532
1537 void beginZoomRect( QPoint pos );
1538
1543 void endZoomRect( QPoint pos );
1544
1546 void stopZoomRect();
1547
1549 void startPan();
1550
1552 void stopPan();
1553
1562 bool boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorLayer *layer, QgsRectangle &bbox, QString &errorMsg ) const;
1563
1570 QgsRectangle optimalExtentForPointLayer( QgsVectorLayer *layer, const QgsPointXY &center, int scaleFactor = 5 );
1571
1572 void setLayersPrivate( const QList<QgsMapLayer *> &layers );
1573
1574 void startPreviewJobs();
1575 void stopPreviewJobs();
1576 void schedulePreviewJob( int number );
1577
1581 bool panOperationInProgress();
1582
1583 int nextZoomLevel( const QList<double> &resolutions, bool zoomIn = true ) const;
1584
1589 void clearTemporalCache();
1590
1594 void clearElevationCache();
1595
1596 void showContextMenu( QgsMapMouseEvent *event );
1597
1602 void notifyRendererErrors( const QgsMapRendererJob::Errors &errors );
1603
1604 friend class TestQgsMapCanvas;
1605
1606}; // class QgsMapCanvas
1607
1608// clazy:excludeall=qstring-allocations
1609
1610#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
DistanceUnit
Units of distance.
Definition qgis.h:5170
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:160
@ Info
Information message.
Definition qgis.h:161
QFlags< MapCanvasFlag > MapCanvasFlags
Flags controlling behavior of map canvases.
Definition qgis.h:3582
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:217
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:83
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:62
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
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 proxy widget for QStatusBar.
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:198
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:93
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
#define SIP_END
Definition qgis_sip.h:215
QSet< QgsFeatureId > QgsFeatureIds
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:705