QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
18 #ifndef QGSMAPCANVAS_H
19 #define QGSMAPCANVAS_H
21 #include "qgsconfig.h"
33 #include <QDomDocument>
34 #include <QGraphicsView>
40 #include <QGestureEvent>
65 class QgsMapCanvasMap;
89 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
90 sipType = sipType_QgsMapCanvas;
97 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
98 Q_PROPERTY(
bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
111 double magnificationFactor()
const;
124 void setLayers(
const QList<QgsMapLayer *> &layers );
160 void setMapSettingsFlags( QgsMapSettings::Flags flags );
172 void setCachingEnabled(
bool enabled );
178 bool isCachingEnabled()
const;
195 void waitWhileRendering();
201 void setParallelRenderingEnabled(
bool enabled );
207 bool isParallelRenderingEnabled()
const;
213 void setMapUpdateInterval(
int timeMilliseconds );
219 int mapUpdateInterval()
const;
225 double scale()
const;
228 double mapUnitsPerPixel()
const;
246 void setExtent(
const QgsRectangle &r,
bool magnified =
false );
262 double rotation()
const;
268 void setRotation(
double degrees );
283 void zoomToFullExtent();
286 void zoomToPreviousExtent();
289 void zoomToNextExtent();
292 void clearExtentHistory();
326 const QColor &startColor = QColor( 255, 0, 0, 255 ),
const QColor &endColor = QColor( 255, 0, 0, 0 ),
327 int flashes = 3,
int duration = 500 );
342 const QColor &startColor = QColor( 255, 0, 0, 255 ),
const QColor &endColor = QColor( 255, 0, 0, 0 ),
343 int flashes = 3,
int duration = 500 );
346 void setMapTool(
QgsMapTool *mapTool,
bool clean =
false );
376 void setCanvasColor(
const QColor &_newVal );
378 QColor canvasColor()
const;
384 void setSelectionColor(
const QColor &color );
390 QColor selectionColor()
const;
399 int layerCount()
const;
405 QList<QgsMapLayer *> layers()
const;
416 void freeze(
bool frozen =
true );
425 bool isFrozen()
const;
448 QMap<QString, QString> layerStyleOverrides()
const;
461 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
481 void setTheme(
const QString &theme );
488 QString
theme()
const {
return mTheme; }
500 void setWheelFactor(
double factor );
509 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
518 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
521 void zoomWithCenter(
int x,
int y,
bool zoomIn );
537 void enableAntiAliasing(
bool flag );
543 void enableMapTileRendering(
bool flag );
548 void panActionEnd( QPoint releasePoint );
557 void panActionStart( QPoint releasePoint );
561 void panAction( QMouseEvent *event );
564 QPoint mouseLastXY();
572 void setPreviewModeEnabled(
bool previewEnabled );
581 bool previewModeEnabled()
const;
667 void setSegmentationTolerance(
double tolerance );
686 bool annotationsVisible()
const {
return mAnnotationsVisible; }
693 void setAnnotationsVisible(
bool visible );
715 bool previewJobsEnabled()
const;
725 void setPreviewJobsEnabled(
bool enabled );
732 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler >> &handlers )
SIP_SKIP;
744 void setTemporalRange(
const QgsDateTimeRange &range );
752 const QgsDateTimeRange &temporalRange()
const;
797 void refreshAllLayers();
807 void redrawAllLayers();
810 void selectionChangedSlot();
813 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
816 void layerStateChange();
825 void setRenderFlag(
bool flag );
831 void stopRendering();
834 void readProject(
const QDomDocument & );
837 void writeProject( QDomDocument & );
847 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
854 void setScaleLocked(
bool isLocked );
884 void mapToolDestroyed();
887 void rendererJobFinished();
890 void previewJobFinished();
892 void mapUpdateTimeout();
896 void mapThemeChanged(
const QString &theme );
898 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
1059 bool event( QEvent *e )
override;
1060 void keyPressEvent( QKeyEvent *e )
override;
1061 void keyReleaseEvent( QKeyEvent *e )
override;
1062 void mouseDoubleClickEvent( QMouseEvent *e )
override;
1063 void mouseMoveEvent( QMouseEvent *e )
override;
1064 void mousePressEvent( QMouseEvent *e )
override;
1065 void mouseReleaseEvent( QMouseEvent *e )
override;
1066 void wheelEvent( QWheelEvent *e )
override;
1067 void resizeEvent( QResizeEvent *e )
override;
1068 void paintEvent( QPaintEvent *e )
override;
1069 void dragEnterEvent( QDragEnterEvent *e )
override;
1072 void moveCanvasContents(
bool reset =
false );
1074 void dropEvent( QDropEvent *event )
override;
1089 void connectNotify(
const char *signal )
override;
1094 void updateCanvasItemPositions();
1098 void layerRepaintRequested(
bool deferred );
1100 void autoRefreshTriggered();
1102 void updateAutoRefreshTimer();
1104 void projectThemesChanged();
1106 void startPreviewJob(
int number );
1117 mLockedScale = mCanvas->mapSettings().scale();
1122 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1123 newExtent.
scale( mLockedScale / mCanvas->mapSettings().scale() );
1124 mCanvas->mSettings.setExtent( newExtent );
1129 double mLockedScale;
1136 QgsMapCanvasMap *mMap =
nullptr;
1145 bool mFrozen =
false;
1148 bool mRefreshScheduled =
false;
1151 bool mRefreshAfterJob =
false;
1154 bool mRenderFlag =
true;
1157 QPointer< QgsMapLayer > mCurrentLayer;
1160 QGraphicsScene *mScene =
nullptr;
1172 QMenu *mMenu =
nullptr;
1175 QList <QgsRectangle> mLastExtent;
1176 int mLastExtentIndex = -1;
1179 double mWheelZoomFactor = 2.0;
1182 QTimer mMapUpdateTimer;
1188 bool mJobCanceled =
false;
1194 bool mUseParallelRendering =
false;
1197 bool mDrawRenderingStats =
false;
1202 QTimer *mResizeTimer =
nullptr;
1203 QTimer *mRefreshTimer =
nullptr;
1211 QList< QgsMapRendererQImageJob * > mPreviewJobs;
1214 bool mScaleLocked =
false;
1222 bool mZoomDragging =
false;
1225 std::unique_ptr< QgsRubberBand > mZoomRubberBand;
1227 QCursor mZoomCursor;
1229 QTimer mAutoRefreshTimer;
1231 QTimer mPreviewTimer;
1232 QMetaObject::Connection mPreviewTimerConnection;
1238 bool mAnnotationsVisible =
true;
1240 bool mUsePreviewJobs =
false;
1242 QHash< QString, int > mLastLayerRenderTime;
1244 QVector<QPointer<QgsCustomDropHandler >> mDropHandlers;
1247 QList<double> mZoomResolutions;
1249 QList< QgsMapCanvasInteractionBlocker * > mInteractionBlockers;
1261 void updateMapSize();
1268 void beginZoomRect( QPoint pos );
1275 void endZoomRect( QPoint pos );
1295 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1297 void startPreviewJobs();
1298 void stopPreviewJobs();
1299 void schedulePreviewJob(
int number );
1304 bool panOperationInProgress();
1306 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1307 double zoomInFactor()
const;
1308 double zoomOutFactor()
const;
1314 void clearTemporalCache();
1318 friend class TestQgsMapCanvas;
void renderStarting()
Emitted when the canvas is about to be rendered.
void renderErrorOccurred(const QString &error, QgsMapLayer *layer)
Emitted whenever an error is encountered during a map render operation.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
An interface for objects which block interactions with a QgsMapCanvas.
An interactive map canvas item which displays a QgsAnnotation.
void transformContextChanged()
Emitted when the canvas transform context is changed.
void mapToolSet(QgsMapTool *newTool, QgsMapTool *oldTool)
Emit map tool changed with the old tool.
void destinationCrsChanged()
Emitted when map CRS has changed.
void xyCoordinates(const QgsPointXY &p)
Emits current mouse position.
void zoomLastStatusChanged(bool)
Emitted when zoom last status changed.
A QgsRectangle with associated coordinate reference system.
A class for drawing transient features (e.g.
bool antiAliasingEnabled() const
true if antialiasing is enabled
const QgsCoordinateReferenceSystem & crs
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
Map canvas is a class for displaying all GIS data types on a canvas.
QString theme() const
Returns the map's theme shown in the canvas, if set.
Class that stores computed placement from labeling engine.
void rotationChanged(double)
Emitted when the rotation of the map changes.
DistanceUnit
Units of distance.
A rectangle specified with double values.
This class is responsible for keeping cache of rendered images resulting from a map rendering job.
#define SIP_KEEPREFERENCE
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A class for highlight features on the map.
void scaleChanged(double)
Emitted when the scale of the map changes.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Custom exception class for Coordinate Reference System related exceptions.
Stores global configuration for labeling engine.
Interaction
Available interactions to block.
void layersChanged()
Emitted when a new set of layers has been received.
void extentsChanged()
Emitted when the extents of the map change.
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
@ Antialiasing
Enable anti-aliasing for map rendering.
A controller base class for temporal objects, contains a signal for notifying updates of the objects ...
std::unique_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
A widget that displays an overview map.
void layerStyleOverridesChanged()
Emitted when the configuration of overridden layer styles changes.
const QList< double > & zoomResolutions() const
QSet< QgsFeatureId > QgsFeatureIds
This class represents a coordinate reference system (CRS).
This class has all the configuration of snapping and can return answers to snapping queries.
Abstract base class for all geometries.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A class to represent a 2D point.
void keyReleased(QKeyEvent *e)
Emit key release event.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Intermediate base class adding functionality that allows client to query the rendered image.
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 canvasColorChanged()
Emitted when canvas background color changes.
void tapAndHoldGestureOccurred(const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
Emitted whenever a tap and hold gesture occurs at the specified map point.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
void themeChanged(const QString &theme)
Emitted when the canvas has been assigned a different map theme.
Perform transforms between map coordinates and device coordinates.
Represents a vector layer which manages a vector based data sets.
void selectionChanged(QgsVectorLayer *layer)
Emitted when selection in any layer gets changed.
Base class for all map layer types.
void magnificationChanged(double)
Emitted when the scale of the map changes.
void setExpressionContextScope(const QgsExpressionContextScope &scope)
Sets an expression context scope for the map canvas.
void panDistanceBearingChanged(double distance, QgsUnitTypes::DistanceUnit unit, double bearing)
Emitted whenever the distance or bearing of an in-progress panning operation is changed.
void keyPressed(QKeyEvent *e)
Emit key press event.
void renderComplete(QPainter *)
Emitted when the canvas has rendered.
Deprecated to be deleted, stuff from here should be moved elsewhere.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void messageEmitted(const QString &title, const QString &message, Qgis::MessageLevel=Qgis::Info)
emit a message (usually to be displayed in a message bar)
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
void contextMenuAboutToShow(QMenu *menu, QgsMapMouseEvent *event)
Emitted before the map canvas context menu will be shown.
void zoomNextStatusChanged(bool)
Emitted when zoom next status changed.
bool scaleLocked() const
Returns whether the scale is locked, so zooming can be performed using magnication.
bool renderFlag() const
Returns true if canvas render is disabled as a result of user disabling renders via the GUI.
The QgsMapSettings class contains configuration for rendering of the map.
const QgsExpressionContextScope & expressionContextScope() const
Returns a const reference to the expression context scope for the map canvas.
void mapCanvasRefreshed()
Emitted when canvas finished a refresh request.