Merge pull request #8387 from OPM/qtcharts-summary-plots

Closes #8228 

Major refactoring of summary plotting. Now possible to create plots both with Qwt and QtChart as plotting tool.
This commit is contained in:
Kristian Bendiksen
2022-01-17 13:14:21 +01:00
committed by GitHub
parent d9bb82de91
commit 258fbddc10
145 changed files with 7245 additions and 2932 deletions

View File

@@ -23,26 +23,18 @@
#include "Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleStatisticsCase.h"
#include "RimMainPlotCollection.h"
#include "RimPlot.h"
#include "RimPlotAxisAnnotation.h"
#include "RimPlotAxisProperties.h"
#include "RimPlotAxisPropertiesInterface.h"
#include "RimRegularLegendConfig.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCurve.h"
#include "RimSummaryCurveCollection.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuPlotAnnotationTool.h"
#include "RiuPlotCurve.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuRimQwtPlotCurve.h"
#include "RiuQwtPlotWidget.h"
#include "RiuWidgetDragger.h"
#include "RiuPlotMainWindowTools.h"
@@ -51,8 +43,6 @@
#include "RiuQwtPlotZoomer.h"
#include "RiuQwtScalePicker.h"
#include "RimProject.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "cafIconProvider.h"
#include "cafSelectionManager.h"
@@ -88,8 +78,8 @@ public:
//--------------------------------------------------------------------------------------------------
QString curveInfoText( QwtPlotCurve* curve ) override
{
RiuRimQwtPlotCurve* riuCurve = dynamic_cast<RiuRimQwtPlotCurve*>( curve );
RimSummaryCurve* sumCurve = nullptr;
RiuPlotCurve* riuCurve = dynamic_cast<RiuPlotCurve*>( curve );
RimSummaryCurve* sumCurve = nullptr;
if ( riuCurve )
{
sumCurve = dynamic_cast<RimSummaryCurve*>( riuCurve->ownerRimCurve() );
@@ -104,24 +94,28 @@ static EnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider;
///
//--------------------------------------------------------------------------------------------------
RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*= nullptr*/ )
: RiuQwtPlotWidget( plot, parent )
: RiuSummaryPlot( plot, parent )
{
m_plotWidget = new RiuQwtPlotWidget( plot, parent );
m_plotWidget->setContextMenuPolicy( Qt::CustomContextMenu );
connect( m_plotWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showContextMenu( QPoint ) ) );
// LeftButton for the zooming
m_zoomerLeft = new RiuQwtPlotZoomer( canvas() );
m_zoomerLeft = new RiuQwtPlotZoomer( m_plotWidget->qwtPlot()->canvas() );
m_zoomerLeft->setTrackerMode( QwtPicker::AlwaysOff );
m_zoomerLeft->initMousePattern( 1 );
// Attach a zoomer for the right axis
m_zoomerRight = new RiuQwtPlotZoomer( canvas() );
m_zoomerRight->setAxis( xTop, yRight );
m_zoomerRight = new RiuQwtPlotZoomer( m_plotWidget->qwtPlot()->canvas() );
m_zoomerRight->setAxis( QwtPlot::xTop, QwtPlot::yRight );
m_zoomerRight->setTrackerMode( QwtPicker::AlwaysOff );
m_zoomerRight->initMousePattern( 1 );
// MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner( canvas() );
QwtPlotPanner* panner = new QwtPlotPanner( m_plotWidget->qwtPlot()->canvas() );
panner->setMouseButton( Qt::MidButton );
m_wheelZoomer = new RiuQwtPlotWheelZoomer( this );
m_wheelZoomer = new RiuQwtPlotWheelZoomer( m_plotWidget->qwtPlot() );
connect( m_wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
@@ -129,12 +123,12 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
setDefaults();
new RiuQwtCurvePointTracker( this, true, &ensembleCurveInfoTextProvider );
new RiuQwtCurvePointTracker( m_plotWidget->qwtPlot(), true, &ensembleCurveInfoTextProvider );
RiuQwtPlotTools::setCommonPlotBehaviour( this );
RiuQwtPlotTools::setDefaultAxes( this );
RiuQwtPlotTools::setCommonPlotBehaviour( m_plotWidget->qwtPlot() );
RiuQwtPlotTools::setDefaultAxes( m_plotWidget->qwtPlot() );
setInternalLegendVisible( true );
m_plotWidget->setInternalLegendVisible( true );
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>( new RiuPlotAnnotationTool() );
}
@@ -154,7 +148,7 @@ void RiuSummaryQwtPlot::useDateBasedTimeAxis( const QString&
RiaQDateTimeTools::DateFormatComponents dateComponents,
RiaQDateTimeTools::TimeFormatComponents timeComponents )
{
RiuQwtPlotTools::enableDateBasedBottomXAxis( this, dateFormat, timeFormat, dateComponents, timeComponents );
RiuQwtPlotTools::enableDateBasedBottomXAxis( m_plotWidget->qwtPlot(), dateFormat, timeFormat, dateComponents, timeComponents );
}
//--------------------------------------------------------------------------------------------------
@@ -162,16 +156,8 @@ void RiuSummaryQwtPlot::useDateBasedTimeAxis( const QString&
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
{
setAxisScaleEngine( QwtPlot::xBottom, new QwtLinearScaleEngine() );
setAxisScaleDraw( QwtPlot::xBottom, new QwtScaleDraw() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setAxisIsLogarithmic( QwtPlot::Axis axis, bool logarithmic )
{
if ( m_wheelZoomer ) m_wheelZoomer->setAxisIsLogarithmic( axis, logarithmic );
m_plotWidget->qwtPlot()->setAxisScaleEngine( QwtPlot::xBottom, new QwtLinearScaleEngine() );
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtPlot::xBottom, new QwtScaleDraw() );
}
//--------------------------------------------------------------------------------------------------
@@ -190,7 +176,7 @@ void RiuSummaryQwtPlot::updateAnnotationObjects( RimPlotAxisPropertiesInterface*
{
if ( annotation->annotationType() == RimPlotAxisAnnotation::AnnotationType::LINE )
{
m_annotationTool->attachAnnotationLine( this,
m_annotationTool->attachAnnotationLine( m_plotWidget->qwtPlot(),
annotation->color(),
annotation->name(),
annotation->value(),
@@ -198,7 +184,7 @@ void RiuSummaryQwtPlot::updateAnnotationObjects( RimPlotAxisPropertiesInterface*
}
else if ( annotation->annotationType() == RimPlotAxisAnnotation::AnnotationType::RANGE )
{
m_annotationTool->attachAnnotationRange( this,
m_annotationTool->attachAnnotationRange( m_plotWidget->qwtPlot(),
annotation->color(),
annotation->name(),
annotation->rangeStart(),
@@ -208,163 +194,6 @@ void RiuSummaryQwtPlot::updateAnnotationObjects( RimPlotAxisPropertiesInterface*
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event )
{
QMenu menu;
caf::CmdFeatureMenuBuilder menuBuilder;
emit plotSelected( false );
menuBuilder << "RicShowPlotDataFeature";
menuBuilder << "RicSavePlotTemplateFeature";
QwtPlotItem* closestItem = nullptr;
double distanceFromClick = std::numeric_limits<double>::infinity();
int closestCurvePoint = -1;
QPoint globalPos = event->globalPos();
QPoint localPos = this->canvas()->mapFromGlobal( globalPos );
findClosestPlotItem( localPos, &closestItem, &closestCurvePoint, &distanceFromClick );
if ( closestItem && closestCurvePoint >= 0 )
{
RiuRimQwtPlotCurve* plotCurve = dynamic_cast<RiuRimQwtPlotCurve*>( closestItem );
if ( plotCurve )
{
RimSummaryCurve* summaryCurve = dynamic_cast<RimSummaryCurve*>( plotCurve->ownerRimCurve() );
if ( summaryCurve && closestCurvePoint < (int)summaryCurve->timeStepsY().size() )
{
std::time_t timeStep = summaryCurve->timeStepsY()[closestCurvePoint];
RimSummaryCaseCollection* ensemble = nullptr;
QString clickedQuantityName;
QStringList allQuantityNamesInPlot;
RimEnsembleCurveSet* clickedEnsembleCurveSet = nullptr;
summaryCurve->firstAncestorOrThisOfType( clickedEnsembleCurveSet );
bool curveClicked = distanceFromClick < 50;
if ( clickedEnsembleCurveSet )
{
ensemble = clickedEnsembleCurveSet->summaryCaseCollection();
if ( ensemble && ensemble->isEnsemble() )
{
clickedQuantityName = QString::fromStdString( clickedEnsembleCurveSet->summaryAddress().uiText() );
}
}
{
auto summaryCase = summaryCurve->summaryCaseY();
if ( summaryCase )
{
int summaryCaseId = summaryCase->caseId();
QVariant summaryCaseIdVariant( summaryCaseId );
auto modelName = summaryCase->nativeCaseName();
menuBuilder.addCmdFeatureWithUserData( "RicImportGridModelFromSummaryCurveFeature",
QString( "Open Grid Model '%1'" ).arg( modelName ),
summaryCaseIdVariant );
}
}
if ( !curveClicked )
{
RimSummaryPlot* summaryPlot = static_cast<RimSummaryPlot*>( plotDefinition() );
std::vector<RimEnsembleCurveSet*> allCurveSetsInPlot;
summaryPlot->descendantsOfType( allCurveSetsInPlot );
for ( auto curveSet : allCurveSetsInPlot )
{
allQuantityNamesInPlot.push_back( QString::fromStdString( curveSet->summaryAddress().uiText() ) );
}
}
else
{
allQuantityNamesInPlot.push_back( clickedQuantityName );
}
if ( !clickedQuantityName.isEmpty() || !allQuantityNamesInPlot.isEmpty() )
{
if ( ensemble && ensemble->isEnsemble() )
{
EnsemblePlotParams params( ensemble, allQuantityNamesInPlot, clickedQuantityName, timeStep );
QVariant variant = QVariant::fromValue( params );
menuBuilder.addCmdFeatureWithUserData( "RicNewAnalysisPlotFeature", "New Analysis Plot", variant );
QString subMenuName = "Create Correlation Plot";
if ( curveClicked )
{
subMenuName = "Create Correlation Plot From Curve Point";
}
menuBuilder.subMenuStart( subMenuName, *caf::IconProvider( ":/CorrelationPlots16x16.png" ).icon() );
{
if ( curveClicked )
{
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationPlotFeature",
"New Tornado Plot",
variant );
}
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationMatrixPlotFeature",
"New Matrix Plot",
variant );
menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationReportPlotFeature",
"New Report Plot",
variant );
if ( curveClicked )
{
menuBuilder.subMenuStart( "Cross Plots",
*caf::IconProvider( ":/CorrelationCrossPlot16x16.png" ).icon() );
std::vector<std::pair<RigEnsembleParameter, double>> ensembleParameters =
ensemble->parameterCorrelations( clickedEnsembleCurveSet->summaryAddress(), timeStep );
std::sort( ensembleParameters.begin(),
ensembleParameters.end(),
[]( const std::pair<RigEnsembleParameter, double>& lhs,
const std::pair<RigEnsembleParameter, double>& rhs ) {
return std::fabs( lhs.second ) > std::fabs( rhs.second );
} );
for ( const auto& param : ensembleParameters )
{
if ( std::fabs( param.second ) >= 1.0e-6 )
{
params.ensembleParameter = param.first.name;
variant = QVariant::fromValue( params );
menuBuilder.addCmdFeatureWithUserData( "RicNewParameterResultCrossPlotFeature",
QString( "New Cross Plot Against %1 "
"(Correlation: %2)" )
.arg( param.first.name )
.arg( param.second, 5, 'f', 2 ),
variant );
}
}
menuBuilder.subMenuEnd();
}
}
menuBuilder.subMenuEnd();
}
}
}
}
}
menuBuilder.appendToMenu( &menu );
if ( menu.actions().size() > 0 )
{
menu.exec( event->globalPos() );
// Parts of progress dialog GUI can be present after menu has closed related to
// RicImportGridModelFromSummaryCurveFeature. Make sure the plot is updated, and call processEvents() to make
// sure all GUI events are processed
update();
QApplication::processEvents();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -398,5 +227,13 @@ void RiuSummaryQwtPlot::endZoomOperations()
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onZoomedSlot()
{
emit plotZoomed();
emit m_plotWidget->plotZoomed();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuPlotWidget* RiuSummaryQwtPlot::plotWidget() const
{
return m_plotWidget;
}