62 mRect = mCanvas->rect();
65 prepareGeometryChange();
66 setPos( mRect.topLeft() );
69 mCachedImages.clear();
77 mCachedImages.clear();
82 bool redrawResults(
const QString &sourceId )
84 auto it = mCachedImages.find( sourceId );
85 if ( it == mCachedImages.end() )
88 mCachedImages.erase( it );
93 QRectF boundingRect()
const override
100 if ( !mPlotArea.isNull() )
105 if ( !scene()->views().isEmpty() )
106 context.
setScaleFactor( scene()->views().at( 0 )->logicalDpiX() / 25.4 );
115 const QRectF area = plotArea();
116 if ( !area.contains( point.x(), point.y() ) )
129 const QRectF area = plotArea();
138 mPlotArea = plotArea;
143 const QStringList sourceIds = mRenderer->sourceIds();
144 for (
const QString &source : sourceIds )
147 auto it = mCachedImages.constFind( source );
148 if ( it != mCachedImages.constEnd() )
154 plot = mRenderer->renderToImage( plotArea.width(), plotArea.height(), xMinimum(),
xMaximum(),
yMinimum(),
yMaximum(), source );
155 mCachedImages.insert( source, plot );
157 rc.
painter()->drawImage( plotArea.left(), plotArea.top(), plot );
161 void paint( QPainter *painter )
override
164 if ( !mImage.isNull() )
166 painter->drawImage( 0, 0, mImage );
170 mImage = QImage( mRect.width(), mRect.height(), QImage::Format_ARGB32_Premultiplied );
171 mImage.fill( Qt::transparent );
173 QPainter imagePainter( &mImage );
174 imagePainter.setRenderHint( QPainter::Antialiasing,
true );
184 painter->drawImage( 0, 0, mImage );
194 QMap< QString, QImage > mCachedImages;
207 , mPlotItem( plotItem )
213 mRect = mCanvas->rect();
215 prepareGeometryChange();
216 setPos( mRect.topLeft() );
226 QRectF boundingRect()
const override
231 void paint( QPainter *painter )
override
233 const QgsPointXY crossHairPlotPoint = mPlotItem->plotPointToCanvasPoint( mPoint );
234 if ( crossHairPlotPoint.
isEmpty() )
238 painter->setBrush( Qt::NoBrush );
240 crossHairPen.setCosmetic(
true );
241 crossHairPen.setWidthF( 1 );
242 crossHairPen.setStyle( Qt::DashLine );
243 crossHairPen.setCapStyle( Qt::FlatCap );
244 crossHairPen.setColor( QColor( 0, 0, 0, 150 ) );
245 painter->setPen( crossHairPen );
246 painter->drawLine( QPointF( mPlotItem->plotArea().left(), crossHairPlotPoint.
y() ), QPointF( mPlotItem->plotArea().right(), crossHairPlotPoint.
y() ) );
247 painter->drawLine( QPointF( crossHairPlotPoint.
x(), mPlotItem->plotArea().top() ), QPointF( crossHairPlotPoint.
x(), mPlotItem->plotArea().bottom() ) );
252 const QString xCoordinateText = mPlotItem->xAxis().numericFormat()->formatDouble( mPoint.distance(), numericContext );
253 const QString yCoordinateText = mPlotItem->yAxis().numericFormat()->formatDouble( mPoint.elevation(), numericContext );
256 const QFontMetrics fm( font );
257 const double height = fm.capHeight();
258 const double xWidth = fm.horizontalAdvance( xCoordinateText );
259 const double yWidth = fm.horizontalAdvance( yCoordinateText );
260 const double textAxisMargin = fm.horizontalAdvance(
' ' );
262 QPointF xCoordOrigin;
263 QPointF yCoordOrigin;
265 if ( mPoint.distance() < ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5 )
267 if ( mPoint.elevation() < ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5 )
270 xCoordOrigin = QPointF( crossHairPlotPoint.
x() + textAxisMargin, mPlotItem->plotArea().top() + height + textAxisMargin );
272 yCoordOrigin = QPointF( mPlotItem->plotArea().right() - yWidth - textAxisMargin, crossHairPlotPoint.
y() - textAxisMargin );
277 xCoordOrigin = QPointF( crossHairPlotPoint.
x() + textAxisMargin, mPlotItem->plotArea().bottom() - textAxisMargin );
279 yCoordOrigin = QPointF( mPlotItem->plotArea().right() - yWidth - textAxisMargin, crossHairPlotPoint.
y() + height + textAxisMargin );
284 if ( mPoint.elevation() < ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5 )
287 xCoordOrigin = QPointF( crossHairPlotPoint.
x() - xWidth - textAxisMargin, mPlotItem->plotArea().top() + height + textAxisMargin );
289 yCoordOrigin = QPointF( mPlotItem->plotArea().left() + textAxisMargin, crossHairPlotPoint.
y() - textAxisMargin );
294 xCoordOrigin = QPointF( crossHairPlotPoint.
x() - xWidth - textAxisMargin, mPlotItem->plotArea().bottom() - textAxisMargin );
296 yCoordOrigin = QPointF( mPlotItem->plotArea().left() + textAxisMargin, crossHairPlotPoint.
y() + height + textAxisMargin );
301 painter->setBrush( QBrush( QColor( 255, 255, 255, 220 ) ) );
302 painter->setPen( Qt::NoPen );
303 painter->drawRect( QRectF( xCoordOrigin.x() - textAxisMargin + 1, xCoordOrigin.y() - textAxisMargin - height + 1, xWidth + 2 * textAxisMargin - 2, height + 2 * textAxisMargin - 2 ) );
304 painter->drawRect( QRectF( yCoordOrigin.x() - textAxisMargin + 1, yCoordOrigin.y() - textAxisMargin - height + 1, yWidth + 2 * textAxisMargin - 2, height + 2 * textAxisMargin - 2 ) );
306 painter->setBrush( Qt::NoBrush );
307 painter->setPen( Qt::black );
309 painter->drawText( xCoordOrigin, xCoordinateText );
310 painter->drawText( yCoordOrigin, yCoordinateText );
318 QgsElevationProfilePlotItem *mPlotItem =
nullptr;
328 mPlotItem =
new QgsElevationProfilePlotItem(
this );
329 mCrossHairsItem =
new QgsElevationProfileCrossHairsItem(
this, mPlotItem );
330 mCrossHairsItem->setZValue( 100 );
331 mCrossHairsItem->hide();
334 mDeferredRegenerationTimer =
new QTimer(
this );
335 mDeferredRegenerationTimer->setSingleShot(
true );
336 mDeferredRegenerationTimer->stop();
337 connect( mDeferredRegenerationTimer, &QTimer::timeout,
this, &QgsElevationProfileCanvas::startDeferredRegeneration );
339 mDeferredRedrawTimer =
new QTimer(
this );
340 mDeferredRedrawTimer->setSingleShot(
true );
341 mDeferredRedrawTimer->stop();
342 connect( mDeferredRedrawTimer, &QTimer::timeout,
this, &QgsElevationProfileCanvas::startDeferredRedraw );
350 mPlotItem->setRenderer(
nullptr );
351 mCurrentJob->deleteLater();
352 mCurrentJob =
nullptr;
360 mPlotItem->setRenderer(
nullptr );
363 mCurrentJob->deleteLater();
364 mCurrentJob =
nullptr;
370 const double dxPercent = dx / mPlotItem->plotArea().width();
371 const double dyPercent = dy / mPlotItem->plotArea().height();
374 const double dxPlot = - dxPercent * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() );
375 const double dyPlot = dyPercent * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
377 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
378 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
379 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
380 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
384 mPlotItem->updatePlot();
390 if ( !mPlotItem->plotArea().contains( x, y ) )
393 const double newCenterX = mPlotItem->xMinimum() + ( x - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() );
394 const double newCenterY = mPlotItem->yMinimum() + ( mPlotItem->plotArea().bottom() - y ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
396 const double dxPlot = newCenterX - ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5;
397 const double dyPlot = newCenterY - ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5;
399 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
400 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
401 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
402 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
406 mPlotItem->updatePlot();
418 const double toleranceInPixels = QFontMetrics( font() ).horizontalAdvance(
' ' );
419 const double xToleranceInPlotUnits = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) / ( mPlotItem->plotArea().width() ) * toleranceInPixels;
420 const double yToleranceInPlotUnits = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * toleranceInPixels;
428 / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) / ( mPlotItem->plotArea().width() ) );
435 const double toleranceInPixels = QFontMetrics( font() ).horizontalAdvance(
' ' );
436 const double xToleranceInPlotUnits = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) / ( mPlotItem->plotArea().width() ) * toleranceInPixels;
437 const double yToleranceInPlotUnits = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * toleranceInPixels;
445 / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) / ( mPlotItem->plotArea().width() ) );
452void QgsElevationProfileCanvas::setupLayerConnections(
QgsMapLayer *layer,
bool isDisconnect )
467 switch ( layer->
type() )
501 if ( !mCurrentJob || !mSnappingEnabled )
515 const double currentWidth = mPlotItem->xMaximum() - mPlotItem->xMinimum();
516 const double currentHeight = mPlotItem->yMaximum() - mPlotItem->yMinimum();
518 const double newWidth = currentWidth / xFactor;
519 const double newHeight = currentHeight / yFactor;
521 const double currentCenterX = ( mPlotItem->xMinimum() + mPlotItem->xMaximum() ) * 0.5;
522 const double currentCenterY = ( mPlotItem->yMinimum() + mPlotItem->yMaximum() ) * 0.5;
524 mPlotItem->setXMinimum( currentCenterX - newWidth * 0.5 );
525 mPlotItem->setXMaximum( currentCenterX + newWidth * 0.5 );
526 mPlotItem->setYMinimum( currentCenterY - newHeight * 0.5 );
527 mPlotItem->setYMaximum( currentCenterY + newHeight * 0.5 );
530 mPlotItem->updatePlot();
536 const QRectF intersected = rect.intersected( mPlotItem->plotArea() );
538 const double minX = ( intersected.left() - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) + mPlotItem->xMinimum();
539 const double maxX = ( intersected.right() - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) + mPlotItem->xMinimum();
540 const double minY = ( mPlotItem->plotArea().bottom() - intersected.bottom() ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
541 const double maxY = ( mPlotItem->plotArea().bottom() - intersected.top() ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
543 mPlotItem->setXMinimum( minX );
544 mPlotItem->setXMaximum( maxX );
545 mPlotItem->setYMinimum( minY );
546 mPlotItem->setYMaximum( maxY );
549 mPlotItem->updatePlot();
557 double zoomFactor = settings.
value( QStringLiteral(
"qgis/zoom_factor" ), 2 ).toDouble();
560 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * std::fabs(
event->angleDelta().y() );
562 if (
event->modifiers() & Qt::ControlModifier )
565 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 20.0;
569 bool zoomIn =
event->angleDelta().y() > 0;
570 double scaleFactor = ( zoomIn ? 1 / zoomFactor : zoomFactor );
572 QRectF viewportRect = mPlotItem->plotArea();
574 if ( viewportRect.contains(
event->position() ) )
577 const double oldCenterX = 0.5 * ( mPlotItem->xMaximum() + mPlotItem->xMinimum() );
578 const double oldCenterY = 0.5 * ( mPlotItem->yMaximum() + mPlotItem->yMinimum() );
580 const double eventPosX = (
event->position().x() - viewportRect.left() ) / viewportRect.width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) + mPlotItem->xMinimum();
581 const double eventPosY = ( viewportRect.bottom() -
event->position().y() ) / viewportRect.height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
583 const double newCenterX = eventPosX + ( ( oldCenterX - eventPosX ) * scaleFactor );
584 const double newCenterY = eventPosY + ( ( oldCenterY - eventPosY ) * scaleFactor );
586 const double dxPlot = newCenterX - ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5;
587 const double dyPlot = newCenterY - ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5;
589 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
590 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
591 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
592 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
610 if ( e->isAccepted() )
612 mCrossHairsItem->hide();
617 if ( mCurrentJob && mSnappingEnabled && !plotPoint.
isEmpty() )
626 mCrossHairsItem->hide();
630 mCrossHairsItem->setPoint( plotPoint );
631 mCrossHairsItem->show();
638 return mPlotItem->plotArea();
648 mPlotItem->setRenderer(
nullptr );
650 mCurrentJob->deleteLater();
651 mCurrentJob =
nullptr;
664 const QList< QgsMapLayer * > layersToGenerate =
layers();
665 QList< QgsAbstractProfileSource * > sources;
666 sources.reserve( layersToGenerate .size() );
670 sources.append( source );
678 generationContext.
setMaximumErrorMapUnits( MAX_ERROR_PIXELS * ( mProfileCurve->length() ) / mPlotItem->plotArea().width() );
683 mPlotItem->setRenderer( mCurrentJob );
690 mZoomFullWhenJobFinished =
true;
693void QgsElevationProfileCanvas::generationFinished()
700 if ( mZoomFullWhenJobFinished )
703 mZoomFullWhenJobFinished =
false;
712 mPlotItem->updatePlot();
715 if ( mForceRegenerationAfterCurrentJobCompletes )
717 mForceRegenerationAfterCurrentJobCompletes =
false;
719 scheduleDeferredRegeneration();
723void QgsElevationProfileCanvas::onLayerProfileGenerationPropertyChanged()
726 if ( !mCurrentJob || mCurrentJob->
isActive() )
733 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( properties->parent() ) )
738 scheduleDeferredRegeneration();
743void QgsElevationProfileCanvas::onLayerProfileRendererPropertyChanged()
746 if ( !mCurrentJob || mCurrentJob->
isActive() )
753 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( properties->parent() ) )
759 if ( mPlotItem->redrawResults( layer->
id() ) )
760 scheduleDeferredRedraw();
764void QgsElevationProfileCanvas::regenerateResultsForLayer()
766 if (
QgsMapLayer *layer = qobject_cast< QgsMapLayer * >( sender() ) )
771 scheduleDeferredRegeneration();
776void QgsElevationProfileCanvas::scheduleDeferredRegeneration()
778 if ( !mDeferredRegenerationScheduled )
780 mDeferredRegenerationTimer->start( 1 );
781 mDeferredRegenerationScheduled =
true;
785void QgsElevationProfileCanvas::scheduleDeferredRedraw()
787 if ( !mDeferredRedrawScheduled )
789 mDeferredRedrawTimer->start( 1 );
790 mDeferredRedrawScheduled =
true;
794void QgsElevationProfileCanvas::startDeferredRegeneration()
796 if ( mCurrentJob && !mCurrentJob->
isActive() )
801 else if ( mCurrentJob )
803 mForceRegenerationAfterCurrentJobCompletes =
true;
806 mDeferredRegenerationScheduled =
false;
809void QgsElevationProfileCanvas::startDeferredRedraw()
812 mDeferredRedrawScheduled =
false;
815void QgsElevationProfileCanvas::refineResults()
821 const double plotDistanceRange = mPlotItem->xMaximum() - mPlotItem->xMinimum();
822 const double plotElevationRange = mPlotItem->yMaximum() - mPlotItem->yMinimum();
823 const double plotDistanceUnitsPerPixel = plotDistanceRange / mPlotItem->plotArea().width();
827 const double targetMaxErrorInMapUnits = MAX_ERROR_PIXELS * plotDistanceUnitsPerPixel;
828 const double factor = std::pow( 10.0, 1 - std::ceil( std::log10( std::fabs( targetMaxErrorInMapUnits ) ) ) );
829 const double roundedErrorInMapUnits = std::floor( targetMaxErrorInMapUnits * factor ) / factor;
837 mPlotItem->xMaximum() + plotDistanceRange * 0.05 ) );
840 mPlotItem->yMaximum() + plotElevationRange * 0.05 ) );
843 scheduleDeferredRegeneration();
848 if ( !mPlotItem->plotArea().contains( point.x(), point.y() ) )
851 return mPlotItem->canvasPointToPlotPoint( point );
856 return mPlotItem->plotPointToCanvasPoint( point );
862 mPlotItem->mProject = project;
872 mProfileCurve.reset( curve );
877 return mProfileCurve.get();
892 for (
QgsMapLayer *layer : std::as_const( mLayers ) )
894 setupLayerConnections( layer,
true );
898 auto filteredList =
layers;
899 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
902 return !layer || !layer->isValid();
903 } ), filteredList.end() );
905 mLayers = _qgis_listRawToQPointer( filteredList );
906 for (
QgsMapLayer *layer : std::as_const( mLayers ) )
908 setupLayerConnections( layer,
false );
914 return _qgis_listQPointerToRaw( mLayers );
920 mPlotItem->updateRect();
921 mCrossHairsItem->updateRect();
926 QgsPlotCanvas::paintEvent(
event );
928 if ( !mFirstDrawOccurred )
931 mFirstDrawOccurred =
true;
932 mPlotItem->updateRect();
933 mCrossHairsItem->updateRect();
939 if ( !mPlotItem->plotArea().contains( point.
x(), point.
y() ) )
942 if ( !mProfileCurve )
945 const double dx = point.
x() - mPlotItem->plotArea().left();
947 const double distanceAlongPlotPercent = dx / mPlotItem->plotArea().width();
948 double distanceAlongCurveLength = distanceAlongPlotPercent * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) + mPlotItem->xMinimum();
950 std::unique_ptr< QgsPoint > mapXyPoint( mProfileCurve->interpolatePoint( distanceAlongCurveLength ) );
954 const double mapZ = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * ( mPlotItem->plotArea().bottom() - point.
y() ) + mPlotItem->yMinimum();
956 return QgsPoint( mapXyPoint->x(), mapXyPoint->y(), mapZ );
961 if ( !mProfileCurve )
966 const double distanceAlongCurve =
geos.lineLocatePoint( point, &error );
968 const double distanceAlongCurveOnPlot = distanceAlongCurve - mPlotItem->xMinimum();
969 const double distanceAlongCurvePercent = distanceAlongCurveOnPlot / ( mPlotItem->xMaximum() - mPlotItem->xMinimum() );
970 const double distanceAlongPlotRect = distanceAlongCurvePercent * mPlotItem->plotArea().width();
972 const double canvasX = mPlotItem->plotArea().left() + distanceAlongPlotRect;
975 if ( std::isnan( point.
z() ) || point.
z() < mPlotItem->yMinimum() )
977 canvasY = mPlotItem->plotArea().top();
979 else if ( point.
z() > mPlotItem->yMaximum() )
981 canvasY = mPlotItem->plotArea().bottom();
985 const double yPercent = ( point.
z() - mPlotItem->yMinimum() ) / ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
986 canvasY = mPlotItem->plotArea().bottom() - mPlotItem->plotArea().height() * yPercent;
1002 mPlotItem->setYMinimum( 0 );
1003 mPlotItem->setYMaximum( 10 );
1008 mPlotItem->setYMinimum( zRange.
lower() - 5 );
1009 mPlotItem->setYMaximum( zRange.
lower() + 5 );
1014 const double margin = ( zRange.
upper() - zRange.
lower() ) * 0.05;
1015 mPlotItem->setYMinimum( zRange.
lower() - margin );
1016 mPlotItem->setYMaximum( zRange.
upper() + margin );
1020 mPlotItem->setXMinimum( 0 );
1022 mPlotItem->setXMaximum( profileLength * 1.02 );
1025 mPlotItem->updatePlot();
1031 mPlotItem->setYMinimum( minimumElevation );
1032 mPlotItem->setYMaximum( maximumElevation );
1033 mPlotItem->setXMinimum( minimumDistance );
1034 mPlotItem->setXMaximum( maximumDistance );
1036 mPlotItem->updatePlot();
1042 return QgsDoubleRange( mPlotItem->xMinimum(), mPlotItem->xMaximum() );
1047 return QgsDoubleRange( mPlotItem->yMinimum(), mPlotItem->yMaximum() );
1056class QgsElevationProfilePlot :
public Qgs2DPlot
1061 : mRenderer( renderer )
1070 rc.
painter()->translate( plotArea.left(), plotArea.top() );
1072 rc.
painter()->translate( -plotArea.left(), -plotArea.top() );
1089 QgsElevationProfilePlot profilePlot( mCurrentJob );
1093 QDomElement elem = doc.createElement( QStringLiteral(
"plot" ) );
1095 plotSettings.
writeXml( elem, doc, rwContext );
1096 profilePlot.readXml( elem, rwContext );
1098 profilePlot.setSize( QSizeF( width, height ) );
1099 profilePlot.render( context );
1109 return mCurrentJob->
identify( plotPoint, identifyContext() );
1120 double distance1 = topLeftPlotPoint.
distance();
1121 double distance2 = bottomRightPlotPoint.
distance();
1122 if ( distance2 < distance1 )
1123 std::swap( distance1, distance2 );
1125 double elevation1 = topLeftPlotPoint.
elevation();
1126 double elevation2 = bottomRightPlotPoint.
elevation();
1127 if ( elevation2 < elevation1 )
1128 std::swap( elevation1, elevation2 );
1136 mPlotItem->setRenderer(
nullptr );
1137 mPlotItem->updatePlot();
1142 mSnappingEnabled = enabled;
Base class for 2-dimensional plot/chart/graphs.
void calculateOptimisedIntervals(QgsRenderContext &context)
Automatically sets the grid and label intervals to optimal values for display in the given render con...
double yMaximum() const
Returns the maximum value of the y axis.
void setSize(QSizeF size)
Sets the overall size of the plot (including titles and over components which sit outside the plot ar...
double xMaximum() const
Returns the maximum value of the x axis.
void render(QgsRenderContext &context)
Renders the plot.
void setYMaximum(double maximum)
Sets 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.
QRectF interiorPlotArea(QgsRenderContext &context) const
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
virtual void renderContent(QgsRenderContext &context, const QRectF &plotArea)
Renders the plot content.
bool writeXml(QDomElement &element, QDomDocument &document, QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
Interface for classes which can generate elevation profiles.
virtual QgsAbstractTerrainProvider * clone() const =0
Creates a clone of the provider and returns the new object.
This class represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
QgsRange which stores a range of double values.
A canvas for elevation profiles.
QgsDoubleRange visibleElevationRange() const
Returns the elevation range currently visible in the plot.
QgsCurve * profileCurve() const
Returns the profile curve.
void setTolerance(double tolerance)
Sets the profile tolerance (in crs() units).
void setProfileCurve(QgsCurve *curve)
Sets the profile curve.
void zoomToRect(const QRectF &rect) override
Zooms the plot to the specified rect in canvas units.
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 scalePlot(double factor) override
Scales the plot by a specified scale factor.
void paintEvent(QPaintEvent *event) override
QgsDoubleRange visibleDistanceRange() const
Returns the distance range currently visible in the plot.
void cancelJobs() override
Cancel any rendering job, in a blocking way.
QgsCoordinateReferenceSystem crs() const override
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
void clear()
Clears the current profile.
QgsProfilePoint canvasPointToPlotPoint(QPointF point) const
Converts a canvas point to the equivalent plot point.
QgsPointXY plotPointToCanvasPoint(const QgsProfilePoint &point) const
Converts a plot point to the equivalent canvas point.
QgsPoint toMapCoordinates(const QgsPointXY &point) const override
Converts a point on the canvas to the associated map coordinate.
void setVisiblePlotRange(double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation)
Sets the visible area of the plot.
void canvasPointHovered(const QgsPointXY &point, const QgsProfilePoint &profilePoint)
Emitted when the mouse hovers over the specified point (in canvas coordinates).
void render(QgsRenderContext &context, double width, double height, const Qgs2DPlot &plotSettings)
Renders a portion of the profile using the specified render context.
QgsPointXY snapToPlot(QPoint point) override
Snap a canvas point to the plot.
void setProject(QgsProject *project)
Sets the project associated with the profile.
QList< QgsMapLayer * > layers() const
Returns the list of layers included in the profile.
void resizeEvent(QResizeEvent *event) override
void centerPlotOn(double x, double y) override
Centers the plot on the plot point corresponding to x, y in canvas units.
const Qgs2DPlot & plot() const
Returns a reference to the 2D plot used by the widget.
void wheelZoom(QWheelEvent *event) override
Zoom plot from a mouse wheel event.
void refresh() override
Triggers a complete regeneration of the profile, causing the profile extraction to perform in the bac...
double tolerance() const
Returns the tolerance of the profile (in crs() units).
void mouseMoveEvent(QMouseEvent *e) override
void panContentsBy(double dx, double dy) override
Pans the plot contents by dx, dy in canvas units.
void invalidateCurrentPlotExtent()
Invalidates the current plot extent, which means that the visible plot area will be recalculated and ...
QgsPointXY toCanvasCoordinates(const QgsPoint &point) const override
Converts a point in map coordinates to the associated canvas point.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs associated with the canvas' map coordinates.
~QgsElevationProfileCanvas() override
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 setSnappingEnabled(bool enabled)
Sets whether snapping of cursor points is enabled.
QVector< QgsProfileIdentifyResults > identify(QPointF point)
Identify results visible at the specified plot point.
QRectF plotArea() const
Returns the interior rectangle representing the surface of the plot, in canvas coordinates.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Does vector analysis using the geos library and handles import, export, exception handling*.
Base class for storage of map layer elevation properties.
void profileGenerationPropertyChanged()
Emitted when any of the elevation properties which relate solely to generation of elevation profiles ...
void profileRenderingPropertyChanged()
Emitted when any of the elevation properties which relate solely to presentation of elevation results...
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
void dataChanged()
Data of layer changed.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
A context for numeric formats.
An abstract class for items that can be placed on a QgsPlotCanvas.
virtual void paint(QPainter *painter)=0
Paints the item.
Plot canvas is a class for displaying interactive 2d charts and plots.
bool event(QEvent *e) override
void plotAreaChanged()
Emitted whenever the visible area of the plot is changed.
void mouseMoveEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
A class to represent a 2D point.
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
Point geometry type, with support for z-dimension and m-values.
Encapsulates the context in which an elevation profile is to be generated.
double maximumErrorMapUnits() const
Returns the maximum allowed error in the generated result, in profile curve map units.
void setDpi(double dpi)
Sets the dpi (dots per inch) for the profie, to be used in size conversions.
void setMaximumErrorMapUnits(double error)
Sets the maximum allowed error in the generated result, in profile curve map units.
void setDistanceRange(const QgsDoubleRange &range)
Sets the range of distances to include in the generation.
void setElevationRange(const QgsDoubleRange &range)
Sets the range of elevations to include in the generation.
void setMapUnitsPerDistancePixel(double units)
Sets the number of map units per pixel in the distance dimension.
Encapsulates the context of identifying profile results.
double maximumPointElevationDelta
Maximum allowed snapping delta for the elevation values when identifying a point.
double maximumPointDistanceDelta
Maximum allowed snapping delta for the distance values when identifying a point.
QgsProject * project
Associated project.
double displayRatioElevationVsDistance
Display ratio of elevation vs distance units.
double maximumSurfaceDistanceDelta
Maximum allowed snapping delta for the distance values when identifying a continuous elevation surfac...
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when identifying a continuous elevation surfa...
Generates and renders elevation profile plots.
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context)
Snap a point to the results.
void regenerateInvalidatedResults()
Starts a background regeneration of any invalidated results and immediately returns.
void invalidateAllRefinableSources()
Invalidates previous results from all refinable sources.
void cancelGeneration()
Stop the generation job - does not return until the job has terminated.
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.
bool isActive() const
Returns true if the generation job is currently running in background.
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).
Encapsulates a point on a distance-elevation profile.
double elevation() const SIP_HOLDGIL
Returns the elevation of the point.
bool isEmpty() const SIP_HOLDGIL
Returns true if the point is empty.
double distance() const SIP_HOLDGIL
Returns the distance of the point.
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.
Encapsulates the context of snapping a profile point.
double maximumPointDistanceDelta
Maximum allowed snapping delta for the distance values when snapping to a point.
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a continuous elevation surfa...
double maximumPointElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a point.
double maximumSurfaceDistanceDelta
Maximum allowed snapping delta for the distance values when snapping to a continuous elevation surfac...
double displayRatioElevationVsDistance
Display ratio of elevation vs distance units.
Encapsulates results of snapping a profile point.
bool isValid() const
Returns true if the result is a valid point.
QgsProfilePoint snappedPoint
Snapped point.
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
const QgsProjectElevationProperties * elevationProperties() const
Returns the project's elevation properties, which contains the project's elevation related settings.
QgsCoordinateTransformContext transformContext
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
A utility class for dynamic handling of changes to screen properties.
double screenDpi() const
Returns the current screen DPI for the screen that the parent widget appears on.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Represents a vector layer which manages a vector based data sets.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted whenever an attribute value change is done in the edit buffer.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted.
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geometry)
Emitted whenever a geometry change is done in the edit buffer.
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
Contains geos related utilities and functions.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsCoordinateReferenceSystem & crs