44#include "moc_qgslayoutitemelevationprofile.cpp"
46using namespace Qt::StringLiterals;
48#define CACHE_SIZE_LIMIT 5000
51class QgsLayoutItemElevationProfilePlot :
public Qgs2DXyPlot
54 QgsLayoutItemElevationProfilePlot() {}
66 const double distanceMin =
xMinimum() * xScale;
67 const double distanceMax =
xMaximum() * xScale;
68 rc.
painter()->translate( plotArea.left(), plotArea.top() );
69 mRenderer->render( rc, plotArea.width(), plotArea.height(), distanceMin, distanceMax, yMinimum(),
yMaximum() );
70 rc.
painter()->translate( -plotArea.left(), -plotArea.top() );
71 mRenderer->renderSubsectionsIndicator( rc, plotArea, distanceMin, distanceMax,
yMinimum(),
yMaximum() );
84 , mPlot( std::make_unique< QgsLayoutItemElevationProfilePlot >() )
86 mBackgroundUpdateTimer =
new QTimer(
this );
87 mBackgroundUpdateTimer->setSingleShot(
true );
88 connect( mBackgroundUpdateTimer, &QTimer::timeout,
this, &QgsLayoutItemElevationProfile::recreateCachedImageInBackground );
90 setCacheMode( QGraphicsItem::NoCache );
114 mRenderJob->cancelGeneration();
138 bool forceUpdate =
false;
143 double value = mTolerance;
163 double value = mPlot->xMinimum();
174 mPlot->setXMinimum( value );
183 double value = mPlot->xMaximum();
194 mPlot->setXMaximum( value );
203 double value = mPlot->yMinimum();
214 mPlot->setYMinimum( value );
223 double value = mPlot->yMaximum();
234 mPlot->setYMaximum( value );
243 double value = mPlot->xAxis().gridIntervalMajor();
254 mPlot->xAxis().setGridIntervalMajor( value );
263 double value = mPlot->xAxis().gridIntervalMinor();
274 mPlot->xAxis().setGridIntervalMinor( value );
283 double value = mPlot->xAxis().labelInterval();
294 mPlot->xAxis().setLabelInterval( value );
303 double value = mPlot->yAxis().gridIntervalMajor();
314 mPlot->yAxis().setGridIntervalMajor( value );
323 double value = mPlot->yAxis().gridIntervalMinor();
334 mPlot->yAxis().setGridIntervalMinor( value );
343 double value = mPlot->yAxis().labelInterval();
354 mPlot->yAxis().setLabelInterval( value );
363 double value = mPlot->margins().left();
376 mPlot->setMargins( margins );
385 double value = mPlot->margins().right();
398 mPlot->setMargins( margins );
407 double value = mPlot->margins().top();
420 mPlot->setMargins( margins );
429 double value = mPlot->margins().bottom();
442 mPlot->setMargins( margins );
450 mCacheInvalidated =
true;
466 return blendMode() != QPainter::CompositionMode_SourceOver;
471 return mEvaluatedOpacity < 1.0;
486 return _qgis_listRefToRaw( mLayers );
491 if (
layers == _qgis_listRefToRaw( mLayers ) )
494 mLayers = _qgis_listRawToRef(
layers );
500 if ( mSources.isEmpty() && !mLayers.isEmpty() )
506 QList< QgsAbstractProfileSource * >
sources;
507 const QList<QgsMapLayer *> layersToGenerate =
layers();
508 sources.reserve( layersToGenerate.size() );
525 QList< QgsAbstractProfileSource * >
sources;
526 sources.reserve( mSources.count() );
527 for (
const auto &source : mSources )
529 if (
const QgsMapLayerRef *layerRef = std::get_if< QgsMapLayerRef >( &source ) )
533 sources << layer->profileSource();
536 else if (
auto *profileSource = std::get_if< QgsAbstractProfileSource * >( &source ) )
544 QgsMessageLog::logMessage( tr(
"Could not find profile source with id '%1' in the registry. Skipping..." ).arg( ( *profileSource )->profileSourceId() ) );
555 mSources.reserve(
sources.count() );
557 for (
const auto &source :
sources )
559 if (
auto *layer = std::get_if< QgsMapLayer * >( &source ) )
561 if ( ( *layer )->profileSource() )
566 else if (
auto *profileSource = std::get_if< QgsAbstractProfileSource * >( &source ) )
570 mSources << *profileSource;
574 QgsMessageLog::logMessage( tr(
"Could not find profile source with id '%1' in the registry. Skipping..." ).arg( ( *profileSource )->profileSourceId() ) );
584 mCurve.reset( curve );
623 mAtlasDriven = enabled;
649 if ( !
mLayout || !painter || !painter->device() || !mUpdatesEnabled )
658 QRectF thisPaintRect = rect();
663 calculateAxisRanges( rc );
665 if (
mLayout->renderContext().isPreviewRender() )
670 painter->setClipRect( thisPaintRect );
671 if ( !mCacheFinalImage || mCacheFinalImage->isNull() )
674 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
675 painter->drawRect( thisPaintRect );
676 painter->setBrush( Qt::NoBrush );
678 messageFont.setPointSize( 12 );
679 painter->setFont( messageFont );
680 painter->setPen( QColor( 255, 255, 255, 255 ) );
681 painter->drawText( thisPaintRect, Qt::AlignCenter | Qt::AlignHCenter, tr(
"Rendering profile" ) );
684 ( mRenderJob && mCacheInvalidated && !mDrawingPreview )
685 || ( !mRenderJob && !mDrawingPreview )
689 mBackgroundUpdateTimer->start( 1 );
694 if ( mCacheInvalidated && !mDrawingPreview )
698 mBackgroundUpdateTimer->start( 1 );
703 double imagePixelWidth = mCacheFinalImage->width();
704 double scale = rect().width() / imagePixelWidth;
708 painter->scale( scale, scale );
709 painter->setCompositionMode( blendModeForRender() );
710 painter->drawImage( 0, 0, *mCacheFinalImage );
713 painter->setClipRect( thisPaintRect, Qt::NoClip );
726 QPaintDevice *paintDevice = painter->device();
733 painter->setRenderHint( QPainter::LosslessImageRendering,
true );
740 if ( (
containsAdvancedEffects() || ( blendModeForRender() != QPainter::CompositionMode_SourceOver ) ) && !forceVector )
745 int widthInPixels =
static_cast< int >( std::round( boundingRect().width() * layoutUnitsInInches * destinationDpi ) );
746 int heightInPixels =
static_cast< int >( std::round( boundingRect().height() * layoutUnitsInInches * destinationDpi ) );
747 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
749 image.fill( Qt::transparent );
750 image.setDotsPerMeterX(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
751 image.setDotsPerMeterY(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
752 double dotsPerMM = destinationDpi / 25.4;
753 layoutSize *= dotsPerMM;
754 QPainter p( &image );
755 preparePainter( &p );
760 p.scale( dotsPerMM, dotsPerMM );
766 p.scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
768 const double mapUnitsPerPixel =
static_cast<double>( mPlot->xMaximum() - mPlot->xMinimum() ) * mPlot->xScale / layoutSize.width();
771 QList< QgsAbstractProfileSource *> sourcesToRender =
sources();
772 std::reverse( sourcesToRender.begin(), sourcesToRender.end() );
779 mPlot->setRenderer( &renderer );
782 mPlot->setSize( layoutSize );
785 mPlot->render( rc, plotContext );
787 mPlot->setRenderer(
nullptr );
789 p.scale( dotsPerMM, dotsPerMM );
797 painter->setCompositionMode( blendModeForRender() );
798 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
799 painter->drawImage( 0, 0, image );
800 painter->scale( dotsPerMM, dotsPerMM );
815 double dotsPerMM = paintDevice->logicalDpiX() / 25.4;
816 layoutSize *= dotsPerMM;
817 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
819 const double mapUnitsPerPixel =
static_cast<double>( mPlot->xMaximum() - mPlot->xMinimum() ) * mPlot->xScale / layoutSize.width();
822 QList< QgsAbstractProfileSource *> sourcesToRender =
sources();
823 std::reverse( sourcesToRender.begin(), sourcesToRender.end() );
836 mPlot->setRenderer( &renderer );
839 mPlot->setSize( layoutSize );
842 mPlot->render( rc, plotContext );
844 mPlot->setRenderer(
nullptr );
846 painter->setClipRect( thisPaintRect, Qt::NoClip );
861 if ( mAtlasDriven &&
mLayout &&
mLayout->reportContext().layer() )
872 mCurve.reset( curve->clone() );
886 mCacheInvalidated =
true;
896 QDomElement plotElement = doc.createElement( u
"plot"_s );
897 mPlot->writeXml( plotElement, doc, rwContext );
898 layoutProfileElem.appendChild( plotElement );
903 layoutProfileElem.setAttribute( u
"rangeMethod"_s,
qgsEnumValueToKey( mRangeMethod ) );
907 layoutProfileElem.setAttribute( u
"distanceScale"_s,
qgsDoubleToString( mDistanceScale ) );
911 layoutProfileElem.setAttribute( u
"elevationScale"_s,
qgsDoubleToString( mElevationScale ) );
914 layoutProfileElem.setAttribute( u
"distanceUnit"_s,
qgsEnumValueToKey( mDistanceUnit ) );
916 layoutProfileElem.setAttribute( u
"tolerance"_s, mTolerance );
917 layoutProfileElem.setAttribute( u
"atlasDriven"_s, mAtlasDriven ? u
"1"_s : u
"0"_s );
918 if ( mCrs.isValid() )
920 QDomElement crsElem = doc.createElement( u
"crs"_s );
921 mCrs.writeXml( crsElem, doc );
922 layoutProfileElem.appendChild( crsElem );
926 QDomElement curveElem = doc.createElement( u
"curve"_s );
927 curveElem.appendChild( doc.createTextNode( mCurve->asWkt() ) );
928 layoutProfileElem.appendChild( curveElem );
932 QDomElement layersElement = doc.createElement( u
"layers"_s );
935 QDomElement layerElement = doc.createElement( u
"layer"_s );
936 layer.writeXml( layerElement, rwContext );
937 layersElement.appendChild( layerElement );
939 layoutProfileElem.appendChild( layersElement );
943 QDomElement sourcesElement = doc.createElement( u
"profileSources"_s );
944 for (
const auto &source : mSources )
946 if (
const QgsMapLayerRef *layerRef = std::get_if< QgsMapLayerRef >( &source ) )
948 if ( layerRef->get() )
950 QDomElement sourceElement = doc.createElement( u
"profileLayerSource"_s );
951 layerRef->writeXml( sourceElement, rwContext );
952 sourcesElement.appendChild( sourceElement );
955 else if (
auto *profileSource = std::get_if< QgsAbstractProfileSource * >( &source ) )
959 QDomElement sourceElement = doc.createElement( u
"profileCustomSource"_s );
960 sourceElement.setAttribute( u
"id"_s, ( *profileSource )->profileSourceId() );
961 sourcesElement.appendChild( sourceElement );
965 QgsMessageLog::logMessage( tr(
"Could not find profile source with id '%1' in the registry. Skipping..." ).arg( ( *profileSource )->profileSourceId() ) );
970 layoutProfileElem.appendChild( sourcesElement );
973 if ( mSubsectionsSymbol )
975 QDomElement subsectionsElement = doc.createElement( u
"subsections"_s );
977 subsectionsElement.appendChild( symbolElement );
978 layoutProfileElem.appendChild( subsectionsElement );
986 const QDomElement plotElement = itemElem.firstChildElement( u
"plot"_s );
987 if ( !plotElement.isNull() )
989 mPlot->readXml( plotElement, context );
992 const QDomNodeList crsNodeList = itemElem.elementsByTagName( u
"crs"_s );
994 if ( !crsNodeList.isEmpty() )
996 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
997 crs.readXml( crsElem );
1002 mDistanceScale = itemElem.attribute( u
"distanceScale"_s ).toDouble();
1003 mElevationScale = itemElem.attribute( u
"elevationScale"_s ).toDouble();
1007 const QDomNodeList curveNodeList = itemElem.elementsByTagName( u
"curve"_s );
1008 if ( !curveNodeList.isEmpty() )
1010 const QDomElement curveElem = curveNodeList.at( 0 ).toElement();
1014 mCurve.reset( curveGeom->clone() );
1022 mTolerance = itemElem.attribute( u
"tolerance"_s ).toDouble();
1023 mAtlasDriven =
static_cast< bool >( itemElem.attribute( u
"atlasDriven"_s, u
"0"_s ).toInt() );
1027 const QDomElement layersElement = itemElem.firstChildElement( u
"layers"_s );
1028 QDomElement layerElement = layersElement.firstChildElement( u
"layer"_s );
1029 while ( !layerElement.isNull() )
1032 ref.
readXml( layerElement, context );
1034 mLayers.append( ref );
1036 layerElement = layerElement.nextSiblingElement( u
"layer"_s );
1042 mSources.reserve( itemElem.elementsByTagName( u
"profileSources"_s ).count() );
1043 const QDomElement sourcesElement = itemElem.firstChildElement( u
"profileSources"_s );
1044 QDomElement sourceElement = sourcesElement.firstChildElement();
1045 while ( !sourceElement.isNull() )
1047 if ( sourceElement.tagName() ==
"profileCustomSource"_L1 )
1049 const QString sourceId = sourceElement.attribute( u
"id"_s );
1052 mSources << profileSource;
1056 QgsMessageLog::logMessage( tr(
"Could not find profile source with id '%1' in the registry. Skipping..." ).arg( sourceId ) );
1059 else if ( sourceElement.tagName() ==
"profileLayerSource"_L1 )
1062 ref.
readXml( sourceElement, context );
1070 sourceElement = sourceElement.nextSiblingElement();
1074 const QDomElement subsectionsElement = itemElem.firstChildElement( u
"subsections"_s );
1075 const QDomElement symbolsElement = subsectionsElement.firstChildElement( u
"symbol"_s );
1076 if ( !symbolsElement.isNull() )
1079 if ( subSectionsSymbol )
1088void QgsLayoutItemElevationProfile::recreateCachedImageInBackground()
1094 QPainter *oldPainter = mPainter.release();
1095 QImage *oldImage = mCacheRenderingImage.release();
1097 oldJob->deleteLater();
1105 mCacheRenderingImage.reset(
nullptr );
1109 Q_ASSERT( !mRenderJob );
1110 Q_ASSERT( !mPainter );
1111 Q_ASSERT( !mCacheRenderingImage );
1114 double widthLayoutUnits = layoutSize.width();
1115 double heightLayoutUnits = layoutSize.height();
1117 int w =
static_cast< int >( std::round( widthLayoutUnits * mPreviewScaleFactor ) );
1118 int h =
static_cast< int >( std::round( heightLayoutUnits * mPreviewScaleFactor ) );
1121 if ( w > 5000 || h > 5000 )
1126 h =
static_cast< int>( std::round( w * heightLayoutUnits / widthLayoutUnits ) );
1131 w =
static_cast< int >( std::round( h * widthLayoutUnits / heightLayoutUnits ) );
1135 if ( w <= 0 || h <= 0 )
1138 mCacheRenderingImage = std::make_unique<QImage>( w, h, QImage::Format_ARGB32 );
1141 mCacheRenderingImage->setDotsPerMeterX(
static_cast< int >( std::round( 1000 * w / widthLayoutUnits ) ) );
1142 mCacheRenderingImage->setDotsPerMeterY(
static_cast< int >( std::round( 1000 * h / heightLayoutUnits ) ) );
1145 mCacheRenderingImage->fill( Qt::transparent );
1152 mCacheInvalidated =
false;
1153 mPainter = std::make_unique<QPainter>( mCacheRenderingImage.get() );
1155 QList< QgsAbstractProfileSource *> sourcesToRender =
sources();
1156 std::reverse( sourcesToRender.begin(), sourcesToRender.end() );
1158 mRenderJob = std::make_unique< QgsProfilePlotRenderer >( sourcesToRender,
profileRequest() );
1160 mRenderJob->setSubsectionsSymbol( rendererSubSectionsSymbol.release() );
1162 mRenderJob->startGeneration();
1164 mDrawingPreview =
false;
1167void QgsLayoutItemElevationProfile::profileGenerationFinished()
1169 mPlot->setRenderer( mRenderJob.get() );
1175 const double mapUnitsPerPixel =
static_cast< double >( mPlot->xMaximum() - mPlot->xMinimum() ) * mPlot->xScale / mCacheRenderingImage->size().width();
1179 mPlot->setSize( mCacheRenderingImage->size() );
1181 QgsPlotRenderContext plotContext;
1182 mPlot->render( rc, plotContext );
1184 mPlot->setRenderer(
nullptr );
1187 mRenderJob.reset(
nullptr );
1188 mPainter.reset(
nullptr );
1189 mCacheFinalImage = std::move( mCacheRenderingImage );
1197 return mDistanceUnit;
1202 mDistanceUnit = unit;
1204 switch ( mDistanceUnit )
1258 mPlot->xAxis().setLabelSuffix( QObject::tr(
"°" ) );
1262 mPlot->xAxis().setLabelSuffix( QString() );
1269 mSubsectionsSymbol.reset( symbol );
1272void QgsLayoutItemElevationProfile::setSourcesPrivate()
1280void QgsLayoutItemElevationProfile::calculateAxisRanges(
QgsRenderContext &context )
1285 switch ( mRangeMethod )
1301 mPlot->setSize( layoutSizeMm.
toQSizeF() * mmToPainterUnits );
1303 QgsPlotRenderContext plotContext;
1311 if ( mDistanceScale > 0 )
1313 const double widthMeters = layoutSizeMm.
width() / 1000;
1315 mPlot->setXMinimum( 0 );
1316 mPlot->setXMaximum( distanceRange );
1318 if ( mElevationScale > 0 )
1320 const double heightMeters = layoutSizeMm.
height() / 1000;
1321 const double elevationRange = heightMeters * mElevationScale;
1322 mPlot->setYMaximum( mPlot->yMinimum() + elevationRange );
1326 QRectF previousPlotArea;
1327 for (
int iteration = 0; iteration < 5; ++iteration )
1329 const QRectF currentPlotArea = mPlot->interiorPlotArea( context, plotContext );
1330 if (
qgsDoubleNear( currentPlotArea.width(), previousPlotArea.width(), 1 ) &&
qgsDoubleNear( currentPlotArea.height(), previousPlotArea.height(), 1 ) )
1333 previousPlotArea = currentPlotArea;
1335 if ( mDistanceScale > 0 )
1337 const double widthMm = currentPlotArea.width() / mmToPainterUnits;
1338 const double widthMeters = widthMm / 1000.0;
1340 mPlot->setXMaximum( distanceRange );
1343 if ( mElevationScale > 0 )
1345 const double heightMm = currentPlotArea.height() / mmToPainterUnits;
1346 const double heightMeters = heightMm / 1000.0;
1347 const double elevationRange = heightMeters * mElevationScale;
1348 mPlot->setYMaximum( mPlot->yMinimum() + elevationRange );
1355 return mElevationScale;
1360 mElevationScale = scale;
1365 return mDistanceScale;
1370 mDistanceScale = scale;
1375 return mRangeMethod;
1380 mRangeMethod = method;
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
@ Millimeters
Millimeters.
DistanceUnit
Units of distance.
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated).
@ MilesUSSurvey
US Survey miles.
@ LinksBritishSears1922
British links (Sears 1922).
@ YardsBritishBenoit1895A
British yards (Benoit 1895 A).
@ LinksBritishBenoit1895A
British links (Benoit 1895 A).
@ Centimeters
Centimeters.
@ YardsIndian1975
Indian yards (1975).
@ FeetUSSurvey
US Survey feet.
@ Millimeters
Millimeters.
@ FeetBritishSears1922
British feet (Sears 1922).
@ YardsClarkes
Clarke's yards.
@ YardsIndian
Indian yards.
@ FeetBritishBenoit1895B
British feet (Benoit 1895 B).
@ Miles
Terrestrial miles.
@ LinksUSSurvey
US Survey links.
@ ChainsUSSurvey
US Survey chains.
@ FeetClarkes
Clarke's feet.
@ Unknown
Unknown distance unit.
@ FeetBritish1936
British feet (1936).
@ FeetIndian1962
Indian feet (1962).
@ YardsBritishSears1922
British yards (Sears 1922).
@ FeetIndian1937
Indian feet (1937).
@ YardsIndian1937
Indian yards (1937).
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ ChainsBritishBenoit1895B
British chains (Benoit 1895 B).
@ LinksBritishSears1922Truncated
British links (Sears 1922 truncated).
@ ChainsBritishBenoit1895A
British chains (Benoit 1895 A).
@ YardsBritishBenoit1895B
British yards (Benoit 1895 B).
@ FeetBritish1865
British feet (1865).
@ YardsIndian1962
Indian yards (1962).
@ FeetBritishSears1922Truncated
British feet (Sears 1922 truncated).
@ MetersGermanLegal
German legal meter.
@ LinksBritishBenoit1895B
British links (Benoit 1895 B).
@ ChainsInternational
International chains.
@ LinksInternational
International links.
@ ChainsBritishSears1922Truncated
British chains (Sears 1922 truncated).
@ FeetIndian
Indian (geodetic) feet.
@ NauticalMiles
Nautical miles.
@ ChainsClarkes
Clarke's chains.
@ LinksClarkes
Clarke's links.
@ ChainsBritishSears1922
British chains (Sears 1922).
@ FeetIndian1975
Indian feet (1975).
@ FeetGoldCoast
Gold Coast feet.
@ FeetBritishBenoit1895A
British feet (Benoit 1895 A).
@ Millimeters
Millimeters.
ElevationProfileRangeMethod
Elevation profile range calculation methods.
@ ManualRange
Distance/elevation ranges are manually set.
@ FixedScale
Distance and elevation ranges are calculated from fixed scales.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
virtual void renderContent(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QRectF &plotArea, const QgsPlotData &plotData=QgsPlotData())
Renders the plot content.
Base class for 2-dimensional plot/chart/graphs with an X and Y axes.
double yMaximum() const
Returns the maximum value of the y axis.
double xMinimum() const
Returns the minimum value of the x axis.
double yMinimum() const
Returns the minimum value of the y axis.
double xMaximum() const
Returns the maximum value of the x axis.
Abstract base class for all geometries.
Interface for classes which can generate elevation profiles.
Abstract base class for terrain providers.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsProfileSourceRegistry * profileSourceRegistry()
Returns registry of available profile source implementations.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
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...
void setElevationScale(double scale)
Sets the denominator of the elevation scale.
QgsLayoutItemElevationProfile(QgsLayout *layout)
Constructor for QgsLayoutItemElevationProfile, with the specified parent layout.
Qgis::ElevationProfileRangeMethod rangeMethod() const
Returns the method used to determine the elevation/distance ranges on the profile.
~QgsLayoutItemElevationProfile() override
QgsCurve * profileCurve() const
Returns the cross section profile curve, which represents the line along which the profile should be ...
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of map layers participating in the elevation profile.
void setSubsectionsSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the subsections.
QList< QgsMapLayer * > layers() const
Returns the list of map layers participating in the elevation profile.
void invalidateCache() override
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.
double distanceScale() const
Returns the denominator of the distance scale.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void setDistanceScale(double scale)
Sets the denominator of the distance scale.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
QList< QgsAbstractProfileSource * > sources() const
Returns the list of sources participating in the elevation profile.
void setRangeMethod(Qgis::ElevationProfileRangeMethod method)
Sets the method used to determine the elevation/distance ranges on the profile.
void setDistanceUnit(Qgis::DistanceUnit unit)
Sets the unit for the distance axis.
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.
void setAtlasDriven(bool enabled)
Sets whether the profile curve will follow the current atlas feature.
double tolerance() const
Returns the tolerance of the request (in crs() units).
QgsLineSymbol * subsectionsSymbol()
Returns the symbol used to draw the subsections.
Qgis::DistanceUnit distanceUnit() const
Returns the units for the distance axis.
bool requiresRasterization() const override
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
bool containsAdvancedEffects() const override
Returns true if the item contains contents with blend modes or transparency effects which can only be...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
double elevationScale() const
Returns the denominator of the elevation scale.
QIcon icon() const override
Returns the item's icon.
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...
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
QgsProfileRequest profileRequest() const
Returns the profile request used to generate the elevation profile.
int type() const override
@ LayoutElevationProfile
Elevation profile item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
QColor backgroundColor(bool useDataDefined=true) const
Returns the background color for this item.
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...
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
@ FlagOverridesPaint
Item overrides the default layout item painting method.
@ FlagDisableSceneCaching
Item should not have QGraphicsItem caching enabled.
void sizePositionChanged()
Emitted when the item's size or position changes.
bool frameEnabled() const
Returns true if the item includes a frame.
bool hasBackground() const
Returns true if the item has a background.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
friend class QgsLayoutItemElevationProfile
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
void backgroundTaskCountChanged(int count)
Emitted whenever the number of background tasks an item is executing changes.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
@ ElevationProfileMaximumDistance
Maximum distance value for elevation profile.
@ MarginBottom
Bottom margin.
@ ElevationProfileElevationMinorInterval
Minor grid line interval for elevation profile elevation axis.
@ ElevationProfileDistanceMinorInterval
Minor grid line interval for elevation profile distance axis.
@ ElevationProfileMinimumDistance
Minimum distance value for elevation profile.
@ ElevationProfileMaximumElevation
Maximum elevation value for elevation profile.
@ ElevationProfileDistanceLabelInterval
Label interval for elevation profile distance axis.
@ ElevationProfileTolerance
Tolerance distance for elevation profiles.
@ ElevationProfileMinimumElevation
Minimum elevation value for elevation profile.
@ MarginRight
Right margin.
@ ElevationProfileElevationLabelInterval
Label interval for elevation profile elevation axis.
@ ElevationProfileDistanceMajorInterval
Major grid line interval for elevation profile distance axis.
@ ElevationProfileElevationMajorInterval
Major grid line interval for elevation profile elevation axis.
@ AllProperties
All properties for item.
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
static Q_DECL_DEPRECATED double scaleFactorFromItemStyle(const QStyleOptionGraphicsItem *style)
Extracts the scale factor from an item style.
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated.
A line symbol type, for rendering LineString and MultiLineString geometries.
Base class for all map layer types.
Perform transforms between map coordinates and device coordinates.
Defines the four margins of a rectangle.
void setBottom(double bottom)
Sets the bottom margin to bottom.
void setLeft(double left)
Sets the left margin to left.
void setRight(double right)
Sets the right margin to right.
void setTop(double top)
Sets the top margin to top.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Encapsulates one or more plot series.
Contains information about the context of a plot rendering operation.
Generates and renders elevation profile plots.
void setSubsectionsSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the subsections.
void cancelGenerationWithoutBlocking()
Triggers cancellation of the generation job without blocking.
void generateSynchronously()
Generate the profile results synchronously in this thread.
void generationFinished()
Emitted when the profile generation is finished (or canceled).
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
QgsProfileRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate expressions.
QgsProfileRequest & setTransformContext(const QgsCoordinateTransformContext &context)
Sets the transform context, for use when transforming coordinates from a source to the request's crs(...
QgsProfileRequest & setTerrainProvider(QgsAbstractTerrainProvider *provider)
Sets the terrain provider.
QgsProfileRequest & setTolerance(double tolerance)
Sets the tolerance of the request (in crs() units).
QgsProfileRequest & setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the desired Coordinate Reference System (crs) for the profile.
void profileSourceUnregistered(const QString &sourceId)
Signal emitted once a profile source is unregistered.
void profileSourceRegistered(const QString &sourceId, const QString &sourceName)
Signal emitted once a profile source is registered.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Scoped object for saving and restoring a QPainter object's state.
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
Represents a vector layer which manages a vector based dataset.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
_LayerRef< QgsMapLayer > QgsMapLayerRef
TYPE * resolveWeakly(const QgsProject *project, MatchType matchType=MatchType::All)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the layer's properties from an XML element.