37#include <QDomDocument>
38#include <QGestureEvent>
39#include <QGraphicsView>
94 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
95 sipType = sipType_QgsMapCanvas;
290 double scale() const;
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 );
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 );
540 void freeze(
bool frozen =
true );
551 bool isFrozen()
const;
575 QMap<QString, QString> layerStyleOverrides()
const;
587 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
609 void setTheme(
const QString &theme );
615 QString
theme()
const {
return mTheme; }
627 void setWheelFactor(
double factor );
636 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
645 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
648 void zoomWithCenter(
int x,
int y,
bool zoomIn );
663 void enableAntiAliasing(
bool flag );
666 bool antiAliasingEnabled()
const;
669 void enableMapTileRendering(
bool flag );
674 void panActionEnd( QPoint releasePoint );
683 void panActionStart( QPoint releasePoint );
687 void panAction( QMouseEvent *event );
690 QPoint mouseLastXY();
697 void setPreviewModeEnabled(
bool previewEnabled );
705 bool previewModeEnabled()
const;
772 return mExpressionContextScope;
789 void setSegmentationTolerance(
double tolerance );
812 void setAnnotationsVisible(
bool visible );
831 bool previewJobsEnabled()
const;
840 void setPreviewJobsEnabled(
bool enabled );
847 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler>> &handlers )
SIP_SKIP;
920 void refreshAllLayers();
930 void redrawAllLayers();
933 void selectionChangedSlot();
936 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
939 void layerStateChange();
950 void setRenderFlag(
bool flag );
955 void stopRendering();
958 void readProject(
const QDomDocument & );
961 void writeProject( QDomDocument & );
970 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
976 void setScaleLocked(
bool isLocked );
988 void zoomToSelected(
QgsMapLayer *layer =
nullptr );
995 void zoomToSelected(
const QList<QgsMapLayer *> &layers );
1007 double zoomInFactor()
const;
1012 double zoomOutFactor()
const;
1044 void mapToolDestroyed();
1047 void rendererJobFinished();
1050 void previewJobFinished();
1052 void mapUpdateTimeout();
1056 void mapThemeChanged(
const QString &theme );
1058 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
1060 void updateDevicePixelFromScreen();
1062 void onElevationShadingRendererChanged();
1239 bool event( QEvent *e )
override;
1278 void connectNotify(
const char *signal )
override;
1287 void layerRepaintRequested(
bool deferred );
1289 void autoRefreshTriggered();
1291 void updateAutoRefreshTimer();
1293 void projectThemesChanged();
1295 void startPreviewJob(
int number );
1297 void temporalControllerModeChanged();
1307 mLockedScale = mCanvas->mapSettings().
scale();
1312 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1313 newExtent.
scale( mLockedScale / mCanvas->mapSettings().scale() );
1314 mCanvas->mSettings.setExtent( newExtent );
1318 QgsMapCanvas *mCanvas;
1319 double mLockedScale;
1322 enum class CacheInvalidationType
1328 QgsOverlayWidgetLayout *mLayout =
nullptr;
1333 QgsMapSettings mSettings;
1336 QgsMapCanvasMap *mMap =
nullptr;
1338 QgsScreenHelper *mScreenHelper =
nullptr;
1344 QgsTemporalController *mController =
nullptr;
1347 bool mFrozen =
false;
1350 bool mRefreshScheduled =
false;
1353 bool mRefreshAfterJob =
false;
1356 bool mRenderFlag =
true;
1358 QFlags<CacheInvalidationType> mCacheInvalidations;
1361 QPointer<QgsMapLayer> mCurrentLayer;
1364 QGraphicsScene *mScene =
nullptr;
1367 QgsMapTool *mMapTool =
nullptr;
1370 QgsProject *mProject =
nullptr;
1373 QList<QgsRectangle> mLastExtent;
1374 int mLastExtentIndex = -1;
1377 double mWheelZoomFactor = 2.0;
1380 QTimer mMapUpdateTimer;
1383 QgsMapRendererQImageJob *mJob =
nullptr;
1386 bool mJobCanceled =
false;
1389 std::unique_ptr<QgsLabelingResults> mLabelingResults;
1392 bool mLabelingResultsOutdated =
false;
1398 std::unique_ptr<QgsRenderedItemResults> mRenderedItemResults;
1404 std::unique_ptr<QgsRenderedItemResults> mPreviousRenderedItemResults;
1411 bool mRenderedItemResultsOutdated =
false;
1414 bool mUseParallelRendering =
false;
1417 bool mDrawRenderingStats =
false;
1420 QgsMapRendererCache *mCache =
nullptr;
1422 QTimer *mResizeTimer =
nullptr;
1423 QTimer *mRefreshTimer =
nullptr;
1425 QgsPreviewEffect *mPreviewEffect =
nullptr;
1427 QgsRectangle imageRect(
const QImage &img,
const QgsMapSettings &mapSettings );
1429 QgsSnappingUtils *mSnappingUtils =
nullptr;
1431 QList<QgsMapRendererQImageJob *> mPreviewJobs;
1434 bool mScaleLocked =
false;
1436 QgsExpressionContextScope mExpressionContextScope;
1442 bool mZoomDragging =
false;
1445 std::unique_ptr<QgsRubberBand> mZoomRubberBand;
1447 QCursor mZoomCursor;
1449 QTimer mAutoRefreshTimer;
1451 QTimer mPreviewTimer;
1452 QMetaObject::Connection mPreviewTimerConnection;
1456 QgsPointXY mCursorPoint;
1458 bool mAnnotationsVisible =
true;
1460 bool mUsePreviewJobs =
false;
1462 QHash<QString, int> mLastLayerRenderTime;
1464 QVector<QPointer<QgsCustomDropHandler>> mDropHandlers;
1466 QgsDistanceArea mDa;
1467 QList<double> mZoomResolutions;
1469 QList<QgsMapCanvasInteractionBlocker *> mInteractionBlockers;
1471 int mBlockItemPositionUpdates = 0;
1472 int mBlockExtentChangedSignal = 0;
1473 int mBlockScaleChangedSignal = 0;
1475 std::unique_ptr<QgsTemporaryCursorOverride> mTemporaryCursorOverride;
1484 QMap<QString, QDateTime> mRendererErrors;
1487 QPointer<QgsAbstract2DMapController> mMapController;
1493 QgsPointXY cursorPoint()
const;
1498 void updateMapSize();
1504 void beginZoomRect( QPoint pos );
1510 void endZoomRect( QPoint pos );
1513 void stopZoomRect();
1529 bool boundingBoxOfFeatureIds(
const QgsFeatureIds &ids, QgsVectorLayer *layer, QgsRectangle &bbox, QString &errorMsg )
const;
1537 QgsRectangle optimalExtentForPointLayer( QgsVectorLayer *layer,
const QgsPointXY ¢er,
int scaleFactor = 5 );
1539 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1541 void startPreviewJobs();
1542 void stopPreviewJobs();
1543 void schedulePreviewJob(
int number );
1548 bool panOperationInProgress();
1550 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1556 void clearTemporalCache();
1561 void clearElevationCache();
1563 void showContextMenu( QgsMapMouseEvent *event );
Provides global constants and enumerations 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.
Represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
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.
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.
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 ¢er)
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.
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.
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.
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)
#define SIP_KEEPREFERENCE
#define SIP_THROW(name,...)
QSet< QgsFeatureId > QgsFeatureIds
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.