Realization in Ensemble RFT-plot hover info + refactoring of point tracker functionality

* Add realization number to mouse over text for Ensemble RFT

* Refactor Curve Info Text Provider functionality

- Refactor provider implementation, to separate RiuWellLogTrack from the point tracker and text provider.
- Move creating of point tracker outside of RiuWellLogTrack.
- Makes it possible to override/write new CurveInfoTextProvider implementation when needed.

* Add guards for nullptr
This commit is contained in:
Jørgen Herje
2023-02-23 15:08:22 +01:00
committed by GitHub
parent 0601de4c18
commit 5c5e460025
8 changed files with 240 additions and 137 deletions

View File

@@ -33,7 +33,7 @@
#include "RiuPlotAnnotationTool.h"
#include "RiuPlotCurve.h"
#include "RiuPlotCurveInfoTextProvider.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuQwtPlotTools.h"
#include "qwt_plot.h"
@@ -45,139 +45,6 @@
#include <QWheelEvent>
class RiuWellLogCurvePointTracker : public RiuQwtCurvePointTracker
{
public:
RiuWellLogCurvePointTracker( QwtPlot* plot, RiuPlotCurveInfoTextProvider* curveInfoTextProvider, RimWellLogTrack* track )
: RiuQwtCurvePointTracker( plot, false, curveInfoTextProvider )
, m_wellLogTrack( track )
{
}
protected:
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtText trackerText( const QPoint& pos ) const override
{
QwtText txt;
if ( m_plot )
{
QwtAxisId relatedYAxis( QwtAxis::YLeft, 0 );
QwtAxisId relatedXAxis( QwtAxis::XTop, 0 );
QString curveInfoText;
QString depthAxisValueString;
QString xAxisValueString;
QPointF closestPoint =
closestCurvePoint( pos, &curveInfoText, &xAxisValueString, &depthAxisValueString, &relatedXAxis, &relatedYAxis );
if ( !closestPoint.isNull() )
{
QString str;
RimWellLogPlot* wlp = nullptr;
m_wellLogTrack->firstAncestorOfType( wlp );
if ( wlp && wlp->depthOrientation() == RiaDefines::Orientation::HORIZONTAL )
{
str = QString( "%1\nDepth: %2" ).arg( depthAxisValueString ).arg( xAxisValueString );
}
else
{
str = QString( "%1\nDepth: %2" ).arg( xAxisValueString ).arg( depthAxisValueString );
}
if ( !curveInfoText.isEmpty() )
{
str = QString( "%1:\n" ).arg( curveInfoText ) + str;
}
txt.setText( str );
}
updateClosestCurvePointMarker( closestPoint, relatedXAxis, relatedYAxis );
}
auto color = RiuGuiTheme::getColorByVariableName( "markerColor" );
txt.setColor( color );
return txt;
}
private:
caf::PdmPointer<RimWellLogTrack> m_wellLogTrack;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class WellLogCurveInfoTextProvider : public RiuPlotCurveInfoTextProvider
{
public:
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString curveInfoText( RiuPlotCurve* riuCurve ) const override
{
if ( riuCurve )
{
RimWellLogCurve* wlCurve = dynamic_cast<RimWellLogCurve*>( riuCurve->ownerRimCurve() );
if ( wlCurve )
{
return QString( "%1" ).arg( wlCurve->curveName() );
}
}
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString additionalText( RiuPlotCurve* curve, int sampleIndex ) const override
{
if ( !curve ) return {};
std::vector<std::pair<QString, double>> propertyNameValues;
auto* sourceCurve = curve->ownerRimCurve();
if ( !sourceCurve ) return {};
auto annotationCurves = sourceCurve->additionalDataSources();
for ( auto annotationCurve : annotationCurves )
{
RimDepthTrackPlot* depthTrackPlot = nullptr;
annotationCurve->firstAncestorOfType( depthTrackPlot );
if ( depthTrackPlot )
{
auto [xValue, yValue] = curve->sample( sampleIndex );
auto depth = depthTrackPlot->depthOrientation() == RiaDefines::Orientation::VERTICAL ? yValue : xValue;
auto propertyValue = annotationCurve->closestYValueForX( depth );
// Use template to get as short label as possible. The default curve name will often
// contain too much and redundant information.
QString templateText = RiaDefines::namingVariableResultName() + ", " +
RiaDefines::namingVariableResultType();
auto resultName = annotationCurve->createCurveNameFromTemplate( templateText );
propertyNameValues.push_back( std::make_pair( resultName, propertyValue ) );
}
}
QString txt;
for ( const auto& [name, value] : propertyNameValues )
{
txt += QString( "%1 : %2\n" ).arg( name ).arg( value );
}
return txt;
}
};
static WellLogCurveInfoTextProvider wellLogCurveInfoTextProvider;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -194,8 +61,6 @@ RiuWellLogTrack::RiuWellLogTrack( RimWellLogTrack* track, QWidget* parent /*= nu
setAxisEnabled( QwtAxis::XBottom, isVertical );
m_annotationTool = std::make_unique<RiuPlotAnnotationTool>();
new RiuWellLogCurvePointTracker( this->qwtPlot(), &wellLogCurveInfoTextProvider, track );
}
//--------------------------------------------------------------------------------------------------
@@ -293,3 +158,63 @@ void RiuWellLogTrack::onMouseMoveEvent( QMouseEvent* mouseEvent )
if ( wellLogTrack ) wellLogTrack->updateDepthMarkerLine();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellLogCurvePointTracker::RiuWellLogCurvePointTracker( QwtPlot* plot,
RiuPlotCurveInfoTextProvider* curveInfoTextProvider,
RimWellLogTrack* track )
: RiuQwtCurvePointTracker( plot, false, curveInfoTextProvider )
, m_wellLogTrack( track )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtText RiuWellLogCurvePointTracker::trackerText( const QPoint& pos ) const
{
QwtText txt;
if ( m_plot )
{
QwtAxisId relatedYAxis( QwtAxis::YLeft, 0 );
QwtAxisId relatedXAxis( QwtAxis::XTop, 0 );
QString curveInfoText;
QString depthAxisValueString;
QString xAxisValueString;
QPointF closestPoint =
closestCurvePoint( pos, &curveInfoText, &xAxisValueString, &depthAxisValueString, &relatedXAxis, &relatedYAxis );
if ( !closestPoint.isNull() )
{
QString str;
RimWellLogPlot* wlp = nullptr;
m_wellLogTrack->firstAncestorOfType( wlp );
if ( wlp && wlp->depthOrientation() == RiaDefines::Orientation::HORIZONTAL )
{
str = QString( "%1\nDepth: %2" ).arg( depthAxisValueString ).arg( xAxisValueString );
}
else
{
str = QString( "%1\nDepth: %2" ).arg( xAxisValueString ).arg( depthAxisValueString );
}
if ( !curveInfoText.isEmpty() )
{
str = QString( "%1:\n" ).arg( curveInfoText ) + str;
}
txt.setText( str );
}
updateClosestCurvePointMarker( closestPoint, relatedXAxis, relatedYAxis );
}
auto color = RiuGuiTheme::getColorByVariableName( "markerColor" );
txt.setColor( color );
return txt;
}