18 #ifndef QGSMAPCANVAS_H
19 #define QGSMAPCANVAS_H
21 #include "qgsconfig.h"
32 #include <QDomDocument>
33 #include <QGraphicsView>
39 #include <QGestureEvent>
64 class QgsMapCanvasMap;
88 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
89 sipType = sipType_QgsMapCanvas;
96 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
97 Q_PROPERTY(
bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
110 double magnificationFactor() const;
123 void setLayers( const QList<
QgsMapLayer *> &layers );
171 void setCachingEnabled(
bool enabled );
177 bool isCachingEnabled() const;
194 void waitWhileRendering();
200 void setParallelRenderingEnabled(
bool enabled );
206 bool isParallelRenderingEnabled() const;
212 void setMapUpdateInterval(
int timeMilliseconds );
218 int mapUpdateInterval() const;
224 double scale() const;
227 double mapUnitsPerPixel() const;
245 void setExtent( const
QgsRectangle &r,
bool magnified = false );
261 double rotation() const;
267 void setRotation(
double degrees );
282 void zoomToFullExtent();
285 void zoomToPreviousExtent();
288 void zoomToNextExtent();
291 void clearExtentHistory();
324 const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
325 int flashes = 3,
int duration = 500 );
340 const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
341 int flashes = 3,
int duration = 500 );
344 void setMapTool(
QgsMapTool *mapTool,
bool clean = false );
359 void setCanvasColor( const QColor &_newVal );
361 QColor canvasColor() const;
367 void setSelectionColor( const QColor &color );
373 QColor selectionColor() const;
382 int layerCount() const;
399 void freeze(
bool frozen = true );
408 bool isFrozen() const;
418 bool renderFlag()
const {
return mRenderFlag; }
431 QMap<QString, QString> layerStyleOverrides()
const;
444 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
464 void setTheme(
const QString &theme );
471 QString
theme()
const {
return mTheme; }
483 void setWheelFactor(
double factor );
492 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
501 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
504 void zoomWithCenter(
int x,
int y,
bool zoomIn );
520 void enableAntiAliasing(
bool flag );
526 void enableMapTileRendering(
bool flag );
531 void panActionEnd( QPoint releasePoint );
540 void panActionStart( QPoint releasePoint );
544 void panAction( QMouseEvent *event );
547 QPoint mouseLastXY();
554 void setPreviewModeEnabled(
bool previewEnabled );
562 bool previewModeEnabled()
const;
645 void setSegmentationTolerance(
double tolerance );
663 bool annotationsVisible()
const {
return mAnnotationsVisible; }
670 void setAnnotationsVisible(
bool visible );
692 bool previewJobsEnabled()
const;
702 void setPreviewJobsEnabled(
bool enabled );
709 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler >> &handlers )
SIP_SKIP;
721 void setTemporalRange(
const QgsDateTimeRange &range );
729 const QgsDateTimeRange &temporalRange()
const;
774 void refreshAllLayers();
784 void redrawAllLayers();
787 void selectionChangedSlot();
790 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
793 void layerStateChange();
802 void setRenderFlag(
bool flag );
808 void stopRendering();
811 void readProject(
const QDomDocument & );
814 void writeProject( QDomDocument & );
824 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
831 void setScaleLocked(
bool isLocked );
861 void mapToolDestroyed();
864 void rendererJobFinished();
867 void previewJobFinished();
869 void mapUpdateTimeout();
873 void mapThemeChanged(
const QString &theme );
875 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
885 void scaleChanged(
double );
888 void extentsChanged();
894 void rotationChanged(
double );
900 void magnificationChanged(
double );
906 void canvasColorChanged();
923 void renderComplete( QPainter * );
927 void mapCanvasRefreshed();
931 void renderStarting();
934 void layersChanged();
937 void keyPressed( QKeyEvent *e );
940 void keyReleased( QKeyEvent *e );
953 void zoomLastStatusChanged(
bool );
956 void zoomNextStatusChanged(
bool );
962 void destinationCrsChanged();
968 void transformContextChanged();
980 void layerStyleOverridesChanged();
987 void themeChanged(
const QString &theme );
999 void renderErrorOccurred(
const QString &error,
QgsMapLayer *layer );
1017 void tapAndHoldGestureOccurred(
const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
1024 void temporalRangeChanged();
1028 bool event( QEvent *e )
override;
1029 void keyPressEvent( QKeyEvent *e )
override;
1030 void keyReleaseEvent( QKeyEvent *e )
override;
1031 void mouseDoubleClickEvent( QMouseEvent *e )
override;
1032 void mouseMoveEvent( QMouseEvent *e )
override;
1033 void mousePressEvent( QMouseEvent *e )
override;
1034 void mouseReleaseEvent( QMouseEvent *e )
override;
1035 void wheelEvent( QWheelEvent *e )
override;
1036 void resizeEvent( QResizeEvent *e )
override;
1037 void paintEvent( QPaintEvent *e )
override;
1038 void dragEnterEvent( QDragEnterEvent *e )
override;
1041 void moveCanvasContents(
bool reset =
false );
1043 void dropEvent( QDropEvent *event )
override;
1058 void connectNotify(
const char *signal )
override;
1063 void updateCanvasItemPositions();
1067 void layerRepaintRequested(
bool deferred );
1069 void autoRefreshTriggered();
1071 void updateAutoRefreshTimer();
1073 void projectThemesChanged();
1075 void startPreviewJob(
int number );
1083 QgsMapCanvasMap *mMap =
nullptr;
1092 bool mFrozen =
false;
1095 bool mRefreshScheduled =
false;
1098 bool mRefreshAfterJob =
false;
1101 bool mRenderFlag =
true;
1104 QPointer< QgsMapLayer > mCurrentLayer;
1107 QGraphicsScene *mScene =
nullptr;
1116 QMenu *mMenu =
nullptr;
1119 QList <QgsRectangle> mLastExtent;
1120 int mLastExtentIndex = -1;
1123 double mWheelZoomFactor = 2.0;
1126 QTimer mMapUpdateTimer;
1132 bool mJobCanceled =
false;
1138 bool mUseParallelRendering =
false;
1141 bool mDrawRenderingStats =
false;
1146 QTimer *mResizeTimer =
nullptr;
1147 QTimer *mRefreshTimer =
nullptr;
1155 QList< QgsMapRendererQImageJob * > mPreviewJobs;
1158 bool mScaleLocked =
false;
1166 bool mZoomDragging =
false;
1169 std::unique_ptr< QgsRubberBand > mZoomRubberBand;
1171 QCursor mZoomCursor;
1173 QTimer mAutoRefreshTimer;
1175 QTimer mPreviewTimer;
1176 QMetaObject::Connection mPreviewTimerConnection;
1182 bool mAnnotationsVisible =
true;
1184 bool mUsePreviewJobs =
false;
1186 QHash< QString, int > mLastLayerRenderTime;
1188 QVector<QPointer<QgsCustomDropHandler >> mDropHandlers;
1191 QList<double> mZoomResolutions;
1193 QList< QgsMapCanvasInteractionBlocker * > mInteractionBlockers;
1205 void updateMapSize();
1212 void beginZoomRect( QPoint pos );
1219 void endZoomRect( QPoint pos );
1230 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1232 void startPreviewJobs();
1233 void stopPreviewJobs();
1234 void schedulePreviewJob(
int number );
1239 bool panOperationInProgress();
1241 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1242 double zoomInFactor()
const;
1243 double zoomOutFactor()
const;
1249 void clearTemporalCache();
1253 friend class TestQgsMapCanvas;