18 #ifndef QGSMAPCANVAS_H
19 #define QGSMAPCANVAS_H
21 #include "qgsconfig.h"
35 #include <QDomDocument>
36 #include <QGraphicsView>
42 #include <QGestureEvent>
68 class QgsMapCanvasMap;
94 if ( qobject_cast<QgsMapCanvas *>( sipCpp ) !=
nullptr )
95 sipType = sipType_QgsMapCanvas;
102 Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
103 Q_PROPERTY(
bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
116 double magnificationFactor() const;
129 void setLayers( const QList<
QgsMapLayer *> &layers );
165 void setMapSettingsFlags(
Qgis::MapSettingsFlags flags );
192 void setCachingEnabled(
bool enabled );
198 bool isCachingEnabled() const;
221 void waitWhileRendering();
227 void setParallelRenderingEnabled(
bool enabled );
233 bool isParallelRenderingEnabled() const;
239 void setMapUpdateInterval(
int timeMilliseconds );
245 int mapUpdateInterval() const;
251 double scale() const;
254 double mapUnitsPerPixel() const;
291 void setExtent( const
QgsRectangle &r,
bool magnified = false );
307 double rotation() const;
313 void setRotation(
double degrees );
332 void zoomToFullExtent();
342 void zoomToProjectExtent();
345 void zoomToPreviousExtent();
348 void zoomToNextExtent();
351 void clearExtentHistory();
377 void panToSelected( const QList<
QgsMapLayer *> &layers );
392 const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
393 int flashes = 3,
int duration = 500 );
408 const QColor &startColor = QColor( 255, 0, 0, 255 ), const QColor &endColor = QColor( 255, 0, 0, 0 ),
409 int flashes = 3,
int duration = 500 );
412 void setMapTool(
QgsMapTool *mapTool,
bool clean = false );
442 void setCanvasColor( const QColor &_newVal );
444 QColor canvasColor() const;
450 void setSelectionColor( const QColor &color );
456 QColor selectionColor() const;
479 int layerCount() const;
489 QList<
QgsMapLayer *> layers(
bool expandGroupLayers = false ) const;
500 void freeze(
bool frozen = true );
509 bool isFrozen() const;
519 bool renderFlag()
const {
return mRenderFlag; }
532 QMap<QString, QString> layerStyleOverrides()
const;
545 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
565 void setTheme(
const QString &theme );
572 QString
theme()
const {
return mTheme; }
584 void setWheelFactor(
double factor );
593 void zoomScale(
double scale,
bool ignoreScaleLock =
false );
602 void zoomByFactor(
double scaleFactor,
const QgsPointXY *center =
nullptr,
bool ignoreScaleLock =
false );
605 void zoomWithCenter(
int x,
int y,
bool zoomIn );
621 void enableAntiAliasing(
bool flag );
624 bool antiAliasingEnabled()
const;
627 void enableMapTileRendering(
bool flag );
632 void panActionEnd( QPoint releasePoint );
641 void panActionStart( QPoint releasePoint );
645 void panAction( QMouseEvent *event );
648 QPoint mouseLastXY();
656 void setPreviewModeEnabled(
bool previewEnabled );
665 bool previewModeEnabled()
const;
753 void setSegmentationTolerance(
double tolerance );
772 bool annotationsVisible()
const {
return mAnnotationsVisible; }
779 void setAnnotationsVisible(
bool visible );
801 bool previewJobsEnabled()
const;
811 void setPreviewJobsEnabled(
bool enabled );
818 void setCustomDropHandlers(
const QVector<QPointer<QgsCustomDropHandler >> &handlers )
SIP_SKIP;
830 void setTemporalRange(
const QgsDateTimeRange &range );
838 const QgsDateTimeRange &temporalRange()
const;
883 void refreshAllLayers();
893 void redrawAllLayers();
896 void selectionChangedSlot();
899 void saveAsImage(
const QString &fileName, QPixmap *QPixmap =
nullptr,
const QString & =
"PNG" );
902 void layerStateChange();
911 void setRenderFlag(
bool flag );
917 void stopRendering();
920 void readProject(
const QDomDocument & );
923 void writeProject( QDomDocument & );
933 void setMagnificationFactor(
double factor,
const QgsPointXY *center =
nullptr );
940 void setScaleLocked(
bool isLocked );
959 void zoomToSelected(
const QList<QgsMapLayer *> &layers );
971 double zoomInFactor()
const;
976 double zoomOutFactor()
const;
1007 void mapToolDestroyed();
1010 void rendererJobFinished();
1013 void previewJobFinished();
1015 void mapUpdateTimeout();
1019 void mapThemeChanged(
const QString &theme );
1021 void mapThemeRenamed(
const QString &theme,
const QString &newTheme );
1023 void updateDevicePixelFromScreen();
1034 void scaleChanged(
double );
1042 void scaleLockChanged(
bool locked );
1046 void extentsChanged();
1052 void rotationChanged(
double );
1058 void magnificationChanged(
double );
1064 void canvasColorChanged();
1078 void renderComplete( QPainter * );
1082 void mapCanvasRefreshed();
1086 void renderStarting();
1092 void mapRefreshCanceled();
1095 void layersChanged();
1098 void keyPressed( QKeyEvent *e );
1101 void keyReleased( QKeyEvent *e );
1114 void zoomLastStatusChanged(
bool );
1117 void zoomNextStatusChanged(
bool );
1123 void destinationCrsChanged();
1129 void transformContextChanged();
1141 void layerStyleOverridesChanged();
1148 void themeChanged(
const QString &theme );
1151 void messageEmitted(
const QString &title,
const QString &message,
Qgis::MessageLevel = Qgis::MessageLevel::Info );
1160 void renderErrorOccurred(
const QString &error,
QgsMapLayer *layer );
1178 void tapAndHoldGestureOccurred(
const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
1185 void temporalRangeChanged();
1195 void zRangeChanged();
1207 bool event( QEvent *e )
override;
1208 void keyPressEvent( QKeyEvent *e )
override;
1209 void keyReleaseEvent( QKeyEvent *e )
override;
1210 void mouseDoubleClickEvent( QMouseEvent *e )
override;
1211 void mouseMoveEvent( QMouseEvent *e )
override;
1212 void mousePressEvent( QMouseEvent *e )
override;
1213 void mouseReleaseEvent( QMouseEvent *e )
override;
1214 void wheelEvent( QWheelEvent *e )
override;
1215 void resizeEvent( QResizeEvent *e )
override;
1216 void paintEvent( QPaintEvent *e )
override;
1217 void dragEnterEvent( QDragEnterEvent *e )
override;
1218 bool viewportEvent( QEvent *event )
override;
1221 void moveCanvasContents(
bool reset =
false );
1223 void dropEvent( QDropEvent *event )
override;
1225 void showEvent( QShowEvent *event )
override;
1239 void connectNotify(
const char *signal )
override;
1244 void updateCanvasItemPositions();
1248 void layerRepaintRequested(
bool deferred );
1250 void autoRefreshTriggered();
1252 void updateAutoRefreshTimer();
1254 void projectThemesChanged();
1256 void startPreviewJob(
int number );
1258 void temporalControllerModeChanged();
1269 mLockedScale = mCanvas->mapSettings().scale();
1274 QgsRectangle newExtent = mCanvas->mapSettings().extent();
1275 newExtent.
scale( mLockedScale / mCanvas->mapSettings().scale() );
1276 mCanvas->mSettings.setExtent( newExtent );
1281 double mLockedScale;
1288 QgsMapCanvasMap *mMap =
nullptr;
1297 bool mFrozen =
false;
1300 bool mRefreshScheduled =
false;
1303 bool mRefreshAfterJob =
false;
1306 bool mRenderFlag =
true;
1309 QPointer< QgsMapLayer > mCurrentLayer;
1312 QGraphicsScene *mScene =
nullptr;
1324 QList <QgsRectangle> mLastExtent;
1325 int mLastExtentIndex = -1;
1328 double mWheelZoomFactor = 2.0;
1331 QTimer mMapUpdateTimer;
1337 bool mJobCanceled =
false;
1340 std::unique_ptr< QgsLabelingResults > mLabelingResults;
1343 bool mLabelingResultsOutdated =
false;
1349 std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults;
1355 std::unique_ptr< QgsRenderedItemResults > mPreviousRenderedItemResults;
1362 bool mRenderedItemResultsOutdated =
false;
1365 bool mUseParallelRendering =
false;
1368 bool mDrawRenderingStats =
false;
1373 QTimer *mResizeTimer =
nullptr;
1374 QTimer *mRefreshTimer =
nullptr;
1382 QList< QgsMapRendererQImageJob * > mPreviewJobs;
1385 bool mScaleLocked =
false;
1393 bool mZoomDragging =
false;
1396 std::unique_ptr< QgsRubberBand > mZoomRubberBand;
1398 QCursor mZoomCursor;
1400 QTimer mAutoRefreshTimer;
1402 QTimer mPreviewTimer;
1403 QMetaObject::Connection mPreviewTimerConnection;
1409 bool mAnnotationsVisible =
true;
1411 bool mUsePreviewJobs =
false;
1413 QHash< QString, int > mLastLayerRenderTime;
1415 QVector<QPointer<QgsCustomDropHandler >> mDropHandlers;
1418 QList<double> mZoomResolutions;
1420 QList< QgsMapCanvasInteractionBlocker * > mInteractionBlockers;
1422 int mBlockItemPositionUpdates = 0;
1424 QMetaObject::Connection mScreenDpiChangedConnection;
1426 std::unique_ptr< QgsTemporaryCursorOverride > mTemporaryCursorOverride;
1435 QMap <QString, QDateTime> mRendererErrors;
1447 void updateMapSize();
1454 void beginZoomRect( QPoint pos );
1461 void endZoomRect( QPoint pos );
1464 void stopZoomRect();
1490 void setLayersPrivate(
const QList<QgsMapLayer *> &layers );
1492 void startPreviewJobs();
1493 void stopPreviewJobs();
1494 void schedulePreviewJob(
int number );
1499 bool panOperationInProgress();
1501 int nextZoomLevel(
const QList<double> &resolutions,
bool zoomIn =
true )
const;
1507 void clearTemporalCache();
1512 void clearElevationCache();
1522 friend class TestQgsMapCanvas;