QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
233 bool lockAxisScales() const;
234
241 void setLockAxisScales( bool lock );
242
249 Qgis::DistanceUnit distanceUnit() const;
250
257 void setDistanceUnit( Qgis::DistanceUnit unit );
258
267 void setBackgroundColor( const QColor &color );
268
269 signals:
270
274 void activeJobCountChanged( int count );
275
281 void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
282
283 public slots:
284
288 void zoomFull();
289
293 void clear();
294
298 void setSnappingEnabled( bool enabled );
299
300 private slots:
301
302 void generationFinished();
303 void onLayerProfileGenerationPropertyChanged();
304 void onLayerProfileRendererPropertyChanged();
305 void regenerateResultsForLayer();
306 void scheduleDeferredRegeneration();
307 void scheduleDeferredRedraw();
308 void startDeferredRegeneration();
309 void startDeferredRedraw();
310 void refineResults();
311
312 private:
313
314 void updateChartFromPalette();
315 QgsProfileSnapContext snapContext() const;
316 QgsProfileIdentifyContext identifyContext() const;
317
318 void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
319
320 void adjustRangeForAxisScaleLock( double &xMinimum, double &xMaximum, double &yMinimum, double &yMaximum ) const;
321
322 QgsScreenHelper *mScreenHelper = nullptr;
323
324 bool mLockAxisScales = false;
325
327 QgsProject *mProject = nullptr;
328 Qgis::DistanceUnit mDistanceUnit = Qgis::DistanceUnit::Unknown;
329
331
332 QgsElevationProfilePlotItem *mPlotItem = nullptr;
333 QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
334
335 QgsProfilePlotRenderer *mCurrentJob = nullptr;
336 QTimer *mDeferredRegenerationTimer = nullptr;
337 bool mDeferredRegenerationScheduled = false;
338 QTimer *mDeferredRedrawTimer = nullptr;
339 bool mDeferredRedrawScheduled = false;
340
341 std::unique_ptr< QgsCurve > mProfileCurve;
342 double mTolerance = 0;
343
344 bool mFirstDrawOccurred = false;
345
346 bool mSnappingEnabled = true;
347
348 bool mZoomFullWhenJobFinished = true;
349
350 bool mForceRegenerationAfterCurrentJobCompletes = false;
351
352 static constexpr double MAX_ERROR_PIXELS = 2;
353};
354
355#endif // QGSELEVATIONPROFILECANVAS_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
Base class for 2-dimensional plot/chart/graphs.
Definition qgsplot.h:273
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:35
QgsRange which stores a range of double values.
Definition qgsrange.h:231
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:76
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.
A class to represent 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