QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsprofilerenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprofilerenderer.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#ifndef QGSPROFILERENDERER_H
18#define QGSPROFILERENDERER_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
23#include "qgslinesymbol.h"
24#include "qgsprofilerequest.h"
25#include "qgsrange.h"
26
27#include <QFutureWatcher>
28#include <QObject>
29
33class QgsFeedback;
37class QgsProfilePoint;
38
59class CORE_EXPORT QgsProfilePlotRenderer : public QObject
60{
61
62 Q_OBJECT
63
64 public:
65
70 QgsProfilePlotRenderer( const QList< QgsAbstractProfileSource * > &sources,
71 const QgsProfileRequest &request );
72
81 QgsProfilePlotRenderer( std::vector<std::unique_ptr<QgsAbstractProfileGenerator> > generators,
82 const QgsProfileRequest &request ) SIP_SKIP;
83
84 ~QgsProfilePlotRenderer() override;
85
89 QStringList sourceIds() const;
90
95 void startGeneration();
96
109
114 void cancelGeneration();
115
122
124 void waitForFinished();
125
127 bool isActive() const;
128
134 void setContext( const QgsProfileGenerationContext &context );
135
140
147
158
167
171 QgsDoubleRange zRange() const;
172
178 QImage renderToImage( int width, int height, double distanceMin, double distanceMax, double zMin, double zMax, const QString &sourceId = QString(), double devicePixelRatio = 1.0 );
179
185 void render( QgsRenderContext &context, double width, double height, double distanceMin, double distanceMax, double zMin, double zMax, const QString &sourceId = QString() );
186
193 static std::unique_ptr<QgsLineSymbol> defaultSubSectionsSymbol() SIP_FACTORY;
194
202
211
219 void renderSubsectionsIndicator( QgsRenderContext &context, const QRectF &plotArea, double distanceMin, double distanceMax, double zMin, double zMax );
220
225
229 QVector<QgsProfileIdentifyResults> identify( const QgsProfilePoint &point, const QgsProfileIdentifyContext &context );
230
234 QVector<QgsProfileIdentifyResults> identify( const QgsDoubleRange &distanceRange, const QgsDoubleRange &elevationRange, const QgsProfileIdentifyContext &context );
235
241 QVector< QgsAbstractProfileResults::Feature > asFeatures( Qgis::ProfileExportType type, QgsFeedback *feedback = nullptr );
242
243 signals:
244
247
248 private slots:
249
250 void onGeneratingFinished();
251
252 private:
253
254 static QTransform computeRenderTransform( double width, double height, double distanceMin, double distanceMax, double zMin, double zMax );
255
256 struct ProfileJob
257 {
258 QgsAbstractProfileGenerator *generator = nullptr;
260 std::unique_ptr< QgsAbstractProfileResults > results;
261 std::unique_ptr< QgsAbstractProfileResults > invalidatedResults;
262 bool complete = false;
263 QMutex mutex;
264 };
265
266 static void generateProfileStatic( std::unique_ptr< ProfileJob > &job );
267 bool replaceSourceInternal( QgsAbstractProfileSource *source, bool clearPreviousResults );
268
269 std::vector< std::unique_ptr< QgsAbstractProfileGenerator > > mGenerators;
270 QgsProfileRequest mRequest;
272
273 std::vector< std::unique_ptr< ProfileJob > > mJobs;
274
275 QFuture<void> mFuture;
276 QFutureWatcher<void> mFutureWatcher;
277
278 enum { Idle, Generating } mStatus = Idle;
279
280 std::unique_ptr<QgsLineSymbol> mSubsectionsSymbol;
281
282};
283
284#endif // QGSPROFILERENDERER_H
ProfileExportType
Types of export for elevation profiles.
Definition qgis.h:4233
Abstract base class for objects which generate elevation profiles.
Abstract base class for storage of elevation profiles.
Interface for classes which can generate elevation profiles.
QgsRange which stores a range of double values.
Definition qgsrange.h:233
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A line symbol type, for rendering LineString and MultiLineString geometries.
Encapsulates the context in which an elevation profile is to be generated.
Encapsulates the context of identifying profile results.
void setSubsectionsSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the subsections.
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context)
Snap a point to the results.
void render(QgsRenderContext &context, double width, double height, double distanceMin, double distanceMax, double zMin, double zMax, const QString &sourceId=QString())
Renders a portion of the profile using the specified render context.
void renderSubsectionsIndicator(QgsRenderContext &context, const QRectF &plotArea, double distanceMin, double distanceMax, double zMin, double zMax)
Renders the vertices of the profile curve as vertical lines using the specified render context.
void regenerateInvalidatedResults()
Starts a background regeneration of any invalidated results and immediately returns.
QVector< QgsAbstractProfileResults::Feature > asFeatures(Qgis::ProfileExportType type, QgsFeedback *feedback=nullptr)
Exports the profile results as a set of features.
QImage renderToImage(int width, int height, double distanceMin, double distanceMax, double zMin, double zMax, const QString &sourceId=QString(), double devicePixelRatio=1.0)
Renders a portion of the profile to an image with the given width and height.
void cancelGenerationWithoutBlocking()
Triggers cancellation of the generation job without blocking.
QgsLineSymbol * subsectionsSymbol()
Returns the line symbol used to draw the subsections.
void invalidateAllRefinableSources()
Invalidates previous results from all refinable sources.
void cancelGeneration()
Stop the generation job - does not return until the job has terminated.
QgsProfilePlotRenderer(const QList< QgsAbstractProfileSource * > &sources, const QgsProfileRequest &request)
Constructor for QgsProfilePlotRenderer, using the provided list of profile sources to generate the re...
void generateSynchronously()
Generate the profile results synchronously in this thread.
void startGeneration()
Start the generation job and immediately return.
QgsDoubleRange zRange() const
Returns the limits of the retrieved elevation values.
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context)
Identify results visible at the specified profile point.
void waitForFinished()
Block until the current job has finished.
bool isActive() const
Returns true if the generation job is currently running in background.
QStringList sourceIds() const
Returns the ordered list of source IDs for the sources used by the renderer.
bool invalidateResults(QgsAbstractProfileSource *source)
Invalidates the profile results from the source with matching ID.
void replaceSource(QgsAbstractProfileSource *source)
Replaces the existing source with matching ID.
void setContext(const QgsProfileGenerationContext &context)
Sets the context in which the profile generation will occur.
void generationFinished()
Emitted when the profile generation is finished (or canceled).
static std::unique_ptr< QgsLineSymbol > defaultSubSectionsSymbol()
Returns the default line symbol to use for subsections lines.
Encapsulates a point on a distance-elevation profile.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Encapsulates the context of snapping a profile point.
Encapsulates results of snapping a profile point.
Contains information about the context of a rendering operation.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84