QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgselevationprofilecanvas.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgselevationprofilecanvas.h
3  ---------------
4  begin : March 2022
5  copyright : (C) 2022 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSELEVATIONPROFILECANVAS_H
19 #define QGSELEVATIONPROFILECANVAS_H
20 
21 #include "qgsconfig.h"
22 #include "qgis_sip.h"
23 #include "qgis_gui.h"
24 #include "qgsplotcanvas.h"
25 #include "qgsmaplayer.h"
27 #include "qgsprofilepoint.h"
28 
29 class QgsElevationProfilePlotItem;
30 class QgsElevationProfileCrossHairsItem;
33 class QgsCurve;
34 class Qgs2DPlot;
38 
45 class GUI_EXPORT QgsElevationProfileCanvas : public QgsPlotCanvas
46 {
47 
48  Q_OBJECT
49 
50  public:
51 
55  QgsElevationProfileCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
56 
57  ~QgsElevationProfileCanvas() override;
58  QgsCoordinateReferenceSystem crs() const override;
59  QgsPoint toMapCoordinates( const QgsPointXY &point ) const override;
60  QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const override;
61  void resizeEvent( QResizeEvent *event ) override;
62  void paintEvent( QPaintEvent *event ) override;
63  void cancelJobs() override SIP_SKIP;
64  void panContentsBy( double dx, double dy ) override;
65  void centerPlotOn( double x, double y ) override;
66  void scalePlot( double factor ) override;
67  QgsPointXY snapToPlot( QPoint point ) override;
68 
72  void scalePlot( double xFactor, double yFactor );
73 
74  void zoomToRect( const QRectF &rect ) override;
75  void wheelZoom( QWheelEvent *event ) override;
76  void mouseMoveEvent( QMouseEvent *e ) override;
77 
81  QRectF plotArea() const;
82 
87  void refresh() override;
88 
93  void invalidateCurrentPlotExtent();
94 
101  void setProject( QgsProject *project );
102 
108  void setLayers( const QList< QgsMapLayer * > &layers );
109 
115  QList< QgsMapLayer * > layers() const;
116 
122  void setCrs( const QgsCoordinateReferenceSystem &crs );
123 
133  void setProfileCurve( QgsCurve *curve SIP_TRANSFER );
134 
142  QgsCurve *profileCurve() const;
143 
153  void setTolerance( double tolerance );
154 
164  double tolerance() const { return mTolerance; }
165 
172  void setVisiblePlotRange( double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation );
173 
180  QgsDoubleRange visibleDistanceRange() const;
181 
188  QgsDoubleRange visibleElevationRange() const;
189 
195  const Qgs2DPlot &plot() const SIP_SKIP;
196 
200  void render( QgsRenderContext &context, double width, double height, const Qgs2DPlot &plotSettings );
201 
205  QVector<QgsProfileIdentifyResults> identify( QPointF point );
206 
210  QVector<QgsProfileIdentifyResults> identify( const QRectF &rect );
211 
217  QgsProfilePoint canvasPointToPlotPoint( QPointF point ) const;
218 
224  QgsPointXY plotPointToCanvasPoint( const QgsProfilePoint &point ) const;
225 
226  signals:
227 
231  void activeJobCountChanged( int count );
232 
238  void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
239 
240  public slots:
241 
245  void zoomFull();
246 
250  void clear();
251 
255  void setSnappingEnabled( bool enabled );
256 
257  private slots:
258 
259  void generationFinished();
260  void onLayerProfileGenerationPropertyChanged();
261  void onLayerProfileRendererPropertyChanged();
262  void regenerateResultsForLayer();
263  void scheduleDeferredRegeneration();
264  void scheduleDeferredRedraw();
265  void startDeferredRegeneration();
266  void startDeferredRedraw();
267  void refineResults();
268 
269  private:
270 
271  QgsProfileSnapContext snapContext() const;
272  QgsProfileIdentifyContext identifyContext() const;
273 
274  void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
275 
277  QgsProject *mProject = nullptr;
278 
280 
281  QgsElevationProfilePlotItem *mPlotItem = nullptr;
282  QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
283 
284  QgsProfilePlotRenderer *mCurrentJob = nullptr;
285  QTimer *mDeferredRegenerationTimer = nullptr;
286  bool mDeferredRegenerationScheduled = false;
287  QTimer *mDeferredRedrawTimer = nullptr;
288  bool mDeferredRedrawScheduled = false;
289 
290  std::unique_ptr< QgsCurve > mProfileCurve;
291  double mTolerance = 0;
292 
293  bool mFirstDrawOccurred = false;
294 
295  bool mSnappingEnabled = true;
296 
297  bool mZoomFullWhenJobFinished = true;
298 
299  bool mForceRegenerationAfterCurrentJobCompletes = false;
300 
301  static constexpr double MAX_ERROR_PIXELS = 2;
302 };
303 
304 #endif // QGSELEVATIONPROFILECANVAS_H
QgsProfileIdentifyContext
Encapsulates the context of identifying profile results.
Definition: qgsabstractprofilegenerator.h:125
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsPlotCanvas::zoomToRect
virtual void zoomToRect(const QRectF &rect)
Zooms the plot to the specified rect in canvas units.
Definition: qgsplotcanvas.cpp:292
QgsPlotCanvas::resizeEvent
void resizeEvent(QResizeEvent *e) override
Definition: qgsplotcanvas.cpp:197
QgsPlotCanvas::cancelJobs
virtual void cancelJobs()
Cancel any rendering job, in a blocking way.
Definition: qgsplotcanvas.cpp:79
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2153
QgsPlotCanvas::crs
virtual QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
Definition: qgsplotcanvas.cpp:262
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
Qgs2DPlot
Base class for 2-dimensional plot/chart/graphs.
Definition: qgsplot.h:234
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgsplotcanvas.h
QgsPlotCanvas::toCanvasCoordinates
virtual QgsPointXY toCanvasCoordinates(const QgsPoint &point) const
Converts a point in map coordinates to the associated canvas point.
Definition: qgsplotcanvas.cpp:272
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsPlotCanvas::scalePlot
virtual void scalePlot(double factor)
Scales the plot by a specified scale factor.
Definition: qgsplotcanvas.cpp:287
QgsProfileSnapContext
Encapsulates the context of snapping a profile point.
Definition: qgsprofilesnapping.h:30
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsPlotCanvas::centerPlotOn
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
Definition: qgsplotcanvas.cpp:282
QgsProfilePoint
Encapsulates a point on a distance-elevation profile.
Definition: qgsprofilepoint.h:30
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsProfileIdentifyResults
Stores identify results generated by a QgsAbstractProfileResults object.
Definition: qgsabstractprofilegenerator.h:158
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsPlotCanvas::refresh
virtual void refresh()
Updates and redraws the plot.
Definition: qgsplotcanvas.cpp:84
qgsprofilepoint.h
QgsElevationProfileCanvas
A canvas for elevation profiles.
Definition: qgselevationprofilecanvas.h:45
QgsPlotCanvas::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition: qgsplotcanvas.cpp:216
qgsmaplayer.h
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsPlotCanvas::snapToPlot
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
Definition: qgsplotcanvas.cpp:297
QgsDoubleRange
QgsRange which stores a range of double values.
Definition: qgsrange.h:202
QgsElevationProfileCanvas::tolerance
double tolerance() const
Returns the tolerance of the profile (in crs() units).
Definition: qgselevationprofilecanvas.h:164
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsPlotCanvas::panContentsBy
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
Definition: qgsplotcanvas.cpp:277
QgsPlotCanvas::toMapCoordinates
virtual QgsPoint toMapCoordinates(const QgsPointXY &point) const
Converts a point on the canvas to the associated map coordinate.
Definition: qgsplotcanvas.cpp:267
QgsAbstractProfileResults
Abstract base class for storage of elevation profiles.
Definition: qgsabstractprofilegenerator.h:193
QgsPlotCanvas::wheelZoom
virtual void wheelZoom(QWheelEvent *event)
Zoom plot from a mouse wheel event.
Definition: qgsplotcanvas.cpp:311
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
QgsProfilePlotRenderer
Generates and renders elevation profile plots.
Definition: qgsprofilerenderer.h:58