18 #ifndef QGSMAPCANVAS_H
19 #define QGSMAPCANVAS_H
21 #include "qgsconfig.h"
33 #include <QDomDocument>
34 #include <QGraphicsView>
40 #include <QGestureEvent>
66 class QgsMapCanvasMap;
90 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
91 sipType = sipType_QgsMapCanvas;
98 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
99 Q_PROPERTY(
bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
112 double magnificationFactor()
const;
125 void setLayers(
const QList<QgsMapLayer *> &layers );
161 void setMapSettingsFlags( QgsMapSettings::Flags flags );
173 void setCachingEnabled(
bool enabled );
179 bool isCachingEnabled()
const;
196 void waitWhileRendering();
202 void setParallelRenderingEnabled(
bool enabled );
208 bool isParallelRenderingEnabled()
const;
214 void setMapUpdateInterval(
int timeMilliseconds );
220 int mapUpdateInterval()
const;
226 double scale()
const;
229 double mapUnitsPerPixel()
const;
247 void setExtent(
const QgsRectangle &r,
bool magnified =
false );
263 double rotation()
const;
269 void setRotation(
double degrees );
284 void zoomToFullExtent();
287 void zoomToPreviousExtent();
290 void zoomToNextExtent();
293 void clearExtentHistory();
319 void panToSelected(
const QList<QgsMapLayer *> &layers );
334 const QColor &startColor = QColor( 255, 0, 0, 255 ),
const QColor &endColor = QColor( 255, 0, 0, 0 ),
335 int flashes = 3,
int duration = 500 );
350 const QColor &startColor = QColor( 255, 0, 0, 255 ),
const QColor &endColor = QColor( 255, 0, 0, 0 ),
351 int flashes = 3,
int duration = 500 );
354 void setMapTool(
QgsMapTool *mapTool,
bool clean =
false );
384 void setCanvasColor(
const QColor &_newVal );
386 QColor canvasColor()
const;
392 void setSelectionColor(
const QColor &color );
398 QColor selectionColor()
const;
407 int layerCount()
const;
413 QList<QgsMapLayer *> layers()
const;
424 void freeze(
bool frozen =
true );
433 bool isFrozen()
const;
456 QMap<QString, QString> layerStyleOverrides()
const;
469 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
489 void setTheme(
const QString &theme );
496 QString
theme()
const {
return mTheme; }
508 void setWheelFactor(
double factor );
517 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
526 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
529 void zoomWithCenter(
int x,
int y,
bool zoomIn );
545 void enableAntiAliasing(
bool flag );
551 void enableMapTileRendering(
bool flag );
556 void panActionEnd( QPoint releasePoint );
565 void panActionStart( QPoint releasePoint );
569 void panAction( QMouseEvent *event );
572 QPoint mouseLastXY();
580 void setPreviewModeEnabled(
bool previewEnabled );
589 bool previewModeEnabled()
const;
675 void setSegmentationTolerance(
double tolerance );
694 bool annotationsVisible()
const {
return mAnnotationsVisible; }
701 void setAnnotationsVisible(
bool visible );
723 bool previewJobsEnabled()
const;
733 void setPreviewJobsEnabled(
bool enabled );
740 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler >> &handlers )
SIP_SKIP;
752 void setTemporalRange(
const QgsDateTimeRange &range );
760 const QgsDateTimeRange &temporalRange()
const;
805 void refreshAllLayers();
815 void redrawAllLayers();
818 void selectionChangedSlot();
821 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
824 void layerStateChange();
833 void setRenderFlag(
bool flag );
839 void stopRendering();
842 void readProject(
const QDomDocument & );
845 void writeProject( QDomDocument & );
855 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
862 void setScaleLocked(
bool isLocked );
881 void zoomToSelected(
const QList<QgsMapLayer *> &layers );
893 double zoomInFactor()
const;
898 double zoomOutFactor()
const;
929 void mapToolDestroyed();
932 void rendererJobFinished();
935 void previewJobFinished();
937 void mapUpdateTimeout();
941 void mapThemeChanged(
const QString &theme );
943 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
1118 bool event( QEvent *e )
override;
1119 void keyPressEvent( QKeyEvent *e )
override;
1120 void keyReleaseEvent( QKeyEvent *e )
override;
1121 void mouseDoubleClickEvent( QMouseEvent *e )
override;
1122 void mouseMoveEvent( QMouseEvent *e )
override;
1123 void mousePressEvent( QMouseEvent *e )
override;
1124 void mouseReleaseEvent( QMouseEvent *e )
override;
1125 void wheelEvent( QWheelEvent *e )
override;
1126 void resizeEvent( QResizeEvent *e )
override;
1127 void paintEvent( QPaintEvent *e )
override;
1128 void dragEnterEvent( QDragEnterEvent *e )
override;
1131 void moveCanvasContents(
bool reset =
false );
1133 void dropEvent( QDropEvent *event )
override;
1148 void connectNotify(
const char *signal )
override;
1153 void updateCanvasItemPositions();
1157 void layerRepaintRequested(
bool deferred );
1159 void autoRefreshTriggered();
1161 void updateAutoRefreshTimer();
1163 void projectThemesChanged();
1165 void startPreviewJob(
int number );
1176 mLockedScale = mCanvas->mapSettings().scale();
1181 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1182 newExtent.
scale( mLockedScale / mCanvas->mapSettings().scale() );
1183 mCanvas->mSettings.setExtent( newExtent );
1188 double mLockedScale;
1195 QgsMapCanvasMap *mMap =
nullptr;
1204 bool mFrozen =
false;
1207 bool mRefreshScheduled =
false;
1210 bool mRefreshAfterJob =
false;
1213 bool mRenderFlag =
true;
1216 QPointer< QgsMapLayer > mCurrentLayer;
1219 QGraphicsScene *mScene =
nullptr;
1231 QList <QgsRectangle> mLastExtent;
1232 int mLastExtentIndex = -1;
1235 double mWheelZoomFactor = 2.0;
1238 QTimer mMapUpdateTimer;
1244 bool mJobCanceled =
false;
1250 bool mUseParallelRendering =
false;
1253 bool mDrawRenderingStats =
false;
1258 QTimer *mResizeTimer =
nullptr;
1259 QTimer *mRefreshTimer =
nullptr;
1267 QList< QgsMapRendererQImageJob * > mPreviewJobs;
1270 bool mScaleLocked =
false;
1278 bool mZoomDragging =
false;
1281 std::unique_ptr< QgsRubberBand > mZoomRubberBand;
1283 QCursor mZoomCursor;
1285 QTimer mAutoRefreshTimer;
1287 QTimer mPreviewTimer;
1288 QMetaObject::Connection mPreviewTimerConnection;
1294 bool mAnnotationsVisible =
true;
1296 bool mUsePreviewJobs =
false;
1298 QHash< QString, int > mLastLayerRenderTime;
1300 QVector<QPointer<QgsCustomDropHandler >> mDropHandlers;
1303 QList<double> mZoomResolutions;
1305 QList< QgsMapCanvasInteractionBlocker * > mInteractionBlockers;
1307 int mBlockItemPositionUpdates = 0;
1319 void updateMapSize();
1326 void beginZoomRect( QPoint pos );
1333 void endZoomRect( QPoint pos );
1353 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1355 void startPreviewJobs();
1356 void stopPreviewJobs();
1357 void schedulePreviewJob(
int number );
1362 bool panOperationInProgress();
1364 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1370 void clearTemporalCache();
1375 void clearElevationCache();
1379 friend class TestQgsMapCanvas;
MessageLevel
Level for messages This will be used both for message log and message bar in application.
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.
Single scope for storing variables and functions for use within a QgsExpressionContext.
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.
const QList< double > & zoomResolutions() const
void extentsChanged()
Emitted when the extents of the map change.
void messageEmitted(const QString &title, const QString &message, Qgis::MessageLevel=Qgis::Info)
emit a message (usually to be displayed in a message bar)
void xyCoordinates(const QgsPointXY &p)
Emits current mouse position.
void magnificationChanged(double)
Emitted when the scale of the map changes.
void setZoomResolutions(const QList< double > &resolutions)
Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map.
bool antiAliasingEnabled() const
true if antialiasing is enabled
QString theme() const
Returns the map's theme shown in the canvas, if set.
void renderComplete(QPainter *)
Emitted when the canvas has rendered.
void tapAndHoldGestureOccurred(const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
Emitted whenever a tap and hold gesture occurs at the specified map point.
void zoomNextStatusChanged(bool)
Emitted when zoom next status changed.
void rotationChanged(double)
Emitted when the rotation of the map changes.
void selectionChanged(QgsVectorLayer *layer)
Emitted when selection in any layer gets changed.
bool scaleLocked() const
Returns whether the scale is locked, so zooming can be performed using magnication.
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
void zRangeChanged()
Emitted when the map canvas z (elevation) range changes.
void mapToolSet(QgsMapTool *newTool, QgsMapTool *oldTool)
Emit map tool changed with the old tool.
void canvasColorChanged()
Emitted when canvas background color 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.
void layerStyleOverridesChanged()
Emitted when the configuration of overridden layer styles changes.
void scaleChanged(double)
Emitted when the scale 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 panDistanceBearingChanged(double distance, QgsUnitTypes::DistanceUnit unit, double bearing)
Emitted whenever the distance or bearing of an in-progress panning operation is changed.
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
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 zoomLastStatusChanged(bool)
Emitted when zoom last status changed.
const QgsExpressionContextScope & expressionContextScope() const
Returns a const reference to the expression context scope for the map canvas.
void layersChanged()
Emitted when a new set of layers has been received.
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.
Intermediate base class adding functionality that allows client to query the rendered image.
The QgsMapSettings class contains configuration for rendering of the map.
@ Antialiasing
Enable anti-aliasing for map rendering.
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.
A class for drawing transient features (e.g.
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 ...
DistanceUnit
Units of distance.
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
#define SIP_KEEPREFERENCE
QSet< QgsFeatureId > QgsFeatureIds
const QgsCoordinateReferenceSystem & crs