34#include <QDomDocument>
35#include <QGraphicsView>
41#include <QGestureEvent>
96 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
97 sipType = sipType_QgsMapCanvas;
104 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
105 Q_PROPERTY(
bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
123 void addOverlayWidget( QWidget *widget
SIP_TRANSFER, Qt::Edge edge );
128 double magnificationFactor() const;
140 void setLayers( const QList<
QgsMapLayer *> &layers );
148 void setFlags(
Qgis::MapCanvasFlags flags );
156 Qgis::MapCanvasFlags flags() const;
197 void setMapSettingsFlags(
Qgis::MapSettingsFlags flags );
226 void setCachingEnabled(
bool enabled );
235 bool isCachingEnabled() const;
266 void waitWhileRendering();
271 void setParallelRenderingEnabled(
bool enabled );
276 bool isParallelRenderingEnabled() const;
281 void setMapUpdateInterval(
int timeMilliseconds );
286 int mapUpdateInterval() const;
292 double scale() const;
295 double mapUnitsPerPixel() const;
332 void setExtent( const
QgsRectangle &r,
bool magnified = false );
347 double rotation() const;
352 void setRotation(
double degrees );
369 void zoomToFullExtent();
379 void zoomToProjectExtent();
382 void zoomToPreviousExtent();
385 void zoomToNextExtent();
388 void clearExtentHistory();
407 void panToSelected(
QgsMapLayer *layer =
nullptr );
414 void panToSelected( const QList<
QgsMapLayer *> &layers );
427 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 );
440 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 );
443 void setMapTool(
QgsMapTool *mapTool,
bool clean = false );
473 void setCanvasColor( const QColor &_newVal );
475 QColor canvasColor() const;
480 void setSelectionColor( const QColor &color );
485 QColor selectionColor() const;
508 int layerCount() const;
518 QList<
QgsMapLayer *> layers(
bool expandGroupLayers = false ) const;
528 QVector<T>
layers()
const {
return mapSettings().layers<T>(); }
542 void freeze(
bool frozen =
true );
553 bool isFrozen()
const;
577 QMap<QString, QString> layerStyleOverrides()
const;
589 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
608 void setTheme(
const QString &theme );
614 QString
theme()
const {
return mTheme; }
626 void setWheelFactor(
double factor );
635 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
644 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
647 void zoomWithCenter(
int x,
int y,
bool zoomIn );
662 void enableAntiAliasing(
bool flag );
665 bool antiAliasingEnabled()
const;
668 void enableMapTileRendering(
bool flag );
673 void panActionEnd( QPoint releasePoint );
682 void panActionStart( QPoint releasePoint );
686 void panAction( QMouseEvent *event );
689 QPoint mouseLastXY();
696 void setPreviewModeEnabled(
bool previewEnabled );
704 bool previewModeEnabled()
const;
771 return mExpressionContextScope;
788 void setSegmentationTolerance(
double tolerance );
805 bool annotationsVisible()
const {
return mAnnotationsVisible; }
811 void setAnnotationsVisible(
bool visible );
830 bool previewJobsEnabled()
const;
839 void setPreviewJobsEnabled(
bool enabled );
846 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler>> &handlers )
SIP_SKIP;
919 void refreshAllLayers();
929 void redrawAllLayers();
932 void selectionChangedSlot();
935 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
938 void layerStateChange();
949 void setRenderFlag(
bool flag );
954 void stopRendering();
957 void readProject(
const QDomDocument & );
960 void writeProject( QDomDocument & );
969 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
975 void setScaleLocked(
bool isLocked );
987 void zoomToSelected(
QgsMapLayer *layer =
nullptr );
994 void zoomToSelected(
const QList<QgsMapLayer *> &layers );
1006 double zoomInFactor()
const;
1011 double zoomOutFactor()
const;
1042 void mapToolDestroyed();
1045 void rendererJobFinished();
1048 void previewJobFinished();
1050 void mapUpdateTimeout();
1054 void mapThemeChanged(
const QString &theme );
1056 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
1058 void updateDevicePixelFromScreen();
1060 void onElevationShadingRendererChanged();
1237 bool event( QEvent *e )
override;
1238 void keyPressEvent( QKeyEvent *e )
override;
1239 void keyReleaseEvent( QKeyEvent *e )
override;
1240 void mouseDoubleClickEvent( QMouseEvent *e )
override;
1241 void mouseMoveEvent( QMouseEvent *e )
override;
1242 void mousePressEvent( QMouseEvent *e )
override;
1243 void mouseReleaseEvent( QMouseEvent *e )
override;
1244 void wheelEvent( QWheelEvent *e )
override;
1245 void resizeEvent( QResizeEvent *e )
override;
1246 void paintEvent( QPaintEvent *e )
override;
1247 void dragEnterEvent( QDragEnterEvent *e )
override;
1248 bool viewportEvent( QEvent *event )
override;
1251 void moveCanvasContents(
bool reset =
false );
1253 void dropEvent( QDropEvent *event )
override;
1255 void showEvent( QShowEvent *event )
override;
1262 void emitExtentsChanged();
1276 void connectNotify(
const char *signal )
override;
1281 void updateCanvasItemPositions();
1285 void layerRepaintRequested(
bool deferred );
1287 void autoRefreshTriggered();
1289 void updateAutoRefreshTimer();
1291 void projectThemesChanged();
1293 void startPreviewJob(
int number );
1295 void temporalControllerModeChanged();
1305 mLockedScale = mCanvas->mapSettings().scale();
1310 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1311 newExtent.
scale( mLockedScale / mCanvas->mapSettings().scale() );
1312 mCanvas->mSettings.setExtent( newExtent );
1317 double mLockedScale;
1320 enum class CacheInvalidationType
1334 QgsMapCanvasMap *mMap =
nullptr;
1345 bool mFrozen =
false;
1348 bool mRefreshScheduled =
false;
1351 bool mRefreshAfterJob =
false;
1354 bool mRenderFlag =
true;
1356 QFlags<CacheInvalidationType> mCacheInvalidations;
1359 QPointer<QgsMapLayer> mCurrentLayer;
1362 QGraphicsScene *mScene =
nullptr;
1371 QList<QgsRectangle> mLastExtent;
1372 int mLastExtentIndex = -1;
1375 double mWheelZoomFactor = 2.0;
1378 QTimer mMapUpdateTimer;
1384 bool mJobCanceled =
false;
1387 std::unique_ptr<QgsLabelingResults> mLabelingResults;
1390 bool mLabelingResultsOutdated =
false;
1396 std::unique_ptr<QgsRenderedItemResults> mRenderedItemResults;
1402 std::unique_ptr<QgsRenderedItemResults> mPreviousRenderedItemResults;
1409 bool mRenderedItemResultsOutdated =
false;
1412 bool mUseParallelRendering =
false;
1415 bool mDrawRenderingStats =
false;
1420 QTimer *mResizeTimer =
nullptr;
1421 QTimer *mRefreshTimer =
nullptr;
1429 QList<QgsMapRendererQImageJob *> mPreviewJobs;
1432 bool mScaleLocked =
false;
1440 bool mZoomDragging =
false;
1443 std::unique_ptr<QgsRubberBand> mZoomRubberBand;
1445 QCursor mZoomCursor;
1447 QTimer mAutoRefreshTimer;
1449 QTimer mPreviewTimer;
1450 QMetaObject::Connection mPreviewTimerConnection;
1456 bool mAnnotationsVisible =
true;
1458 bool mUsePreviewJobs =
false;
1460 QHash<QString, int> mLastLayerRenderTime;
1462 QVector<QPointer<QgsCustomDropHandler>> mDropHandlers;
1465 QList<double> mZoomResolutions;
1467 QList<QgsMapCanvasInteractionBlocker *> mInteractionBlockers;
1469 int mBlockItemPositionUpdates = 0;
1470 int mBlockExtentChangedSignal = 0;
1471 int mBlockScaleChangedSignal = 0;
1473 std::unique_ptr<QgsTemporaryCursorOverride> mTemporaryCursorOverride;
1482 QMap<QString, QDateTime> mRendererErrors;
1485 QPointer<QgsAbstract2DMapController> mMapController;
1496 void updateMapSize();
1502 void beginZoomRect( QPoint pos );
1508 void endZoomRect( QPoint pos );
1511 void stopZoomRect();
1537 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1539 void startPreviewJobs();
1540 void stopPreviewJobs();
1541 void schedulePreviewJob(
int number );
1546 bool panOperationInProgress();
1548 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1554 void clearTemporalCache();
1559 void clearElevationCache();
1569 friend class TestQgsMapCanvas;
The Qgis class provides global constants for use throughout the application.
DistanceUnit
Units of distance.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Info
Information message.
QFlags< MapCanvasFlag > MapCanvasFlags
Flags controlling behavior of map canvases.
Abstract base class for all 2D map controllers.
Abstract base class for all geometries.
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
QgsRange which stores a range of double values.
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.
A class for highlight features on the map.
Stores global configuration for labeling engine.
Class that 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.
Map canvas is a class for displaying all GIS data types on a canvas.
void contextMenuAboutToShow(QMenu *menu, QgsMapMouseEvent *event)
Emitted before the map canvas context menu will be shown.
void selectionChanged(QgsMapLayer *layer)
Emitted when selection in any layer gets changed.
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 setZoomResolutions(const QList< double > &resolutions)
Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map.
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 tapAndHoldGestureOccurred(const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
Emitted whenever a tap and hold gesture occurs at the specified map point.
const QList< double > & zoomResolutions() const
void panDistanceBearingChanged(double distance, Qgis::DistanceUnit unit, double bearing)
Emitted whenever the distance or bearing of an in-progress panning operation is changed.
bool scaleLocked() const
Returns whether the scale is locked, so zooming can be performed using magnication.
void zRangeChanged()
Emitted when the map canvas z (elevation) range changes.
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 magnificationChanged(double magnification)
Emitted when the scale of the map changes.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
void renderErrorOccurred(const QString &error, QgsMapLayer *layer)
Emitted whenever an error is encountered during a map render operation.
void mapRefreshCanceled()
Emitted when the pending map refresh has been canceled.
void renderStarting()
Emitted when the canvas is about to be rendered.
std::unique_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
void keyReleased(QKeyEvent *e)
Emit key release event.
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.
void zoomNextStatusChanged(bool available)
Emitted when zoom next status changed.
void rotationChanged(double rotation)
Emitted when the rotation of the map changes.
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.
bool renderFlag() const
Returns true if canvas render is disabled as a result of user disabling renders via the GUI.
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
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 mapCanvasRefreshed()
Emitted when canvas finished a refresh request.
void layersChanged()
Emitted when a new set of layers has been received.
void renderComplete(QPainter *painter)
Emitted when the canvas has rendered.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope for the map canvas.
Base class for all map layer types.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
A widget that displays an overview map.
This class is responsible for keeping cache of rendered images resulting from a map rendering job.
QList< QgsMapRendererJob::Error > Errors
Intermediate base class adding functionality that allows client to query the rendered image.
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
A class to represent a 2D point.
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
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.
A class for drawing transient features (e.g.
A utility class for dynamic handling of changes to screen properties.
This class has all the 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 data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
#define SIP_KEEPREFERENCE
#define SIP_THROW(name,...)
QSet< QgsFeatureId > QgsFeatureIds
const QgsCoordinateReferenceSystem & crs