Show time annotation in all sub plots (#11906)

* Prepare for more customization of annotation objects
* Move files
* Add configuration of readout lines in sub plots. The location along the time axis is based on the current mouse cursor position. The location is distributed to all sub plots. Optional support for readout of values at the current time.
This commit is contained in:
Magne Sjaastad
2025-02-05 17:19:01 +01:00
committed by GitHub
parent 28d3050433
commit 2021b286ab
29 changed files with 550 additions and 100 deletions

View File

@@ -141,7 +141,8 @@ void RiuGridCrossQwtPlot::updateAnnotationObjects( RimPlotAxisPropertiesInterfac
annotation->name(),
annotation->penStyle(),
annotation->value(),
RiaDefines::Orientation::HORIZONTAL );
RiaDefines::Orientation::HORIZONTAL,
Qt::AlignRight );
}
}

View File

@@ -190,7 +190,8 @@ void RiuPlotAnnotationTool::attachAnnotationLine( QwtPlot* plot,
const QString& annotationText,
Qt::PenStyle penStyle,
const double position,
RiaDefines::Orientation orientation )
RiaDefines::Orientation orientation,
Qt::Alignment horizontalAlignment )
{
m_plot = plot;
@@ -202,22 +203,11 @@ void RiuPlotAnnotationTool::attachAnnotationLine( QwtPlot* plot,
textColor = RiuGuiTheme::getColorByVariableName( "textColor" );
}
RiuPlotAnnotationTool::setLineProperties( line, annotationText, orientation, position, penStyle, color, textColor );
RiuPlotAnnotationTool::setLineProperties( line, annotationText, orientation, position, penStyle, color, textColor, horizontalAlignment );
m_plotItems.push_back( line );
line->attach( m_plot );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotAnnotationTool::attachAnnotation( QwtPlot* plot, RimPlotAxisAnnotation* annotation, RiaDefines::Orientation orientation )
{
if ( annotation->annotationType() == RimPlotAxisAnnotation::AnnotationType::LINE )
{
attachAnnotationLine( plot, annotation->color(), annotation->name(), annotation->penStyle(), annotation->value(), orientation );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -262,6 +252,23 @@ void RiuPlotAnnotationTool::detachAllAnnotations()
m_plotItems.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::Alignment RiuPlotAnnotationTool::textAlignment( RiaDefines::TextAlignment alignment )
{
switch ( alignment )
{
case RiaDefines::TextAlignment::LEFT:
return Qt::AlignLeft;
case RiaDefines::TextAlignment::CENTER:
return Qt::AlignHCenter;
case RiaDefines::TextAlignment::RIGHT:
return Qt::AlignRight;
}
return Qt::AlignRight;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -58,9 +58,8 @@ public:
const QString& annotationText,
Qt::PenStyle penStyle,
const double position,
RiaDefines::Orientation orientation );
void attachAnnotation( QwtPlot* plot, RimPlotAxisAnnotation* annotation, RiaDefines::Orientation orientation );
RiaDefines::Orientation orientation,
Qt::Alignment horizontalAlignment );
void attachAnnotationRange( QwtPlot* plot,
const QColor& color,
@@ -83,6 +82,8 @@ public:
void detachAllAnnotations();
static Qt::Alignment textAlignment( RiaDefines::TextAlignment alignment );
private:
static Qt::Alignment trackTextAlignment( RiaDefines::TrackSpan trackSpan );

View File

@@ -52,6 +52,8 @@ public:
virtual RiuPlotWidget* plotWidget() const = 0;
virtual void enableCurvePointTracking( bool enable ){};
public slots:
void showContextMenu( QPoint );
};

View File

@@ -20,6 +20,7 @@
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "Summary/RiaSummaryTools.h"
#include "Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h"
@@ -29,7 +30,9 @@
#include "RimPlotAxisPropertiesInterface.h"
#include "RimSummaryCase.h"
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryPlot.h"
#include "RimSummaryTimeAxisProperties.h"
#include "RiuPlotAnnotationTool.h"
#include "RiuPlotCurve.h"
@@ -40,7 +43,6 @@
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtPlotTools.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuQwtScalePicker.h"
@@ -54,6 +56,7 @@
#include "qwt_interval.h"
#include "qwt_legend.h"
#include "qwt_legend_label.h"
#include "qwt_picker_machine.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_panner.h"
#include "qwt_plot_zoomer.h"
@@ -71,6 +74,44 @@
static RimEnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider;
//--------------------------------------------------------------------------------------------------
/// Class used to track the cursor position and send the plot coordinates to the summary plot
//--------------------------------------------------------------------------------------------------
class CoordinatePicker : public QwtPlotPicker
{
public:
CoordinatePicker( RimSummaryMultiPlot* summaryMultiPlot, QwtPlot* plot )
: QwtPlotPicker( plot->canvas() )
, m_summaryMultiPlot( summaryMultiPlot )
{
setTrackerMode( QwtPlotPicker::AlwaysOn );
plot->canvas()->setMouseTracking( true );
setStateMachine( new QwtPickerTrackerMachine );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtText trackerText( const QPoint& screenPixelCoordinates ) const override
{
if ( m_summaryMultiPlot )
{
auto domainCoordinates = invTransform( screenPixelCoordinates );
auto qwtTimeValue = domainCoordinates.x();
auto yValue = domainCoordinates.y();
m_summaryMultiPlot->updateReadOutLines( qwtTimeValue, yValue );
}
// Return empty text here, as we only want to update the vertical line
return {};
}
private:
caf::PdmPointer<RimSummaryMultiPlot> m_summaryMultiPlot;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -97,7 +138,7 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
setDefaults();
new RiuQwtCurvePointTracker( m_plotWidget->qwtPlot(), true, &ensembleCurveInfoTextProvider );
m_curvePointTracker = new RiuQwtCurvePointTracker( m_plotWidget->qwtPlot(), true, &ensembleCurveInfoTextProvider );
RiuQwtPlotTools::setCommonPlotBehaviour( m_plotWidget->qwtPlot() );
RiuQwtPlotTools::setDefaultAxes( m_plotWidget->qwtPlot() );
@@ -107,6 +148,11 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
m_plotWidget->clearLegend();
m_annotationTool = std::make_unique<RiuPlotAnnotationTool>();
if ( auto multiPlot = RiaSummaryTools::parentSummaryMultiPlot( plot ) )
{
new CoordinatePicker( multiPlot, m_plotWidget->qwtPlot() );
}
}
//--------------------------------------------------------------------------------------------------
@@ -158,7 +204,8 @@ void RiuSummaryQwtPlot::updateAnnotationObjects( RimPlotAxisPropertiesInterface*
annotation->name(),
annotation->penStyle(),
annotation->value(),
orientation );
orientation,
RiuPlotAnnotationTool::textAlignment( annotation->textAlignment() ) );
}
else if ( annotation->annotationType() == RimPlotAxisAnnotation::AnnotationType::RANGE )
{
@@ -215,6 +262,14 @@ RiuPlotWidget* RiuSummaryQwtPlot::plotWidget() const
return m_plotWidget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::enableCurvePointTracking( bool enable )
{
m_curvePointTracker->setEnabled( enable );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -33,6 +33,7 @@ class RiuQwtPlotZoomer;
class RiuQwtPlotWheelZoomer;
class RimPlotAxisPropertiesInterface;
class RiuPlotAnnotationTool;
class RiuQwtCurvePointTracker;
//==================================================================================================
//
@@ -59,6 +60,8 @@ public:
RiuPlotWidget* plotWidget() const override;
void enableCurvePointTracking( bool enable ) override;
protected:
void setDefaults();
bool isZoomerActive() const;
@@ -71,6 +74,7 @@ private:
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;
QPointer<RiuQwtPlotWidget> m_plotWidget;
QPointer<RiuQwtPlotZoomer> m_plotZoomer;
QPointer<RiuQwtPlotWheelZoomer> m_wheelZoomer;
QPointer<RiuQwtPlotZoomer> m_plotZoomer;
QPointer<RiuQwtPlotWheelZoomer> m_wheelZoomer;
QPointer<RiuQwtCurvePointTracker> m_curvePointTracker;
};

View File

@@ -107,7 +107,13 @@ void RiuWellLogTrack::createAnnotationsInPlot( const std::vector<RimPlotAxisAnno
: RiaDefines::Orientation::HORIZONTAL;
for ( auto annotation : annotations )
{
m_annotationTool->attachAnnotation( qwtPlot(), annotation, orientation );
m_annotationTool->attachAnnotationLine( qwtPlot(),
annotation->color(),
annotation->name(),
annotation->penStyle(),
annotation->value(),
orientation,
Qt::AlignRight );
}
}