QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 Q_OBJECT
49
50 public:
54 QgsElevationProfileCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
55
57 QgsCoordinateReferenceSystem crs() const override;
58 QgsPoint toMapCoordinates( const QgsPointXY &point ) const override;
59 QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const override;
60 void resizeEvent( QResizeEvent *event ) override;
61 void paintEvent( QPaintEvent *event ) override;
62 void cancelJobs() override SIP_SKIP;
63 void panContentsBy( double dx, double dy ) override;
64 void centerPlotOn( double x, double y ) override;
65 void scalePlot( double factor ) override;
66 QgsPointXY snapToPlot( QPoint point ) override;
67
71 void scalePlot( double xFactor, double yFactor );
72
73 void zoomToRect( const QRectF &rect ) override;
74 void wheelZoom( QWheelEvent *event ) override;
75 void mouseMoveEvent( QMouseEvent *e ) override;
76
80 QRectF plotArea() const;
81
86 void refresh() override;
87
92 void invalidateCurrentPlotExtent();
93
100 void setProject( QgsProject *project );
101
107 void setLayers( const QList<QgsMapLayer *> &layers );
108
114 QList<QgsMapLayer *> layers() const;
115
121 void setCrs( const QgsCoordinateReferenceSystem &crs );
122
132 void setProfileCurve( QgsCurve *curve SIP_TRANSFER );
133
141 QgsCurve *profileCurve() const;
142
152 void setTolerance( double tolerance );
153
163 double tolerance() const { return mTolerance; }
164
171 void setVisiblePlotRange( double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation );
172
179 QgsDoubleRange visibleDistanceRange() const;
180
187 QgsDoubleRange visibleElevationRange() const;
188
194 const Qgs2DPlot &plot() const SIP_SKIP;
195
199 void render( QgsRenderContext &context, double width, double height, const Qgs2DPlot &plotSettings );
200
204 QVector<QgsProfileIdentifyResults> identify( QPointF point );
205
209 QVector<QgsProfileIdentifyResults> identify( const QRectF &rect );
210
216 QgsProfilePoint canvasPointToPlotPoint( QPointF point ) const;
217
223 QgsPointXY plotPointToCanvasPoint( const QgsProfilePoint &point ) const;
224
231 bool lockAxisScales() const;
232
239 void setLockAxisScales( bool lock );
240
247 Qgis::DistanceUnit distanceUnit() const;
248
255 void setDistanceUnit( Qgis::DistanceUnit unit );
256
265 void setBackgroundColor( const QColor &color );
266
267 signals:
268
272 void activeJobCountChanged( int count );
273
279 void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
280
281 public slots:
282
286 void zoomFull();
287
291 void clear();
292
296 void setSnappingEnabled( bool enabled );
297
298 private slots:
299
300 void generationFinished();
301 void onLayerProfileGenerationPropertyChanged();
302 void onLayerProfileRendererPropertyChanged();
303 void regenerateResultsForLayer();
304 void scheduleDeferredRegeneration();
305 void scheduleDeferredRedraw();
306 void startDeferredRegeneration();
307 void startDeferredRedraw();
308 void refineResults();
309
310 private:
311 void updateChartFromPalette();
312 QgsProfileSnapContext snapContext() const;
313 QgsProfileIdentifyContext identifyContext() const;
314
315 void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
316
317 void adjustRangeForAxisScaleLock( double &xMinimum, double &xMaximum, double &yMinimum, double &yMaximum ) const;
318
319 QgsScreenHelper *mScreenHelper = nullptr;
320
321 bool mLockAxisScales = false;
322
324 QgsProject *mProject = nullptr;
325 Qgis::DistanceUnit mDistanceUnit = Qgis::DistanceUnit::Unknown;
326
328
329 QgsElevationProfilePlotItem *mPlotItem = nullptr;
330 QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
331
332 QgsProfilePlotRenderer *mCurrentJob = nullptr;
333 QTimer *mDeferredRegenerationTimer = nullptr;
334 bool mDeferredRegenerationScheduled = false;
335 QTimer *mDeferredRedrawTimer = nullptr;
336 bool mDeferredRedrawScheduled = false;
337
338 std::unique_ptr<QgsCurve> mProfileCurve;
339 double mTolerance = 0;
340
341 bool mFirstDrawOccurred = false;
342
343 bool mSnappingEnabled = true;
344
345 bool mZoomFullWhenJobFinished = true;
346
347 bool mForceRegenerationAfterCurrentJobCompletes = false;
348
349 static constexpr double MAX_ERROR_PIXELS = 2;
350};
351
352#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