QGIS API Documentation 4.1.0-Master (467af3bbe65)
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;
59class QgsVectorLayer;
60
62
65class QgsMapSettings;
66class QgsMapCanvasMap;
68class QgsMapTool;
70class QgsRubberBand;
76class QgsStatusBar;
77
79class QgsScreenHelper;
80
82
83class QMenu;
85
86
91
92class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContextGenerator
93{
94#ifdef SIP_RUN
96 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
97 sipType = sipType_QgsMapCanvas;
98 else
99 sipType = nullptr;
100 SIP_END
101#endif
102
103 Q_OBJECT
104 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
106
107 public:
109 QgsMapCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
110
111 ~QgsMapCanvas() override;
112
123 void addOverlayWidget( QWidget *widget SIP_TRANSFER, Qt::Edge edge );
124
128 double magnificationFactor() const;
129
140 void setLayers( const QList<QgsMapLayer *> &layers );
141
148 void setFlags( Qgis::MapCanvasFlags flags );
149
156 Qgis::MapCanvasFlags flags() const;
157
159
164
172
180
188
193
197 void setMapSettingsFlags( Qgis::MapSettingsFlags flags );
198
206 const QgsLabelingResults *labelingResults( bool allowOutdatedResults = true ) const;
207
217 const QgsRenderedItemResults *renderedItemResults( bool allowOutdatedResults = true ) const;
218
226 void setCachingEnabled( bool enabled );
227
235 bool isCachingEnabled() const;
236
240 void clearCache();
241
251
256 void cancelJobs() SIP_SKIP;
257
266 void waitWhileRendering();
267
271 void setParallelRenderingEnabled( bool enabled );
272
276 bool isParallelRenderingEnabled() const;
277
281 void setMapUpdateInterval( int timeMilliseconds );
282
286 int mapUpdateInterval() const;
287
292 double scale() const;
293
295 double mapUnitsPerPixel() const;
296
298 QgsRectangle extent() const;
299
308 QgsRectangle fullExtent() const;
309
320
332 void setExtent( const QgsRectangle &r, bool magnified = false );
333
343
347 double rotation() const;
348
352 void setRotation( double degrees );
353
357 void setCenter( const QgsPointXY &center );
358
362 QgsPointXY center() const;
363
369 void zoomToFullExtent();
370
379 void zoomToProjectExtent();
380
383
385 void zoomToNextExtent();
386
388 void clearExtentHistory();
389
390
397
404 void panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter = true );
405
407 void panToSelected( QgsMapLayer *layer = nullptr );
408
414 void panToSelected( const QList<QgsMapLayer *> &layers );
415
427 void flashFeatureIds(
428 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
429 );
430
442 void flashGeometries(
443 const QList<QgsGeometry> &geometries,
445 const QColor &startColor = QColor( 255, 0, 0, 255 ),
446 const QColor &endColor = QColor( 255, 0, 0, 0 ),
447 int flashes = 3,
448 int duration = 500
449 );
450
452 void setMapTool( QgsMapTool *mapTool, bool clean = false );
453
462
464 QgsMapTool *mapTool() const;
465
472
480
482 void setCanvasColor( const QColor &_newVal );
484 QColor canvasColor() const;
485
489 void setSelectionColor( const QColor &color );
490
494 QColor selectionColor() const;
495
497 void updateScale();
498
500 QgsMapLayer *layer( int index );
501
512 QgsMapLayer *layer( const QString &id );
513
517 int layerCount() const;
518
527 QList<QgsMapLayer *> layers( bool expandGroupLayers = false ) const;
528
529#ifndef SIP_RUN
536 template<typename T> QVector<T> layers() const { return mapSettings().layers<T>(); }
537#endif
538
550 void freeze( bool frozen = true );
551
561 bool isFrozen() const;
562
573 bool renderFlag() const { return mRenderFlag; }
574
579 Qgis::DistanceUnit mapUnits() const;
580
585 QMap<QString, QString> layerStyleOverrides() const;
586
597 void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
598
619 void setTheme( const QString &theme );
620
625 QString theme() const { return mTheme; }
626
628 const QgsMapToPixel *getCoordinateTransform();
629
631 bool isDrawing();
632
634 QgsMapLayer *currentLayer();
635
637 void setWheelFactor( double factor );
638
646 void zoomScale( double scale, bool ignoreScaleLock = false );
647
655 void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr, bool ignoreScaleLock = false );
656
658 void zoomWithCenter( int x, int y, bool zoomIn );
659
664 void zoomToFeatureExtent( QgsRectangle &rect );
665
670 bool scaleLocked() const { return mScaleLocked; }
671
673 void enableAntiAliasing( bool flag );
674
676 bool antiAliasingEnabled() const;
677
679 void enableMapTileRendering( bool flag );
680
681 // following 2 methods should be moved elsewhere or changed to private
682 // currently used by pan map tool
684 void panActionEnd( QPoint releasePoint );
685
686#ifndef SIP_RUN
687
693 void panActionStart( QPoint releasePoint );
694#endif
695
697 void panAction( QMouseEvent *event );
698
700 QPoint mouseLastXY();
701
707 void setPreviewModeEnabled( bool previewEnabled );
708
715 bool previewModeEnabled() const;
716
725 void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
726
734 QgsPreviewEffect::PreviewMode previewMode() const;
735
743 QgsSnappingUtils *snappingUtils() const;
744
752 void setSnappingUtils( QgsSnappingUtils *utils );
753
763 void setExpressionContextScope( const QgsExpressionContextScope &scope ) { mExpressionContextScope = scope; }
764
772 QgsExpressionContextScope &expressionContextScope() { return mExpressionContextScope; }
773
780 const QgsExpressionContextScope &expressionContextScope() const SIP_SKIP { return mExpressionContextScope; }
781
788 QgsExpressionContextScope *defaultExpressionContextScope() const SIP_FACTORY;
789
790 QgsExpressionContext createExpressionContext() const override;
791
796 void setSegmentationTolerance( double tolerance );
797
802 void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
803
807 QList<QgsMapCanvasAnnotationItem *> annotationItems() const;
808
813 bool annotationsVisible() const { return mAnnotationsVisible; }
814
819 void setAnnotationsVisible( bool visible );
820
824 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
825
829 const QgsLabelingEngineSettings &labelingEngineSettings() const;
830
836 void setSelectiveMaskingSourceSets( const QVector< QgsSelectiveMaskingSourceSet > &sets );
837
845 bool previewJobsEnabled() const;
846
854 void setPreviewJobsEnabled( bool enabled );
855
861 void setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHandler>> &handlers ) SIP_SKIP;
862
873 void setTemporalRange( const QgsDateTimeRange &range );
874
881 const QgsDateTimeRange &temporalRange() const;
882
894 void installInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
895
903 void removeInteractionBlocker( QgsMapCanvasInteractionBlocker *blocker );
904
910 bool allowInteraction( QgsMapCanvasInteractionBlocker::Interaction interaction ) const;
911
919 void setMapController( QgsAbstract2DMapController *controller SIP_TRANSFER );
920
929 QgsStatusBar *statusBar();
930
937 void setStatusBar( QgsStatusBar *bar );
938
940
941 public slots:
942
944 void refresh();
945
954 void refreshAllLayers();
955
964 void redrawAllLayers();
965
968
970 void saveAsImage( const QString &fileName, QPixmap *QPixmap = nullptr, const QString & = "PNG" );
971
973 void layerStateChange();
974
984 void setRenderFlag( bool flag );
985
989 void stopRendering();
990
992 void readProject( const QDomDocument & );
993
995 void writeProject( QDomDocument & );
996
1004 void setMagnificationFactor( double factor, const QgsPointXY *center = nullptr );
1005
1010 void setScaleLocked( bool isLocked );
1011
1013 void zoomIn();
1014
1016 void zoomOut();
1017
1022 void zoomToSelected( QgsMapLayer *layer = nullptr );
1023
1029 void zoomToSelected( const QList<QgsMapLayer *> &layers );
1030
1036 void setZoomResolutions( const QList<double> &resolutions ) { mZoomResolutions = resolutions; }
1037
1041 double zoomInFactor() const;
1042
1046 double zoomOutFactor() const;
1047
1054 const QList<double> &zoomResolutions() const { return mZoomResolutions; }
1055
1064 QgsDoubleRange zRange() const;
1065
1074 void setZRange( const QgsDoubleRange &range );
1075
1076 private slots:
1078 void mapToolDestroyed();
1079
1081 void rendererJobFinished();
1082
1084 void previewJobFinished();
1085
1086 void mapUpdateTimeout();
1087
1088 void refreshMap();
1089
1090 void mapThemeChanged( const QString &theme );
1092 void mapThemeRenamed( const QString &theme, const QString &newTheme );
1093
1094 void updateDevicePixelFromScreen();
1095
1096 void onElevationShadingRendererChanged();
1097
1098 signals:
1099
1104 void xyCoordinates( const QgsPointXY &p );
1105
1107 void scaleChanged( double scale );
1108
1115 void scaleLockChanged( bool locked );
1116
1117
1120
1125
1129 void magnificationChanged( double magnification );
1130
1135
1136 // TODO: deprecate when decorations are reimplemented as map canvas items
1137
1148 void renderComplete( QPainter *painter );
1149
1150 // ### QGIS 3: renamte to mapRefreshFinished()
1153
1154 // ### QGIS 3: rename to mapRefreshStarted()
1157
1163
1166
1168 void keyPressed( QKeyEvent *e );
1169
1171 void keyReleased( QKeyEvent *e );
1172
1176 void mapToolSet( QgsMapTool *newTool, QgsMapTool *oldTool );
1177
1184
1186 void zoomLastStatusChanged( bool available );
1187
1189 void zoomNextStatusChanged( bool available );
1190
1195
1200
1205
1210
1215 void themeChanged( const QString &theme );
1216
1218 void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
1219
1227 void renderErrorOccurred( const QString &error, QgsMapLayer *layer );
1228
1239 void panDistanceBearingChanged( double distance, Qgis::DistanceUnit unit, double bearing );
1240
1245 void tapAndHoldGestureOccurred( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
1246
1253
1263
1271
1272 protected:
1273 bool event( QEvent *e ) override;
1274 void keyPressEvent( QKeyEvent *e ) override;
1275 void keyReleaseEvent( QKeyEvent *e ) override;
1276 void mouseDoubleClickEvent( QMouseEvent *e ) override;
1277 void mouseMoveEvent( QMouseEvent *e ) override;
1278 void mousePressEvent( QMouseEvent *e ) override;
1279 void mouseReleaseEvent( QMouseEvent *e ) override;
1280 void wheelEvent( QWheelEvent *e ) override;
1281 void resizeEvent( QResizeEvent *e ) override;
1282 void paintEvent( QPaintEvent *e ) override;
1283 void dragEnterEvent( QDragEnterEvent *e ) override;
1284 bool viewportEvent( QEvent *event ) override;
1285
1287 void moveCanvasContents( bool reset = false );
1288
1289 void dropEvent( QDropEvent *event ) override;
1290
1291 void showEvent( QShowEvent *event ) override;
1292
1298 void emitExtentsChanged();
1299
1301 class CanvasProperties;
1302
1304 std::unique_ptr<CanvasProperties> mCanvasProperties;
1305
1306#if 0
1307
1312 void connectNotify( const char *signal ) override;
1313#endif
1314
1315 protected slots:
1318
1319 private slots:
1320
1321 void layerRepaintRequested( bool deferred );
1322
1323 void autoRefreshTriggered();
1324
1325 void updateAutoRefreshTimer();
1326
1327 void projectThemesChanged();
1328
1329 void startPreviewJob( int number );
1330
1331 void temporalControllerModeChanged();
1332
1333 private:
1334 // Restore scale RAII
1335 class ScaleRestorer
1336 {
1337 public:
1338 ScaleRestorer( QgsMapCanvas *canvas )
1339 : mCanvas( canvas )
1340 {
1341 mLockedScale = mCanvas->mapSettings().scale();
1342 };
1343
1344 ~ScaleRestorer()
1345 {
1346 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1347 newExtent.scale( mLockedScale / mCanvas->mapSettings().scale() );
1348 mCanvas->mSettings.setExtent( newExtent );
1349 };
1350
1351 private:
1352 QgsMapCanvas *mCanvas;
1353 double mLockedScale;
1354 };
1355
1356 enum class CacheInvalidationType
1357 {
1358 Temporal = 1 << 0,
1359 Elevation = 1 << 1,
1360 };
1361
1362 QgsOverlayWidgetLayout *mLayout = nullptr;
1363
1364 Qgis::MapCanvasFlags mFlags;
1365
1367 QgsMapSettings mSettings;
1368
1370 QgsMapCanvasMap *mMap = nullptr;
1371
1372 QgsScreenHelper *mScreenHelper = nullptr;
1373
1378 QgsTemporalController *mController = nullptr;
1379
1381 bool mFrozen = false;
1382
1384 bool mRefreshScheduled = false;
1385
1387 bool mRefreshAfterJob = false;
1388
1390 bool mRenderFlag = true;
1391
1392 QFlags<CacheInvalidationType> mCacheInvalidations;
1393
1395 QPointer<QgsMapLayer> mCurrentLayer;
1396
1398 QGraphicsScene *mScene = nullptr;
1399
1401 QgsMapTool *mMapTool = nullptr;
1402
1404 QgsProject *mProject = nullptr;
1405
1407 QList<QgsRectangle> mLastExtent;
1408 int mLastExtentIndex = -1;
1409
1411 double mWheelZoomFactor = 2.0;
1412
1414 QTimer mMapUpdateTimer;
1415
1417 QgsMapRendererQImageJob *mJob = nullptr;
1418
1420 bool mJobCanceled = false;
1421
1423 std::unique_ptr<QgsLabelingResults> mLabelingResults;
1424
1426 bool mLabelingResultsOutdated = false;
1427
1432 std::unique_ptr<QgsRenderedItemResults> mRenderedItemResults;
1433
1438 std::unique_ptr<QgsRenderedItemResults> mPreviousRenderedItemResults;
1439
1445 bool mRenderedItemResultsOutdated = false;
1446
1448 bool mUseParallelRendering = false;
1449
1451 bool mDrawRenderingStats = false;
1452
1454 std::unique_ptr<QgsMapRendererCache> mCache;
1455
1456 QTimer *mResizeTimer = nullptr;
1457 QTimer *mRefreshTimer = nullptr;
1458
1459 QgsPreviewEffect *mPreviewEffect = nullptr;
1460
1461 QgsRectangle imageRect( const QImage &img, const QgsMapSettings &mapSettings );
1462
1463 QgsSnappingUtils *mSnappingUtils = nullptr;
1464
1465 QList<QgsMapRendererQImageJob *> mPreviewJobs;
1466
1468 bool mScaleLocked = false;
1469
1470 QgsExpressionContextScope mExpressionContextScope;
1471
1473 QRect mZoomRect;
1474
1476 bool mZoomDragging = false;
1477
1479 std::unique_ptr<QgsRubberBand> mZoomRubberBand;
1480
1481 QCursor mZoomCursor;
1482
1483 QTimer mAutoRefreshTimer;
1484
1485 QTimer mPreviewTimer;
1486 QMetaObject::Connection mPreviewTimerConnection;
1487
1488 QString mTheme;
1489
1490 QgsPointXY mCursorPoint;
1491
1492 bool mAnnotationsVisible = true;
1493
1494 bool mUsePreviewJobs = false;
1495
1496 QHash<QString, int> mLastLayerRenderTime;
1497
1498 QVector<QPointer<QgsCustomDropHandler>> mDropHandlers;
1499
1500 QgsDistanceArea mDa;
1501 QList<double> mZoomResolutions;
1502
1503 QList<QgsMapCanvasInteractionBlocker *> mInteractionBlockers;
1504
1505 int mBlockItemPositionUpdates = 0;
1506 int mBlockExtentChangedSignal = 0;
1507 int mBlockScaleChangedSignal = 0;
1508
1509 std::unique_ptr<QgsTemporaryCursorOverride> mTemporaryCursorOverride;
1510
1518 QMap<QString, QDateTime> mRendererErrors;
1519
1520
1521 QPointer<QgsAbstract2DMapController> mMapController;
1522
1523 QPointer< QgsStatusBar > mStatusBar;
1524
1529 QgsPointXY cursorPoint() const;
1530
1534 void updateMapSize();
1535
1540 void beginZoomRect( QPoint pos );
1541
1546 void endZoomRect( QPoint pos );
1547
1549 void stopZoomRect();
1550
1552 void startPan();
1553
1555 void stopPan();
1556
1565 bool boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorLayer *layer, QgsRectangle &bbox, QString &errorMsg ) const;
1566
1573 QgsRectangle optimalExtentForPointLayer( QgsVectorLayer *layer, const QgsPointXY &center, int scaleFactor = 5 );
1574
1575 void setLayersPrivate( const QList<QgsMapLayer *> &layers );
1576
1577 void startPreviewJobs();
1578 void stopPreviewJobs();
1579 void schedulePreviewJob( int number );
1580
1584 bool panOperationInProgress();
1585
1586 int nextZoomLevel( const QList<double> &resolutions, bool zoomIn = true ) const;
1587
1592 void clearTemporalCache();
1593
1597 void clearElevationCache();
1598
1599 void showContextMenu( QgsMapMouseEvent *event );
1600
1605 void notifyRendererErrors( const QgsMapRendererJob::Errors &errors );
1606
1607 friend class TestQgsMapCanvas;
1608
1609}; // class QgsMapCanvas
1610
1611// clazy:excludeall=qstring-allocations
1612
1613#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
DistanceUnit
Units of distance.
Definition qgis.h:5269
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:3634
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.
void zoomToSelected(QgsMapLayer *layer=nullptr)
Zoom to the extent of the selected features of provided map layer.
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 setRenderFlag(bool flag)
Sets whether a user has disabled canvas renders via the GUI.
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.
void stopRendering()
stop rendering (if there is any right now)
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 layerStateChange()
This slot is connected to the visibility change of one or more layers.
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 saveAsImage(const QString &fileName, QPixmap *QPixmap=nullptr, const QString &="PNG")
Save the contents of the map canvas to disk as an image.
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 zoomOut()
Zoom out with fixed factor.
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 writeProject(QDomDocument &)
called to write map canvas settings to project
void mousePressEvent(QMouseEvent *e) override
void updateScale()
Emits signal scaleChanged to update scale in main window.
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Sets the factor of magnification to apply to the map canvas.
void refreshAllLayers()
Reload all layers (including refreshing layer properties from their data sources),...
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 redrawAllLayers()
Clears all cached images and redraws all layers.
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
void selectionChangedSlot()
Receives signal about selection change, and pass it on with layer info.
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.
void zoomIn()
Zoom in with fixed factor.
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
static const QgsSettingsEntryString * settingsCustomCoordinateCrs
void dropEvent(QDropEvent *event) override
QgsProject * project()
Returns the project linked to this canvas.
void setScaleLocked(bool isLocked)
Lock the scale, so zooming can be performed using magnication.
void setRotation(double degrees)
Set the rotation of the map canvas in clockwise degrees.
void readProject(const QDomDocument &)
called to read map canvas settings from project
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 refresh()
Repaints the canvas map.
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:73
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.
A string settings entry.
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