QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
23#include "qgis_gui.h"
24#include "qgis_sip.h"
26#include "qgslinesymbol.h"
27#include "qgsmaplayer.h"
28#include "qgsplotcanvas.h"
29#include "qgsprofilepoint.h"
30
31class QgsElevationProfilePlotItem;
32class QgsElevationProfileCrossHairsItem;
35class QgsCurve;
36class Qgs2DXyPlot;
40class QgsScreenHelper;
41
49{
50 Q_OBJECT
51
52 public:
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
95
102 void setProject( QgsProject *project );
103
109 void setLayers( const QList<QgsMapLayer *> &layers );
110
116 QList<QgsMapLayer *> layers() const;
117
123 void setSources( const QList<QgsAbstractProfileSource *> &sources );
124
132 QList<QgsAbstractProfileSource *> sources() const;
133
140
151
159 QgsCurve *profileCurve() const;
160
170 void setTolerance( double tolerance );
171
181 double tolerance() const { return mTolerance; }
182
189 void setVisiblePlotRange( double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation );
190
197 QgsDoubleRange visibleDistanceRange() const;
198
205 QgsDoubleRange visibleElevationRange() const;
206
212 const Qgs2DXyPlot &plot() const SIP_SKIP;
213
217 void render( QgsRenderContext &context, double width, double height, const Qgs2DXyPlot &plotSettings );
218
222 QVector<QgsProfileIdentifyResults> identify( QPointF point );
223
227 QVector<QgsProfileIdentifyResults> identify( const QRectF &rect );
228
234 QgsProfilePoint canvasPointToPlotPoint( QPointF point ) const;
235
241 QgsPointXY plotPointToCanvasPoint( const QgsProfilePoint &point ) const;
242
249 bool lockAxisScales() const;
250
257 void setLockAxisScales( bool lock );
258
266 double axisScaleRatio() const;
267
280 void setAxisScaleRatio( double scale );
281
288 Qgis::DistanceUnit distanceUnit() const;
289
296 void setDistanceUnit( Qgis::DistanceUnit unit );
297
306 void setBackgroundColor( const QColor &color );
307
314 QgsLineSymbol *subsectionsSymbol() { return mSubsectionsSymbol.get(); }
315
323 void setSubsectionsSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
324
325 signals:
326
330 void activeJobCountChanged( int count );
331
337 void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
338
345
346 public slots:
347
351 void zoomFull();
352
356 void clear();
357
361 void setSnappingEnabled( bool enabled );
362
363 private slots:
364
365 void generationFinished();
366 void onLayerProfileGenerationPropertyChanged();
367 void onLayerProfileRendererPropertyChanged();
368 void regenerateResultsForLayer();
369 void scheduleDeferredRegeneration();
370 void scheduleDeferredRedraw();
371 void startDeferredRegeneration();
372 void startDeferredRedraw();
373 void refineResults();
374 void setSourcesPrivate();
375
376 private:
377 void updateChartFromPalette();
378 QgsProfileSnapContext snapContext() const;
379 QgsProfileIdentifyContext identifyContext() const;
380
381 void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
382
383 void adjustRangeForAxisScaleLock( double &xMinimum, double &xMaximum, double &yMinimum, double &yMaximum ) const;
384
385 QgsScreenHelper *mScreenHelper = nullptr;
386
387 bool mLockAxisScales = false;
388 double mLockedAxisScale = 1;
389
391 QgsProject *mProject = nullptr;
393
395 QList< std::variant< QgsWeakMapLayerPointer, QgsAbstractProfileSource * > > mSources;
396
397 QgsElevationProfilePlotItem *mPlotItem = nullptr;
398 QgsElevationProfileCrossHairsItem *mCrossHairsItem = nullptr;
399
400 QgsProfilePlotRenderer *mCurrentJob = nullptr;
401 QTimer *mDeferredRegenerationTimer = nullptr;
402 bool mDeferredRegenerationScheduled = false;
403 QTimer *mDeferredRedrawTimer = nullptr;
404 bool mDeferredRedrawScheduled = false;
405
406 std::unique_ptr<QgsCurve> mProfileCurve;
407 double mTolerance = 0;
408
409 bool mFirstDrawOccurred = false;
410
411 bool mSnappingEnabled = true;
412
413 bool mZoomFullWhenJobFinished = true;
414
415 bool mForceRegenerationAfterCurrentJobCompletes = false;
416
417 static constexpr double MAX_ERROR_PIXELS = 2;
418
419 std::unique_ptr<QgsLineSymbol> mSubsectionsSymbol;
420};
421
422#endif // QGSELEVATIONPROFILECANVAS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
DistanceUnit
Units of distance.
Definition qgis.h:5170
@ Unknown
Unknown distance unit.
Definition qgis.h:5220
Base class for 2-dimensional plot/chart/graphs with an X and Y axes.
Definition qgsplot.h:687
Abstract base class for storage of elevation profiles.
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:217
QgsCurve * profileCurve() const
Returns the profile curve.
void setTolerance(double tolerance)
Sets the profile tolerance (in crs() units).
void setSources(const QList< QgsAbstractProfileSource * > &sources)
Sets the list of sources to include in the profile.
void setProfileCurve(QgsCurve *curve)
Sets the profile curve.
void activeJobCountChanged(int count)
Emitted when the number of active background jobs changes.
QgsElevationProfileCanvas(QWidget *parent=nullptr)
Constructor for QgsElevationProfileCanvas, with the specified parent widget.
void paintEvent(QPaintEvent *event) override
QgsCoordinateReferenceSystem crs() const override
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
void clear()
Clears the current profile.
void canvasPointHovered(const QgsPointXY &point, const QgsProfilePoint &profilePoint)
Emitted when the mouse hovers over the specified point (in canvas coordinates).
void setProject(QgsProject *project)
Sets the project associated with the profile.
QList< QgsMapLayer * > layers() const
Returns the list of layers included in the profile.
double tolerance() const
Returns the tolerance of the profile (in crs() units).
void invalidateCurrentPlotExtent()
Invalidates the current plot extent, which means that the visible plot area will be recalculated and ...
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs associated with the canvas' map coordinates.
QList< QgsAbstractProfileSource * > sources() const
Returns the list of sources included in the profile.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to include in the profile.
void zoomFull()
Zooms to the full extent of the profile.
void scaleChanged()
Emitted when the plot scale is changed.
QgsLineSymbol * subsectionsSymbol()
Returns the symbol used to draw the subsections.
void setSnappingEnabled(bool enabled)
Sets whether snapping of cursor points is enabled.
QRectF plotArea() const
Returns the interior rectangle representing the surface of the plot, in canvas coordinates.
A line symbol type, for rendering LineString and MultiLineString geometries.
Base class for all map layer types.
Definition qgsmaplayer.h:83
bool event(QEvent *e) override
virtual void cancelJobs()
Cancel any rendering job, in a blocking way.
QgsPlotCanvas(QWidget *parent=nullptr)
Constructor for QgsPlotCanvas, with the specified parent widget.
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:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
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:113
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:52
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.