46#include "moc_qgselevationprofilecanvas.cpp"
52 QgsElevationProfilePlotItem( QgsElevationProfileCanvas *canvas )
53 : QgsPlotCanvasItem( canvas )
61 void setRenderer( QgsProfilePlotRenderer *renderer )
68 mRect = mCanvas->rect();
71 prepareGeometryChange();
72 setPos( mRect.topLeft() );
75 mCachedImages.clear();
83 mCachedImages.clear();
88 bool redrawResults(
const QString &sourceId )
90 auto it = mCachedImages.find( sourceId );
91 if ( it == mCachedImages.end() )
94 mCachedImages.erase( it );
99 QRectF boundingRect()
const override
104 QString distanceSuffix()
const
106 switch ( mDistanceUnit )
159 return QObject::tr(
"°" );
168 mDistanceUnit = unit;
175 if ( !mPlotArea.isNull() )
179 QgsRenderContext context;
180 if ( !scene()->views().isEmpty() )
181 context.
setScaleFactor( scene()->views().at( 0 )->logicalDpiX() / 25.4 );
183 QgsPlotRenderContext plotContext;
189 QgsProfilePoint canvasPointToPlotPoint( QPointF point )
191 const QRectF area = plotArea();
192 if ( !area.contains( point.x(), point.y() ) )
193 return QgsProfilePoint();
195 const double distance = ( point.x() - area.left() ) / area.width() * (
xMaximum() -
xMinimum() ) * mXScaleFactor +
xMinimum() * mXScaleFactor;
197 return QgsProfilePoint( distance, elevation );
200 QgsPointXY plotPointToCanvasPoint(
const QgsProfilePoint &point )
202 if ( point.
distance() < xMinimum() * mXScaleFactor || point.
distance() > xMaximum() * mXScaleFactor || point.
elevation() < yMinimum() || point.
elevation() > yMaximum() )
205 const QRectF area = plotArea();
209 return QgsPointXY( x, y );
212 void renderContent( QgsRenderContext &rc, QgsPlotRenderContext &,
const QRectF &plotArea,
const QgsPlotData & )
override
214 mPlotArea = plotArea;
219 const double pixelRatio = !scene()->views().empty() ? scene()->views().at( 0 )->devicePixelRatioF() : 1;
221 const QStringList sourceIds = mRenderer->sourceIds();
222 for (
const QString &source : sourceIds )
225 auto it = mCachedImages.constFind( source );
226 if ( it != mCachedImages.constEnd() )
232 plot = mRenderer->renderToImage( plotArea.width() * pixelRatio, plotArea.height() * pixelRatio, xMinimum() * mXScaleFactor,
xMaximum() * mXScaleFactor,
yMinimum(),
yMaximum(), source, pixelRatio );
233 plot.setDevicePixelRatio( pixelRatio );
234 mCachedImages.insert( source, plot );
236 rc.
painter()->drawImage( QPointF( plotArea.left(), plotArea.top() ), plot );
241 void paint( QPainter *painter )
override
244 if ( !mImage.isNull() )
246 painter->drawImage( QPointF( 0, 0 ), mImage );
250 const double pixelRatio = !scene()->views().empty() ? scene()->views().at( 0 )->devicePixelRatioF() : 1;
251 mImage = QImage( mRect.width() * pixelRatio, mRect.height() * pixelRatio, QImage::Format_ARGB32_Premultiplied );
252 mImage.setDevicePixelRatio( pixelRatio );
253 mImage.fill( Qt::transparent );
255 QPainter imagePainter( &mImage );
256 imagePainter.setRenderHint( QPainter::Antialiasing,
true );
260 const double mapUnitsPerPixel = (
xMaximum() -
xMinimum() ) * mXScaleFactor / plotArea().width();
266 QgsPlotRenderContext plotContext;
268 render( rc, plotContext );
271 painter->drawImage( QPointF( 0, 0 ), mImage );
275 void setSubsectionsSymbol( QgsLineSymbol *symbol )
279 mRenderer->setSubsectionsSymbol( symbol );
284 QgsProject *mProject =
nullptr;
285 double mXScaleFactor = 1.0;
292 QMap<QString, QImage> mCachedImages;
296 QgsProfilePlotRenderer *mRenderer =
nullptr;
302 QgsElevationProfileCrossHairsItem( QgsElevationProfileCanvas *canvas, QgsElevationProfilePlotItem *plotItem )
303 : QgsPlotCanvasItem( canvas )
304 , mPlotItem( plotItem )
310 mRect = mCanvas->rect();
312 prepareGeometryChange();
313 setPos( mRect.topLeft() );
317 void setPoint(
const QgsProfilePoint &point )
323 QRectF boundingRect()
const override
329 void paint( QPainter *painter )
override
331 const QgsPointXY crossHairPlotPoint = mPlotItem->plotPointToCanvasPoint( mPoint );
332 if ( crossHairPlotPoint.
isEmpty() )
336 painter->setBrush( Qt::NoBrush );
338 crossHairPen.setCosmetic(
true );
339 crossHairPen.setWidthF( 1 );
340 crossHairPen.setStyle( Qt::DashLine );
341 crossHairPen.setCapStyle( Qt::FlatCap );
342 const QPalette scenePalette = mPlotItem->scene()->palette();
343 QColor penColor = scenePalette.color( QPalette::ColorGroup::Active, QPalette::Text );
344 penColor.setAlpha( 150 );
345 crossHairPen.setColor( penColor );
346 painter->setPen( crossHairPen );
347 painter->drawLine( QPointF( mPlotItem->plotArea().left(), crossHairPlotPoint.
y() ), QPointF( mPlotItem->plotArea().right(), crossHairPlotPoint.
y() ) );
348 painter->drawLine( QPointF( crossHairPlotPoint.
x(), mPlotItem->plotArea().top() ), QPointF( crossHairPlotPoint.
x(), mPlotItem->plotArea().bottom() ) );
351 QgsNumericFormatContext numericContext;
353 const QString xCoordinateText = mPlotItem->xAxis().numericFormat()->formatDouble( mPoint.distance() / mPlotItem->mXScaleFactor, numericContext )
354 + mPlotItem->distanceSuffix();
356 const QString yCoordinateText = mPlotItem->yAxis().numericFormat()->formatDouble( mPoint.elevation(), numericContext );
359 const QFontMetrics fm( font );
360 const double height = fm.capHeight();
361 const double xWidth = fm.horizontalAdvance( xCoordinateText );
362 const double yWidth = fm.horizontalAdvance( yCoordinateText );
363 const double textAxisMargin = fm.horizontalAdvance(
' ' );
365 QPointF xCoordOrigin;
366 QPointF yCoordOrigin;
368 if ( mPoint.distance() < ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5 * mPlotItem->mXScaleFactor )
370 if ( mPoint.elevation() < ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5 )
373 xCoordOrigin = QPointF( crossHairPlotPoint.
x() + textAxisMargin, mPlotItem->plotArea().top() + height + textAxisMargin );
375 yCoordOrigin = QPointF( mPlotItem->plotArea().right() - yWidth - textAxisMargin, crossHairPlotPoint.
y() - textAxisMargin );
380 xCoordOrigin = QPointF( crossHairPlotPoint.
x() + textAxisMargin, mPlotItem->plotArea().bottom() - textAxisMargin );
382 yCoordOrigin = QPointF( mPlotItem->plotArea().right() - yWidth - textAxisMargin, crossHairPlotPoint.
y() + height + textAxisMargin );
387 if ( mPoint.elevation() < ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5 )
390 xCoordOrigin = QPointF( crossHairPlotPoint.
x() - xWidth - textAxisMargin, mPlotItem->plotArea().top() + height + textAxisMargin );
392 yCoordOrigin = QPointF( mPlotItem->plotArea().left() + textAxisMargin, crossHairPlotPoint.
y() - textAxisMargin );
397 xCoordOrigin = QPointF( crossHairPlotPoint.
x() - xWidth - textAxisMargin, mPlotItem->plotArea().bottom() - textAxisMargin );
399 yCoordOrigin = QPointF( mPlotItem->plotArea().left() + textAxisMargin, crossHairPlotPoint.
y() + height + textAxisMargin );
404 QColor backgroundColor = mPlotItem->chartBackgroundSymbol()->color();
405 backgroundColor.setAlpha( 220 );
406 painter->setBrush( QBrush( backgroundColor ) );
407 painter->setPen( Qt::NoPen );
408 painter->drawRect( QRectF( xCoordOrigin.x() - textAxisMargin + 1, xCoordOrigin.y() - textAxisMargin - height + 1, xWidth + 2 * textAxisMargin - 2, height + 2 * textAxisMargin - 2 ) );
409 painter->drawRect( QRectF( yCoordOrigin.x() - textAxisMargin + 1, yCoordOrigin.y() - textAxisMargin - height + 1, yWidth + 2 * textAxisMargin - 2, height + 2 * textAxisMargin - 2 ) );
411 painter->setBrush( Qt::NoBrush );
412 painter->setPen( scenePalette.color( QPalette::ColorGroup::Active, QPalette::Text ) );
414 painter->drawText( xCoordOrigin, xCoordinateText );
415 painter->drawText( yCoordOrigin, yCoordinateText );
421 QgsProfilePoint mPoint;
422 QgsElevationProfilePlotItem *mPlotItem =
nullptr;
432 mPlotItem =
new QgsElevationProfilePlotItem(
this );
437 mCrossHairsItem =
new QgsElevationProfileCrossHairsItem(
this, mPlotItem );
438 mCrossHairsItem->setZValue( 100 );
439 mCrossHairsItem->hide();
442 mDeferredRegenerationTimer =
new QTimer(
this );
443 mDeferredRegenerationTimer->setSingleShot(
true );
444 mDeferredRegenerationTimer->stop();
445 connect( mDeferredRegenerationTimer, &QTimer::timeout,
this, &QgsElevationProfileCanvas::startDeferredRegeneration );
447 mDeferredRedrawTimer =
new QTimer(
this );
448 mDeferredRedrawTimer->setSingleShot(
true );
449 mDeferredRedrawTimer->stop();
450 connect( mDeferredRedrawTimer, &QTimer::timeout,
this, &QgsElevationProfileCanvas::startDeferredRedraw );
462 mPlotItem->setRenderer(
nullptr );
463 mCurrentJob->deleteLater();
464 mCurrentJob =
nullptr;
472 mPlotItem->setRenderer(
nullptr );
474 mCurrentJob->cancelGeneration();
475 mCurrentJob->deleteLater();
476 mCurrentJob =
nullptr;
482 const double dxPercent = dx / mPlotItem->plotArea().width();
483 const double dyPercent = dy / mPlotItem->plotArea().height();
486 const double dxPlot = -dxPercent * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() );
487 const double dyPlot = dyPercent * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
490 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
491 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
492 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
493 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
497 mPlotItem->updatePlot();
503 if ( !mPlotItem->plotArea().contains( x, y ) )
506 const double newCenterX = mPlotItem->xMinimum() + ( x - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() );
507 const double newCenterY = mPlotItem->yMinimum() + ( mPlotItem->plotArea().bottom() - y ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
509 const double dxPlot = newCenterX - ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5;
510 const double dyPlot = newCenterY - ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5;
513 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
514 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
515 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
516 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
520 mPlotItem->updatePlot();
532 const double toleranceInPixels = QFontMetrics( font() ).horizontalAdvance(
' ' );
533 const double xToleranceInPlotUnits = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor / ( mPlotItem->plotArea().width() ) * toleranceInPixels;
534 const double yToleranceInPlotUnits = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * toleranceInPixels;
542 / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor / ( mPlotItem->plotArea().width() ) );
549 const double toleranceInPixels = QFontMetrics( font() ).horizontalAdvance(
' ' );
550 const double xToleranceInPlotUnits = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor / ( mPlotItem->plotArea().width() ) * toleranceInPixels;
551 const double yToleranceInPlotUnits = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * toleranceInPixels;
553 QgsProfileIdentifyContext context;
559 / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor / ( mPlotItem->plotArea().width() ) );
566void QgsElevationProfileCanvas::setupLayerConnections(
QgsMapLayer *layer,
bool isDisconnect )
581 switch ( layer->
type() )
585 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
614void QgsElevationProfileCanvas::adjustRangeForAxisScaleLock(
double &xMinimum,
double &xMaximum,
double &yMinimum,
double &yMaximum )
const
617 const double horizontalScale = ( xMaximum - xMinimum ) / mPlotItem->plotArea().width();
618 const double verticalScale = ( yMaximum - yMinimum ) / mPlotItem->plotArea().height();
620 const double currentRatio = horizontalScale / verticalScale;
622 if ( currentRatio <= mLockedAxisScale )
624 const double height = horizontalScale * mPlotItem->plotArea().height() / mLockedAxisScale;
625 const double deltaHeight = ( yMaximum - yMinimum ) - height;
626 yMinimum += deltaHeight / 2;
627 yMaximum -= deltaHeight / 2;
631 const double width = verticalScale * mPlotItem->plotArea().width() * mLockedAxisScale;
632 const double deltaWidth = ( ( xMaximum - xMinimum ) - width );
633 xMinimum += deltaWidth / 2;
634 xMaximum -= deltaWidth / 2;
640 return mDistanceUnit;
645 mDistanceUnit = unit;
646 const double oldMin = mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
647 const double oldMax = mPlotItem->xMaximum() * mPlotItem->mXScaleFactor;
649 mPlotItem->setXAxisUnits( mDistanceUnit );
650 mPlotItem->setXMinimum( oldMin / mPlotItem->mXScaleFactor );
651 mPlotItem->setXMaximum( oldMax / mPlotItem->mXScaleFactor );
652 mPlotItem->updatePlot();
658 if ( !color.isValid() )
660 QPalette customPalette = qApp->palette();
661 const QColor baseColor = qApp->palette().color( QPalette::ColorRole::Base );
662 const QColor windowColor = qApp->palette().color( QPalette::ColorRole::Window );
663 customPalette.setColor( QPalette::ColorRole::Base, windowColor );
664 customPalette.setColor( QPalette::ColorRole::Window, baseColor );
665 setPalette( customPalette );
666 scene()->setPalette( customPalette );
671 const bool isDarkTheme = color.lightnessF() < 0.5;
672 QPalette customPalette = qApp->palette();
673 customPalette.setColor( QPalette::ColorRole::Window, color );
676 customPalette.setColor( QPalette::ColorRole::Text, QColor( 255, 255, 255 ) );
677 customPalette.setColor( QPalette::ColorRole::Base, color.lighter( 120 ) );
681 customPalette.setColor( QPalette::ColorRole::Text, QColor( 0, 0, 0 ) );
682 customPalette.setColor( QPalette::ColorRole::Base, color.darker( 120 ) );
685 setPalette( customPalette );
686 scene()->setPalette( customPalette );
689 updateChartFromPalette();
694 return mLockAxisScales;
699 mLockAxisScales = lock;
700 if ( mLockAxisScales )
702 double xMinimum = mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
703 double xMaximum = mPlotItem->xMaximum() * mPlotItem->mXScaleFactor;
704 double yMinimum = mPlotItem->yMinimum();
705 double yMaximum = mPlotItem->yMaximum();
706 adjustRangeForAxisScaleLock( xMinimum, xMaximum, yMinimum, yMaximum );
707 mPlotItem->setXMinimum( xMinimum / mPlotItem->mXScaleFactor );
708 mPlotItem->setXMaximum( xMaximum / mPlotItem->mXScaleFactor );
709 mPlotItem->setYMinimum( yMinimum );
710 mPlotItem->setYMaximum( yMaximum );
713 mPlotItem->updatePlot();
721 const double horizontalScale = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor / mPlotItem->plotArea().width();
722 const double verticalScale = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / mPlotItem->plotArea().height();
723 return horizontalScale / verticalScale;
728 mLockedAxisScale = scale;
730 double xMinimum = mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
731 double xMaximum = mPlotItem->xMaximum() * mPlotItem->mXScaleFactor;
732 double yMinimum = mPlotItem->yMinimum();
733 double yMaximum = mPlotItem->yMaximum();
734 adjustRangeForAxisScaleLock( xMinimum, xMaximum, yMinimum, yMaximum );
735 mPlotItem->setXMinimum( xMinimum / mPlotItem->mXScaleFactor );
736 mPlotItem->setXMaximum( xMaximum / mPlotItem->mXScaleFactor );
737 mPlotItem->setYMinimum( yMinimum );
738 mPlotItem->setYMaximum( yMaximum );
741 mPlotItem->updatePlot();
748 if ( !mCurrentJob || !mSnappingEnabled )
762 if ( mLockAxisScales )
765 const double currentWidth = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor;
766 const double currentHeight = mPlotItem->yMaximum() - mPlotItem->yMinimum();
768 const double newWidth = currentWidth / xFactor;
769 const double newHeight = currentHeight / yFactor;
771 const double currentCenterX = ( mPlotItem->xMinimum() + mPlotItem->xMaximum() ) * 0.5 * mPlotItem->mXScaleFactor;
772 const double currentCenterY = ( mPlotItem->yMinimum() + mPlotItem->yMaximum() ) * 0.5;
774 double xMinimum = currentCenterX - newWidth * 0.5;
775 double xMaximum = currentCenterX + newWidth * 0.5;
776 double yMinimum = currentCenterY - newHeight * 0.5;
777 double yMaximum = currentCenterY + newHeight * 0.5;
778 if ( mLockAxisScales )
780 adjustRangeForAxisScaleLock( xMinimum, xMaximum, yMinimum, yMaximum );
783 mPlotItem->setXMinimum( xMinimum / mPlotItem->mXScaleFactor );
784 mPlotItem->setXMaximum( xMaximum / mPlotItem->mXScaleFactor );
785 mPlotItem->setYMinimum( yMinimum );
786 mPlotItem->setYMaximum( yMaximum );
789 mPlotItem->updatePlot();
796 const QRectF intersected = rect.intersected( mPlotItem->plotArea() );
798 double minX = ( intersected.left() - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor + mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
799 double maxX = ( intersected.right() - mPlotItem->plotArea().left() ) / mPlotItem->plotArea().width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor + mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
800 double minY = ( mPlotItem->plotArea().bottom() - intersected.bottom() ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
801 double maxY = ( mPlotItem->plotArea().bottom() - intersected.top() ) / mPlotItem->plotArea().height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
803 if ( mLockAxisScales )
805 adjustRangeForAxisScaleLock( minX, maxX, minY, maxY );
808 mPlotItem->setXMinimum( minX / mPlotItem->mXScaleFactor );
809 mPlotItem->setXMaximum( maxX / mPlotItem->mXScaleFactor );
810 mPlotItem->setYMinimum( minY );
811 mPlotItem->setYMaximum( maxY );
814 mPlotItem->updatePlot();
823 double zoomFactor = settings.
value( QStringLiteral(
"qgis/zoom_factor" ), 2 ).toDouble();
824 bool reverseZoom = settings.
value( QStringLiteral(
"qgis/reverse_wheel_zoom" ),
false ).toBool();
825 bool zoomIn = reverseZoom ?
event->angleDelta().y() < 0 :
event->angleDelta().y() > 0;
828 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * std::fabs(
event->angleDelta().y() );
830 if (
event->modifiers() & Qt::ControlModifier )
833 zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 20.0;
837 double scaleFactor = ( zoomIn ? 1 / zoomFactor : zoomFactor );
839 QRectF viewportRect = mPlotItem->plotArea();
841 if ( viewportRect.contains(
event->position() ) )
844 const double oldCenterX = 0.5 * ( mPlotItem->xMaximum() + mPlotItem->xMinimum() );
845 const double oldCenterY = 0.5 * ( mPlotItem->yMaximum() + mPlotItem->yMinimum() );
847 const double eventPosX = (
event->position().x() - viewportRect.left() ) / viewportRect.width() * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) + mPlotItem->xMinimum();
848 const double eventPosY = ( viewportRect.bottom() -
event->position().y() ) / viewportRect.height() * ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) + mPlotItem->yMinimum();
850 const double newCenterX = eventPosX + ( ( oldCenterX - eventPosX ) * scaleFactor );
851 const double newCenterY = eventPosY + ( ( oldCenterY - eventPosY ) * scaleFactor );
853 const double dxPlot = newCenterX - ( mPlotItem->xMaximum() + mPlotItem->xMinimum() ) * 0.5;
854 const double dyPlot = newCenterY - ( mPlotItem->yMaximum() + mPlotItem->yMinimum() ) * 0.5;
857 mPlotItem->setXMinimum( mPlotItem->xMinimum() + dxPlot );
858 mPlotItem->setXMaximum( mPlotItem->xMaximum() + dxPlot );
859 mPlotItem->setYMinimum( mPlotItem->yMinimum() + dyPlot );
860 mPlotItem->setYMaximum( mPlotItem->yMaximum() + dyPlot );
879 if ( e->isAccepted() )
881 mCrossHairsItem->hide();
886 if ( mCurrentJob && mSnappingEnabled && !plotPoint.
isEmpty() )
895 mCrossHairsItem->hide();
899 mCrossHairsItem->setPoint( plotPoint );
900 mCrossHairsItem->show();
907 return mPlotItem->plotArea();
921 request.
setTerrainProvider( mProject->elevationProperties()->terrainProvider() ? mProject->elevationProperties()->terrainProvider()->clone() :
nullptr );
927 QList< QgsAbstractProfileSource *> sourcesToRender =
sources();
928 std::reverse( sourcesToRender.begin(), sourcesToRender.end() );
934 generationContext.
setDpi( mScreenHelper->screenDpi() );
935 generationContext.
setMaximumErrorMapUnits( MAX_ERROR_PIXELS * ( mProfileCurve->length() ) / mPlotItem->plotArea().width() );
937 mCurrentJob->setContext( generationContext );
939 if ( mSubsectionsSymbol )
941 mCurrentJob->setSubsectionsSymbol( mSubsectionsSymbol->clone() );
944 mCurrentJob->startGeneration();
945 mPlotItem->setRenderer( mCurrentJob );
952 mZoomFullWhenJobFinished =
true;
955void QgsElevationProfileCanvas::generationFinished()
962 if ( mZoomFullWhenJobFinished )
965 mZoomFullWhenJobFinished =
false;
974 mPlotItem->updatePlot();
977 if ( mForceRegenerationAfterCurrentJobCompletes )
979 mForceRegenerationAfterCurrentJobCompletes =
false;
980 mCurrentJob->invalidateAllRefinableSources();
981 scheduleDeferredRegeneration();
985void QgsElevationProfileCanvas::onLayerProfileGenerationPropertyChanged()
988 if ( !mCurrentJob || mCurrentJob->isActive() )
991 QgsMapLayerElevationProperties *properties = qobject_cast<QgsMapLayerElevationProperties *>( sender() );
995 if ( QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( properties->parent() ) )
997 if ( QgsAbstractProfileSource *source = layer->
profileSource() )
999 if ( mCurrentJob->invalidateResults( source ) )
1000 scheduleDeferredRegeneration();
1005void QgsElevationProfileCanvas::onLayerProfileRendererPropertyChanged()
1008 if ( !mCurrentJob || mCurrentJob->isActive() )
1011 QgsMapLayerElevationProperties *properties = qobject_cast<QgsMapLayerElevationProperties *>( sender() );
1015 if ( QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( properties->parent() ) )
1017 if ( QgsAbstractProfileSource *source = layer->
profileSource() )
1019 mCurrentJob->replaceSource( source );
1021 if ( mPlotItem->redrawResults( layer->
id() ) )
1022 scheduleDeferredRedraw();
1026void QgsElevationProfileCanvas::regenerateResultsForLayer()
1031 if ( QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() ) )
1033 if ( QgsAbstractProfileSource *source = layer->
profileSource() )
1035 if ( mCurrentJob->invalidateResults( source ) )
1036 scheduleDeferredRegeneration();
1041void QgsElevationProfileCanvas::scheduleDeferredRegeneration()
1043 if ( !mDeferredRegenerationScheduled )
1045 mDeferredRegenerationTimer->start( 1 );
1046 mDeferredRegenerationScheduled =
true;
1050void QgsElevationProfileCanvas::scheduleDeferredRedraw()
1052 if ( !mDeferredRedrawScheduled )
1054 mDeferredRedrawTimer->start( 1 );
1055 mDeferredRedrawScheduled =
true;
1059void QgsElevationProfileCanvas::startDeferredRegeneration()
1061 if ( mCurrentJob && !mCurrentJob->isActive() )
1064 mCurrentJob->regenerateInvalidatedResults();
1066 else if ( mCurrentJob )
1068 mForceRegenerationAfterCurrentJobCompletes =
true;
1071 mDeferredRegenerationScheduled =
false;
1074void QgsElevationProfileCanvas::startDeferredRedraw()
1076 mPlotItem->update();
1077 mDeferredRedrawScheduled =
false;
1080void QgsElevationProfileCanvas::refineResults()
1084 QgsProfileGenerationContext context;
1085 context.
setDpi( mScreenHelper->screenDpi() );
1086 const double plotDistanceRange = ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor;
1087 const double plotElevationRange = mPlotItem->yMaximum() - mPlotItem->yMinimum();
1088 const double plotDistanceUnitsPerPixel = plotDistanceRange / mPlotItem->plotArea().width();
1092 const double targetMaxErrorInMapUnits = MAX_ERROR_PIXELS * plotDistanceUnitsPerPixel;
1093 const double factor = std::pow( 10.0, 1 - std::ceil( std::log10( std::fabs( targetMaxErrorInMapUnits ) ) ) );
1094 const double roundedErrorInMapUnits = std::floor( targetMaxErrorInMapUnits * factor ) / factor;
1101 context.
setDistanceRange( QgsDoubleRange( std::max( 0.0, distanceMin ), mPlotItem->xMaximum() * mPlotItem->mXScaleFactor + plotDistanceRange * 0.05 ) );
1103 context.
setElevationRange( QgsDoubleRange( mPlotItem->yMinimum() - plotElevationRange * 0.05, mPlotItem->yMaximum() + plotElevationRange * 0.05 ) );
1104 mCurrentJob->setContext( context );
1106 scheduleDeferredRegeneration();
1109void QgsElevationProfileCanvas::updateChartFromPalette()
1111 const QPalette chartPalette = palette();
1112 setBackgroundBrush( QBrush( chartPalette.color( QPalette::ColorRole::Base ) ) );
1114 QgsTextFormat textFormat = mPlotItem->xAxis().textFormat();
1115 textFormat.
setColor( chartPalette.color( QPalette::ColorGroup::Active, QPalette::Text ) );
1116 mPlotItem->xAxis().setTextFormat( textFormat );
1117 mPlotItem->yAxis().setTextFormat( textFormat );
1120 std::unique_ptr<QgsFillSymbol> chartFill( mPlotItem->chartBackgroundSymbol()->clone() );
1121 chartFill->setColor( chartPalette.color( QPalette::ColorGroup::Active, QPalette::ColorRole::Window ) );
1122 mPlotItem->setChartBackgroundSymbol( chartFill.release() );
1125 std::unique_ptr<QgsFillSymbol> chartBorder( mPlotItem->chartBorderSymbol()->clone() );
1126 chartBorder->setColor( chartPalette.color( QPalette::ColorGroup::Active, QPalette::ColorRole::Text ) );
1127 mPlotItem->setChartBorderSymbol( chartBorder.release() );
1130 std::unique_ptr<QgsLineSymbol> chartMajorSymbol( mPlotItem->xAxis().gridMajorSymbol()->clone() );
1131 QColor
c = chartPalette.color( QPalette::ColorGroup::Active, QPalette::ColorRole::Text );
1133 chartMajorSymbol->setColor(
c );
1134 mPlotItem->xAxis().setGridMajorSymbol( chartMajorSymbol->clone() );
1135 mPlotItem->yAxis().setGridMajorSymbol( chartMajorSymbol.release() );
1138 std::unique_ptr<QgsLineSymbol> chartMinorSymbol( mPlotItem->xAxis().gridMinorSymbol()->clone() );
1139 QColor
c = chartPalette.color( QPalette::ColorGroup::Active, QPalette::ColorRole::Text );
1141 chartMinorSymbol->setColor(
c );
1142 mPlotItem->xAxis().setGridMinorSymbol( chartMinorSymbol->clone() );
1143 mPlotItem->yAxis().setGridMinorSymbol( chartMinorSymbol.release() );
1145 mPlotItem->updatePlot();
1150 if ( !mPlotItem->plotArea().contains( point.x(), point.y() ) )
1153 return mPlotItem->canvasPointToPlotPoint( point );
1158 return mPlotItem->plotPointToCanvasPoint( point );
1164 mPlotItem->mProject = project;
1174 mProfileCurve.reset( curve );
1179 return mProfileCurve.get();
1194 for (
QgsMapLayer *layer : std::as_const( mLayers ) )
1196 setupLayerConnections( layer,
true );
1200 auto filteredList =
layers;
1201 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(), [](
QgsMapLayer *layer ) {
1202 return !layer || !layer->isValid();
1204 filteredList.end() );
1206 mLayers = _qgis_listRawToQPointer( filteredList );
1207 for (
QgsMapLayer *layer : std::as_const( mLayers ) )
1209 setupLayerConnections( layer,
false );
1215 return _qgis_listQPointerToRaw( mLayers );
1225 if ( mSources.isEmpty() && !mLayers.isEmpty() )
1231 QList< QgsAbstractProfileSource * >
sources;
1232 const QList<QgsMapLayer *> layersToGenerate =
layers();
1233 sources.reserve( layersToGenerate.size() );
1255 if ( mLockAxisScales )
1257 double xMinimum = mPlotItem->xMinimum();
1258 double xMaximum = mPlotItem->xMaximum();
1259 double yMinimum = mPlotItem->yMinimum();
1260 double yMaximum = mPlotItem->yMaximum();
1261 adjustRangeForAxisScaleLock( xMinimum, xMaximum, yMinimum, yMaximum );
1262 mPlotItem->setXMinimum( xMinimum );
1263 mPlotItem->setXMaximum( xMaximum );
1264 mPlotItem->setYMinimum( yMinimum );
1265 mPlotItem->setYMaximum( yMaximum );
1268 mPlotItem->updateRect();
1269 mCrossHairsItem->updateRect();
1276 QgsPlotCanvas::paintEvent(
event );
1278 if ( !mFirstDrawOccurred )
1281 mFirstDrawOccurred =
true;
1282 mPlotItem->updateRect();
1283 mCrossHairsItem->updateRect();
1289 if ( !mPlotItem->plotArea().contains( point.
x(), point.
y() ) )
1292 if ( !mProfileCurve )
1295 const double dx = point.
x() - mPlotItem->plotArea().left();
1297 const double distanceAlongPlotPercent = dx / mPlotItem->plotArea().width();
1298 double distanceAlongCurveLength = distanceAlongPlotPercent * ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor + mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
1300 std::unique_ptr<QgsPoint> mapXyPoint( mProfileCurve->interpolatePoint( distanceAlongCurveLength ) );
1304 const double mapZ = ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) * ( mPlotItem->plotArea().bottom() - point.
y() ) + mPlotItem->yMinimum();
1306 return QgsPoint( mapXyPoint->x(), mapXyPoint->y(), mapZ );
1311 if ( !mProfileCurve )
1316 const double distanceAlongCurve =
geos.lineLocatePoint( point, &error );
1318 const double distanceAlongCurveOnPlot = distanceAlongCurve - mPlotItem->xMinimum() * mPlotItem->mXScaleFactor;
1319 const double distanceAlongCurvePercent = distanceAlongCurveOnPlot / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) * mPlotItem->mXScaleFactor );
1320 const double distanceAlongPlotRect = distanceAlongCurvePercent * mPlotItem->plotArea().width();
1322 const double canvasX = mPlotItem->plotArea().left() + distanceAlongPlotRect;
1325 if ( std::isnan( point.
z() ) || point.
z() < mPlotItem->yMinimum() )
1327 canvasY = mPlotItem->plotArea().top();
1329 else if ( point.
z() > mPlotItem->yMaximum() )
1331 canvasY = mPlotItem->plotArea().bottom();
1335 const double yPercent = ( point.
z() - mPlotItem->yMinimum() ) / ( mPlotItem->yMaximum() - mPlotItem->yMinimum() );
1336 canvasY = mPlotItem->plotArea().bottom() - mPlotItem->plotArea().height() * yPercent;
1349 double yMinimum = 0;
1350 double yMaximum = 0;
1361 yMinimum = zRange.
lower() - 5;
1362 yMaximum = zRange.
lower() + 5;
1367 const double margin = ( zRange.
upper() - zRange.
lower() ) * 0.05;
1368 yMinimum = zRange.
lower() - margin;
1369 yMaximum = zRange.
upper() + margin;
1373 double xMinimum = 0;
1375 double xMaximum = profileLength * 1.02;
1377 if ( mLockAxisScales )
1379 adjustRangeForAxisScaleLock( xMinimum, xMaximum, yMinimum, yMaximum );
1382 mPlotItem->setXMinimum( xMinimum / mPlotItem->mXScaleFactor );
1383 mPlotItem->setXMaximum( xMaximum / mPlotItem->mXScaleFactor );
1384 mPlotItem->setYMinimum( yMinimum );
1385 mPlotItem->setYMaximum( yMaximum );
1388 mPlotItem->updatePlot();
1395 if ( mLockAxisScales )
1397 adjustRangeForAxisScaleLock( minimumDistance, maximumDistance, minimumElevation, maximumElevation );
1400 mPlotItem->setYMinimum( minimumElevation );
1401 mPlotItem->setYMaximum( maximumElevation );
1402 mPlotItem->setXMinimum( minimumDistance / mPlotItem->mXScaleFactor );
1403 mPlotItem->setXMaximum( maximumDistance / mPlotItem->mXScaleFactor );
1405 mPlotItem->updatePlot();
1412 return QgsDoubleRange( mPlotItem->xMinimum() * mPlotItem->mXScaleFactor, mPlotItem->xMaximum() * mPlotItem->mXScaleFactor );
1417 return QgsDoubleRange( mPlotItem->yMinimum(), mPlotItem->yMaximum() );
1430 : mRenderer( renderer )
1434 void renderContent( QgsRenderContext &rc, QgsPlotRenderContext &,
const QRectF &plotArea,
const QgsPlotData & )
override
1439 rc.
painter()->translate( plotArea.left(), plotArea.top() );
1440 mRenderer->render( rc, plotArea.width(), plotArea.height(), xMinimum() * mXScale,
xMaximum() * mXScale,
yMinimum(),
yMaximum() );
1441 rc.
painter()->translate( -plotArea.left(), -plotArea.top() );
1447 QgsProfilePlotRenderer *mRenderer =
nullptr;
1459 QgsElevationProfilePlot profilePlot( mCurrentJob );
1463 QDomElement elem = doc.createElement( QStringLiteral(
"plot" ) );
1465 plotSettings.
writeXml( elem, doc, rwContext );
1466 profilePlot.readXml( elem, rwContext );
1468 profilePlot.mXScale = mPlotItem->mXScaleFactor;
1469 profilePlot.xAxis().setLabelSuffix( mPlotItem->xAxis().labelSuffix() );
1470 profilePlot.xAxis().setLabelSuffixPlacement( mPlotItem->xAxis().labelSuffixPlacement() );
1472 profilePlot.setSize( QSizeF( width, height ) );
1474 profilePlot.render( context, plotContext );
1484 return mCurrentJob->identify( plotPoint, identifyContext() );
1495 double distance1 = topLeftPlotPoint.
distance();
1496 double distance2 = bottomRightPlotPoint.
distance();
1497 if ( distance2 < distance1 )
1498 std::swap( distance1, distance2 );
1500 double elevation1 = topLeftPlotPoint.
elevation();
1501 double elevation2 = bottomRightPlotPoint.
elevation();
1502 if ( elevation2 < elevation1 )
1503 std::swap( elevation1, elevation2 );
1512 mPlotItem->updatePlot();
1517 mSnappingEnabled = enabled;
1522 mSubsectionsSymbol.reset( symbol );
1523 std::unique_ptr<QgsLineSymbol> plotItemSymbol( mSubsectionsSymbol ? mSubsectionsSymbol->clone() :
nullptr );
1524 mPlotItem->setSubsectionsSymbol( plotItemSymbol.release() );
1527void QgsElevationProfileCanvas::setSourcesPrivate()
@ FirstAndLastLabels
Place suffix after the first and last label values only.
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).
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
virtual void renderContent(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QRectF &plotArea, const QgsPlotData &plotData=QgsPlotData())
Renders the plot content.
void setSize(QSizeF size)
Sets the overall size of the plot (including titles and over components which sit outside the plot ar...
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.
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
double xMinimum() const
Returns the minimum value of the x axis.
void render(QgsRenderContext &context, QgsPlotRenderContext &plotContext, const QgsPlotData &plotData=QgsPlotData()) override
Renders the plot.
void calculateOptimisedIntervals(QgsRenderContext &context, QgsPlotRenderContext &plotContext)
Automatically sets the grid and label intervals to optimal values for display in the given render con...
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
double yMinimum() const
Returns the minimum value of the y axis.
QRectF interiorPlotArea(QgsRenderContext &context, QgsPlotRenderContext &plotContext) const override
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the plot's properties into an XML element.
double xMaximum() const
Returns the maximum value of the x axis.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
Interface for classes which can generate elevation profiles.
static QgsProfileSourceRegistry * profileSourceRegistry()
Returns registry of available profile source implementations.
Represents a coordinate reference system (CRS).
Abstract base class for curved geometry type.
QgsRange which stores a range of double values.
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 setSources(const QList< QgsAbstractProfileSource * > &sources)
Sets the list of sources to include in the profile.
void setLockAxisScales(bool lock)
Sets whether the distance and elevation scales are locked to each other.
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.
void setDistanceUnit(Qgis::DistanceUnit unit)
Sets the distance unit used by the canvas.
QgsProfilePoint canvasPointToPlotPoint(QPointF point) const
Converts a canvas point to the equivalent plot point.
void setBackgroundColor(const QColor &color)
Sets the background color to use for the profile canvas.
void render(QgsRenderContext &context, double width, double height, const Qgs2DXyPlot &plotSettings)
Renders a portion of the profile using the specified render context.
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.
bool lockAxisScales() const
Returns true if the distance and elevation scales are locked to each other.
void setAxisScaleRatio(double scale)
Sets the ratio of horizontal (distance) to vertical (elevation) scale for the plot.
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).
const Qgs2DXyPlot & plot() const
Returns a reference to the 2D plot used by the widget.
void setSubsectionsSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the subsections.
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.
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...
Qgis::DistanceUnit distanceUnit() const
Returns the distance unit used by the canvas.
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.
QList< QgsAbstractProfileSource * > sources() const
Returns the list of sources included in the profile.
~QgsElevationProfileCanvas() override
double axisScaleRatio() const
Returns the current ratio of horizontal (distance) to vertical (elevation) scale for the plot.
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.
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, and exception handling.
A line symbol type, for rendering LineString and MultiLineString geometries.
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.
virtual QgsAbstractProfileSource * profileSource()
Returns the layer's profile source if it has profile capabilities.
void dataChanged()
Data of layer changed.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
void setLabelSuffixPlacement(Qgis::PlotAxisSuffixPlacement placement)
Sets the placement for the axis label suffixes.
void setLabelSuffix(const QString &suffix)
Sets the axis label suffix.
An abstract class for items that can be placed on a QgsPlotCanvas.
virtual void paint(QPainter *painter)=0
Paints the item.
bool event(QEvent *e) override
QgsPlotCanvas(QWidget *parent=nullptr)
Constructor for QgsPlotCanvas, with the specified parent widget.
void plotAreaChanged()
Emitted whenever the visible area of the plot is changed.
void mouseMoveEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
Contains information about the context of a plot rendering operation.
bool isEmpty() const
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.
void generationFinished()
Emitted when the profile generation is finished (or canceled).
Encapsulates a point on a distance-elevation profile.
double elevation() const
Returns the elevation of the point.
double distance() const
Returns the distance of the point.
bool isEmpty() const
Returns true if the point is empty.
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.
void profileSourceUnregistered(const QString &sourceId)
Signal emitted once a profile source is unregistered.
QList< QgsAbstractProfileSource * > profileSources() const
Returns a list of registered profile sources.
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,...
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
A container for the context for various read/write operations on 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.
void setDevicePixelRatio(float ratio)
Sets the device pixel ratio.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
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.
Stores settings for use within QGIS.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
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.
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.
Contains geos related utilities and functions.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define BUILTIN_UNREACHABLE
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).