QGIS API Documentation 4.5.0-Master (c9e0ddc514d)
Loading...
Searching...
No Matches
qgslayoutitemelevationprofile.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutitemelevationprofile.h
3 -------------------------------
4 begin : January 2023
5 copyright : (C) 2023 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 QGSLAYOUTITEMELEVATIONPROFILE_H
18#define QGSLAYOUTITEMELEVATIONPROFILE_H
19
20#include "qgis_core.h"
21#include "qgslayoutitem.h"
22#include "qgsmaplayerref.h"
23
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
28class QgsLayoutItemElevationProfilePlot;
29class Qgs2DXyPlot;
32class QgsLineSymbol;
33
40{
41 Q_OBJECT
42
43 public:
48
50
57
58 int type() const override;
59 QIcon icon() const override;
61 QgsLayoutItem::Flags itemFlags() const override;
62 bool requiresRasterization() const override;
63 bool containsAdvancedEffects() const override;
64
70
75 const Qgs2DXyPlot *plot() const SIP_SKIP;
76
82 QList< QgsMapLayer * > layers() const;
83
89 void setLayers( const QList< QgsMapLayer * > &layers );
90
98 QList<QgsAbstractProfileSource *> sources() const;
99
100#ifndef SIP_RUN
106 void setSources( const QList< std::variant< QgsMapLayer *, QgsAbstractProfileSource * > > &sources );
107#else
108 // clang-format off
109
115 void setSources( SIP_PYOBJECT sources SIP_TYPEHINT( List[Union[QgsMapLayer, QgsAbstractProfileSource]] ) );
116 % MethodCode
117 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
118 {
119 sipIsErr = 0;
120 QList< std::variant< QgsMapLayer *, QgsAbstractProfileSource * > > sourcesList;
121 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( a0 ); ++i )
122 {
123 PyObject *p0 = PyList_GetItem( a0, i );
124 int state;
125
126 const sipTypeDef *source_type = sipFindType( "QgsAbstractProfileSource" );
127
128 if ( sipCanConvertToType( p0, sipType_QgsMapLayer, SIP_NOT_NONE ) )
129 {
130 QgsMapLayer *layerSource = reinterpret_cast<QgsMapLayer *>( sipConvertToType( p0, sipType_QgsMapLayer, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
131 if ( !sipIsErr )
132 {
133 if ( layerSource->profileSource() )
134 {
135 sourcesList << layerSource;
136 }
137 else
138 {
139 sipIsErr = 1;
140 PyErr_SetString( PyExc_ValueError, u"The input list contains a map layer that does not provide a valid profile source!"_s.toUtf8().constData() );
141 }
142 }
143
144 sipReleaseType( layerSource, sipType_QgsMapLayer, state );
145 }
146 else if ( sipCanConvertToType( p0, source_type, SIP_NOT_NONE ) )
147 {
148 QgsAbstractProfileSource *profileSource = reinterpret_cast<QgsAbstractProfileSource *>( sipConvertToType( p0, source_type, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
149 if ( !sipIsErr )
150 {
151 sourcesList << profileSource;
152 }
153
154 sipReleaseType( profileSource, source_type, state );
155 }
156 else
157 {
158 sipIsErr = 1;
159 PyErr_SetString( PyExc_TypeError, u"The input list contains an element with unexpected type!"_s.toUtf8().constData() );
160 }
161 }
162 if ( !sipIsErr )
163 {
164 sipCpp->setSources( sourcesList );
165 }
166 }
167 else
168 {
169 sipIsErr = 1;
170 PyErr_SetString( PyExc_TypeError, u"First argument is not a list or is empty."_s.toUtf8().constData() );
171 }
172 % End
173// clang-format on
174#endif
175
186
194 QgsCurve *profileCurve() const;
195
204
213
224 void setTolerance( double tolerance );
225
236 double tolerance() const;
237
243 bool atlasDriven() const { return mAtlasDriven; }
244
252 void setAtlasDriven( bool enabled );
253
257 QgsProfileRequest profileRequest() const;
258
259 void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
260
267 Qgis::DistanceUnit distanceUnit() const;
268
275 void setDistanceUnit( Qgis::DistanceUnit unit );
276
283 QgsLineSymbol *subsectionsSymbol() { return mSubsectionsSymbol.get(); }
284
292 void setSubsectionsSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
293
300 Qgis::ElevationProfileRangeMethod rangeMethod() const;
301
308 void setRangeMethod( Qgis::ElevationProfileRangeMethod method );
309
322 double elevationScale() const;
323
336 void setElevationScale( double scale );
337
350 double distanceScale() const;
351
364 void setDistanceScale( double scale );
365
366 public slots:
367
368 void refresh() override;
369 void invalidateCache() override;
370
371 signals:
372
379
380 protected:
381 void draw( QgsLayoutItemRenderContext &context ) override;
382 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
383 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
384
385 private slots:
386
387 void recreateCachedImageInBackground();
388 void profileGenerationFinished();
389 void setSourcesPrivate();
390
391 private:
392 void calculateAxisRanges( QgsRenderContext &context );
393
394 std::unique_ptr< QgsLayoutItemElevationProfilePlot > mPlot;
395
396 QList< QgsMapLayerRef > mLayers;
397 QList< std::variant< QgsMapLayerRef, QgsAbstractProfileSource * > > mSources;
398
400 double mElevationScale = 10;
401 double mDistanceScale = 1000;
402
405 std::unique_ptr< QgsCurve> mCurve;
406 bool mAtlasDriven = false;
407
408 double mTolerance = 0;
409
410 std::unique_ptr<QgsLineSymbol> mSubsectionsSymbol;
411
412 // render job handling
413
414 // see note in QgsLayoutItemMap about these!
415 std::unique_ptr< QImage > mCacheFinalImage;
416 std::unique_ptr< QImage > mCacheRenderingImage;
417 bool mUpdatesEnabled = true;
418 bool mCacheInvalidated = true;
419 bool mDrawing = false;
420 bool mDrawingPreview = false;
421 QTimer *mBackgroundUpdateTimer = nullptr;
422 double mPreviewScaleFactor = 0;
423 std::unique_ptr< QPainter > mPainter;
424 std::unique_ptr< QgsProfilePlotRenderer > mRenderJob;
425};
426
427#endif //QGSLAYOUTITEMELEVATIONPROFILE_H
DistanceUnit
Units of distance.
Definition qgis.h:5595
@ Unknown
Unknown distance unit.
Definition qgis.h:5645
ElevationProfileRangeMethod
Elevation profile range calculation methods.
Definition qgis.h:6192
@ ManualRange
Distance/elevation ranges are manually set.
Definition qgis.h:6193
Base class for 2-dimensional plot/chart/graphs with an X and Y axes.
Definition qgsplot.h:687
Interface for classes which can generate elevation profiles.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
Definition qgscurve.h:36
static QgsLayoutItemElevationProfile * create(QgsLayout *layout)
Returns a new elevation profile item for the specified layout.
Qgs2DXyPlot * plot()
Returns a reference to the elevation plot object, which can be used to set plot appearance and proper...
QgsLayoutItemElevationProfile(QgsLayout *layout)
Constructor for QgsLayoutItemElevationProfile, with the specified parent layout.
QgsCurve * profileCurve() const
Returns the cross section profile curve, which represents the line along which the profile should be ...
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of map layers participating in the elevation profile.
QList< QgsMapLayer * > layers() const
Returns the list of map layers participating in the elevation profile.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the desired Coordinate Reference System (crs) for the profile.
void setSources(const QList< std::variant< QgsMapLayer *, QgsAbstractProfileSource * > > &sources)
Sets the list of sources participating in the elevation profile.
QList< QgsAbstractProfileSource * > sources() const
Returns the list of sources participating in the elevation profile.
void setTolerance(double tolerance)
Sets the tolerance of the request (in crs() units).
QgsCoordinateReferenceSystem crs() const
Returns the desired Coordinate Reference System for the profile.
double tolerance() const
Returns the tolerance of the request (in crs() units).
QgsLineSymbol * subsectionsSymbol()
Returns the symbol used to draw the subsections.
bool atlasDriven() const
Returns whether the profile curve is set to follow the current atlas feature.
void previewRefreshed()
Emitted whenever the item's preview has been refreshed.
void setProfileCurve(QgsCurve *curve)
Sets the cross section profile curve, which represents the line along which the profile should be gen...
Contains settings and helpers relating to a render of a QgsLayoutItem.
friend class QgsLayout
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
virtual QIcon icon() const
Returns the item's icon.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item's content.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
int type() const override
Returns a unique graphics item type identifier.
virtual bool requiresRasterization() const
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
QFlags< Flag > Flags
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
friend class QgsLayoutItemElevationProfile
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
const QgsLayout * layout() const
Returns the layout the object is attached to.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
A line symbol type, for rendering LineString and MultiLineString geometries.
Base class for all map layer types.
Definition qgsmaplayer.h:84
virtual QgsAbstractProfileSource * profileSource()
Returns the layer's profile source if it has profile capabilities.
Generates and renders elevation profile plots.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:242
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83