QGIS API Documentation 3.43.0-Master (b60ef06885e)
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#include "qgslinesymbol.h"
29
30class QgsElevationProfilePlotItem;
31class QgsElevationProfileCrossHairsItem;
34class QgsCurve;
35class Qgs2DPlot;
39class QgsScreenHelper;
40
48{
49 Q_OBJECT
50
51 public:
55 QgsElevationProfileCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
56
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
232 bool lockAxisScales() const;
233
240 void setLockAxisScales( bool lock );
241
248 Qgis::DistanceUnit distanceUnit() const;
249
256 void setDistanceUnit( Qgis::DistanceUnit unit );
257
266 void setBackgroundColor( const QColor &color );
267
274 QgsLineSymbol *subsectionsSymbol()
275 {
276 return mSubsectionsSymbol.get();
277 }
278
286 void setSubsectionsSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
287
288 signals:
289
293 void activeJobCountChanged( int count );
294
300 void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
301
302 public slots:
303
307 void zoomFull();
308
312 void clear();
313
317 void setSnappingEnabled( bool enabled );
318
319 private slots:
320
321 void generationFinished();
322 void onLayerProfileGenerationPropertyChanged();
323 void onLayerProfileRendererPropertyChanged();
324 void regenerateResultsForLayer();
325 void scheduleDeferredRegeneration();
326 void scheduleDeferredRedraw();
327 void startDeferredRegeneration();
328 void startDeferredRedraw();
329 void refineResults();
330
331 private:
332 void updateChartFromPalette();
333 QgsProfileSnapContext snapContext() const;
334 QgsProfileIdentifyContext identifyContext() const;
335
336 void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
337
338 void adjustRangeForAxisScaleLock( double &xMinimum, double &xMaximum, double &yMinimum, double &yMaximum ) const;
339
340 QgsScreenHelper *mScreenHelper = nullptr;
341
342 bool mLockAxisScales = false;
343
345 QgsProject *mProject = nullptr;
347
349
350 QgsElevationProfilePlotItem *mPlotItem = nullptr;
351 QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
352
353 QgsProfilePlotRenderer *mCurrentJob = nullptr;
354 QTimer *mDeferredRegenerationTimer = nullptr;
355 bool mDeferredRegenerationScheduled = false;
356 QTimer *mDeferredRedrawTimer = nullptr;
357 bool mDeferredRedrawScheduled = false;
358
359 std::unique_ptr<QgsCurve> mProfileCurve;
360 double mTolerance = 0;
361
362 bool mFirstDrawOccurred = false;
363
364 bool mSnappingEnabled = true;
365
366 bool mZoomFullWhenJobFinished = true;
367
368 bool mForceRegenerationAfterCurrentJobCompletes = false;
369
370 static constexpr double MAX_ERROR_PIXELS = 2;
371
372 std::unique_ptr<QgsLineSymbol> mSubsectionsSymbol;
373};
374
375#endif // QGSELEVATIONPROFILECANVAS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
DistanceUnit
Units of distance.
Definition qgis.h:4843
@ Unknown
Unknown distance unit.
Base class for 2-dimensional plot/chart/graphs.
Definition qgsplot.h:273
Abstract base class for storage of elevation profiles.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
Definition qgscurve.h:35
QgsRange which stores a range of double values.
Definition qgsrange.h:233
A canvas for elevation profiles.
void activeJobCountChanged(int count)
Emitted when the number of active background jobs changes.
void canvasPointHovered(const QgsPointXY &point, const QgsProfilePoint &profilePoint)
Emitted when the mouse hovers over the specified point (in canvas coordinates).
double tolerance() const
Returns the tolerance of the profile (in crs() units).
A line symbol type, for rendering LineString and MultiLineString geometries.
Base class for all map layer types.
Definition qgsmaplayer.h:77
Plot canvas is a class for displaying interactive 2d charts and plots.
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.
Represents a 2D point.
Definition qgspointxy.h:60
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:107
Contains information about the context of a rendering operation.
A utility class for dynamic handling of changes to screen properties.
#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.
const QgsCoordinateReferenceSystem & crs