QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
29class QgsElevationProfilePlotItem;
30class QgsElevationProfileCrossHairsItem;
33class QgsCurve;
34class Qgs2DPlot;
38class QgsScreenHelper;
39
47{
48
49 Q_OBJECT
50
51 public:
52
56 QgsElevationProfileCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
57
59 QgsCoordinateReferenceSystem crs() const override;
60 QgsPoint toMapCoordinates( const QgsPointXY &point ) const override;
61 QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const override;
62 void resizeEvent( QResizeEvent *event ) override;
63 void paintEvent( QPaintEvent *event ) override;
64 void cancelJobs() override SIP_SKIP;
65 void panContentsBy( double dx, double dy ) override;
66 void centerPlotOn( double x, double y ) override;
67 void scalePlot( double factor ) override;
68 QgsPointXY snapToPlot( QPoint point ) override;
69
73 void scalePlot( double xFactor, double yFactor );
74
75 void zoomToRect( const QRectF &rect ) override;
76 void wheelZoom( QWheelEvent *event ) override;
77 void mouseMoveEvent( QMouseEvent *e ) override;
78
82 QRectF plotArea() const;
83
88 void refresh() override;
89
94 void invalidateCurrentPlotExtent();
95
102 void setProject( QgsProject *project );
103
109 void setLayers( const QList< QgsMapLayer * > &layers );
110
116 QList< QgsMapLayer * > layers() const;
117
123 void setCrs( const QgsCoordinateReferenceSystem &crs );
124
134 void setProfileCurve( QgsCurve *curve SIP_TRANSFER );
135
143 QgsCurve *profileCurve() const;
144
154 void setTolerance( double tolerance );
155
165 double tolerance() const { return mTolerance; }
166
173 void setVisiblePlotRange( double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation );
174
181 QgsDoubleRange visibleDistanceRange() const;
182
189 QgsDoubleRange visibleElevationRange() const;
190
196 const Qgs2DPlot &plot() const SIP_SKIP;
197
201 void render( QgsRenderContext &context, double width, double height, const Qgs2DPlot &plotSettings );
202
206 QVector<QgsProfileIdentifyResults> identify( QPointF point );
207
211 QVector<QgsProfileIdentifyResults> identify( const QRectF &rect );
212
218 QgsProfilePoint canvasPointToPlotPoint( QPointF point ) const;
219
225 QgsPointXY plotPointToCanvasPoint( const QgsProfilePoint &point ) const;
226
227 signals:
228
232 void activeJobCountChanged( int count );
233
239 void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
240
241 public slots:
242
246 void zoomFull();
247
251 void clear();
252
256 void setSnappingEnabled( bool enabled );
257
258 private slots:
259
260 void generationFinished();
261 void onLayerProfileGenerationPropertyChanged();
262 void onLayerProfileRendererPropertyChanged();
263 void regenerateResultsForLayer();
264 void scheduleDeferredRegeneration();
265 void scheduleDeferredRedraw();
266 void startDeferredRegeneration();
267 void startDeferredRedraw();
268 void refineResults();
269
270 private:
271
272 QgsProfileSnapContext snapContext() const;
273 QgsProfileIdentifyContext identifyContext() const;
274
275 void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
276
277 QgsScreenHelper *mScreenHelper = nullptr;
278
280 QgsProject *mProject = nullptr;
281
283
284 QgsElevationProfilePlotItem *mPlotItem = nullptr;
285 QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
286
287 QgsProfilePlotRenderer *mCurrentJob = nullptr;
288 QTimer *mDeferredRegenerationTimer = nullptr;
289 bool mDeferredRegenerationScheduled = false;
290 QTimer *mDeferredRedrawTimer = nullptr;
291 bool mDeferredRedrawScheduled = false;
292
293 std::unique_ptr< QgsCurve > mProfileCurve;
294 double mTolerance = 0;
295
296 bool mFirstDrawOccurred = false;
297
298 bool mSnappingEnabled = true;
299
300 bool mZoomFullWhenJobFinished = true;
301
302 bool mForceRegenerationAfterCurrentJobCompletes = false;
303
304 static constexpr double MAX_ERROR_PIXELS = 2;
305};
306
307#endif // QGSELEVATIONPROFILECANVAS_H
Base class for 2-dimensional plot/chart/graphs.
Definition: qgsplot.h:235
Abstract base class for storage of elevation profiles.
This class represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
A canvas for elevation profiles.
double tolerance() const
Returns the tolerance of the profile (in crs() units).
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:54
virtual void cancelJobs()
Cancel any rendering job, in a blocking way.
virtual void refresh()
Updates and redraws the plot.
virtual void zoomToRect(const QRectF &rect)
Zooms the plot to the specified rect in canvas units.
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
virtual QgsPointXY toCanvasCoordinates(const QgsPoint &point) const
Converts a point in map coordinates to the associated canvas point.
void mouseMoveEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
virtual void scalePlot(double factor)
Scales the plot by a specified scale factor.
virtual QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
virtual void wheelZoom(QWheelEvent *event)
Zoom plot from a mouse wheel event.
virtual QgsPoint toMapCoordinates(const QgsPointXY &point) const
Converts a point on the canvas to the associated map coordinate.
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
Encapsulates the context of identifying profile results.
Stores identify results generated by a QgsAbstractProfileResults object.
Generates and renders elevation profile plots.
Encapsulates a point on a distance-elevation profile.
Encapsulates the context of snapping a profile point.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:105
Contains information about the context of a rendering operation.
A utility class for dynamic handling of changes to screen properties.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2213
const QgsCoordinateReferenceSystem & crs