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

@@ -18,7 +18,6 @@
#include "RimPlotCurve.h"
#include "RiaColorTables.h"
#include "RiaColorTools.h"
#include "RiaCurveDataTools.h"
#include "RiaGuiApplication.h"
@@ -33,23 +32,19 @@
#include "RimSummaryCurveCollection.h"
#include "RimSummaryPlot.h"
#include "RiuPlotCurve.h"
#include "RiuPlotCurveSymbol.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuRimQwtPlotCurve.h"
#include "RiuPlotWidget.h"
#include "cafAssert.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cvfAssert.h"
#include "qwt_date.h"
#include "qwt_interval_symbol.h"
#include "qwt_plot.h"
#include "qwt_symbol.h"
#include <QPen>
// NB! Special macro for pure virtual class
CAF_PDM_XML_ABSTRACT_SOURCE_INIT( RimPlotCurve, "PlotCurve" );
#define DOUBLE_INF std::numeric_limits<double>::infinity()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -125,14 +120,8 @@ RimPlotCurve::RimPlotCurve()
m_curveAppearance->appearanceChanged.connect( this, &RimPlotCurve::onCurveAppearanceChanged );
m_curveAppearance->appearanceChanged.connect( this, &RimPlotCurve::onFillColorChanged );
m_qwtPlotCurve = new RiuRimQwtPlotCurve( this );
m_qwtCurveErrorBars = new QwtPlotIntervalCurve();
m_qwtCurveErrorBars->setStyle( QwtPlotIntervalCurve::CurveStyle::NoCurve );
m_qwtCurveErrorBars->setSymbol( new QwtIntervalSymbol( QwtIntervalSymbol::Bar ) );
m_qwtCurveErrorBars->setItemAttribute( QwtPlotItem::Legend, false );
m_qwtCurveErrorBars->setZ( RiuQwtPlotCurveDefines::zDepthForIndex( RiuQwtPlotCurveDefines::ZIndex::Z_ERROR_BARS ) );
m_parentQwtPlot = nullptr;
m_plotCurve = nullptr;
m_parentPlot = nullptr;
}
//--------------------------------------------------------------------------------------------------
@@ -140,18 +129,11 @@ RimPlotCurve::RimPlotCurve()
//--------------------------------------------------------------------------------------------------
RimPlotCurve::~RimPlotCurve()
{
if ( m_qwtPlotCurve )
if ( m_plotCurve )
{
m_qwtPlotCurve->detach();
delete m_qwtPlotCurve;
m_qwtPlotCurve = nullptr;
}
if ( m_qwtCurveErrorBars )
{
m_qwtCurveErrorBars->detach();
delete m_qwtCurveErrorBars;
m_qwtCurveErrorBars = nullptr;
detach();
delete m_plotCurve;
m_plotCurve = nullptr;
}
}
@@ -191,7 +173,7 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField, co
}
RiuPlotMainWindowTools::refreshToolbars();
if ( m_parentQwtPlot ) m_parentQwtPlot->replot();
replotParentPlot();
}
//--------------------------------------------------------------------------------------------------
@@ -237,22 +219,7 @@ void RimPlotCurve::setLegendEntryText( const QString& legendEntryText )
void RimPlotCurve::setErrorBarsVisible( bool isVisible )
{
m_showErrorBars = isVisible;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateCurveVisibility()
{
if ( canCurveBeAttached() )
{
attachCurveAndErrorBars();
}
else
{
m_qwtPlotCurve->detach();
m_qwtCurveErrorBars->detach();
}
updateCurveAppearance();
}
//--------------------------------------------------------------------------------------------------
@@ -286,37 +253,6 @@ void RimPlotCurve::updateCurvePresentation( bool updatePlotLegendAndTitle )
updateCurveAppearance();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setParentQwtPlotAndReplot( QwtPlot* plot )
{
m_parentQwtPlot = plot;
if ( canCurveBeAttached() )
{
attachCurveAndErrorBars();
m_parentQwtPlot->replot();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setParentQwtPlotNoReplot( QwtPlot* plot )
{
m_parentQwtPlot = plot;
if ( canCurveBeAttached() )
{
attachCurveAndErrorBars();
}
else
{
m_qwtPlotCurve->detach();
m_qwtCurveErrorBars->detach();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -342,35 +278,6 @@ cvf::Color3f RimPlotCurve::color() const
return m_curveAppearance->color();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::detachQwtCurve()
{
m_qwtPlotCurve->detach();
m_qwtCurveErrorBars->detach();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::reattachQwtCurve()
{
detachQwtCurve();
if ( canCurveBeAttached() )
{
attachCurveAndErrorBars();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtPlotCurve* RimPlotCurve::qwtPlotCurve() const
{
return m_qwtPlotCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -401,16 +308,13 @@ void RimPlotCurve::updateCurveName()
m_curveName = m_customCurveName;
}
if ( m_qwtPlotCurve )
if ( !m_legendEntryText().isEmpty() )
{
if ( !m_legendEntryText().isEmpty() )
{
m_qwtPlotCurve->setTitle( m_legendEntryText );
}
else
{
m_qwtPlotCurve->setTitle( m_curveName );
}
setTitle( m_legendEntryText );
}
else
{
setTitle( m_curveName );
}
}
@@ -453,126 +357,6 @@ void RimPlotCurve::updatePlotTitle()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateLegendsInPlot()
{
nameChanged.send( curveName() );
if ( m_parentQwtPlot != nullptr )
{
m_parentQwtPlot->updateLegend();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromXYErrorValues(
const std::vector<double>& xValues,
const std::vector<double>& yValues,
const std::vector<double>& errorValues,
bool keepOnlyPositiveValues,
RiaCurveDataTools::ErrorAxis errorAxis /*= RiuQwtPlotCurve::ERROR_ALONG_Y_AXIS */ )
{
CVF_ASSERT( xValues.size() == yValues.size() );
CVF_ASSERT( xValues.size() == errorValues.size() );
auto intervalsOfValidValues = RiaCurveDataTools::calculateIntervalsOfValidValues( yValues, keepOnlyPositiveValues );
std::vector<double> filteredYValues;
std::vector<double> filteredXValues;
RiaCurveDataTools::getValuesByIntervals( yValues, intervalsOfValidValues, &filteredYValues );
RiaCurveDataTools::getValuesByIntervals( xValues, intervalsOfValidValues, &filteredXValues );
std::vector<double> filteredErrorValues;
RiaCurveDataTools::getValuesByIntervals( errorValues, intervalsOfValidValues, &filteredErrorValues );
QVector<QwtIntervalSample> errorIntervals;
errorIntervals.reserve( static_cast<int>( filteredXValues.size() ) );
for ( size_t i = 0; i < filteredXValues.size(); i++ )
{
if ( filteredYValues[i] != DOUBLE_INF && filteredErrorValues[i] != DOUBLE_INF )
{
if ( errorAxis == RiaCurveDataTools::ErrorAxis::ERROR_ALONG_Y_AXIS )
{
errorIntervals << QwtIntervalSample( filteredXValues[i],
filteredYValues[i] - filteredErrorValues[i],
filteredYValues[i] + filteredErrorValues[i] );
}
else
{
errorIntervals << QwtIntervalSample( filteredYValues[i],
filteredXValues[i] - filteredErrorValues[i],
filteredXValues[i] + filteredErrorValues[i] );
}
}
}
if ( m_qwtPlotCurve )
{
m_qwtPlotCurve->setSamples( filteredXValues.data(),
filteredYValues.data(),
static_cast<int>( filteredXValues.size() ) );
m_qwtPlotCurve->setLineSegmentStartStopIndices( intervalsOfValidValues );
}
if ( m_qwtCurveErrorBars )
{
m_qwtCurveErrorBars->setSamples( errorIntervals );
if ( errorAxis == RiaCurveDataTools::ErrorAxis::ERROR_ALONG_Y_AXIS )
{
m_qwtCurveErrorBars->setOrientation( Qt::Vertical );
}
else
{
m_qwtCurveErrorBars->setOrientation( Qt::Horizontal );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromXYValues( const std::vector<double>& xValues,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_qwtPlotCurve )
{
m_qwtPlotCurve->setSamplesFromXValuesAndYValues( xValues, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromDatesAndYValues( const std::vector<QDateTime>& dateTimes,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_qwtPlotCurve )
{
m_qwtPlotCurve->setSamplesFromDatesAndYValues( dateTimes, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromTimeTAndYValues( const std::vector<time_t>& dateTimes,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_qwtPlotCurve )
{
m_qwtPlotCurve->setSamplesFromTimeTAndYValues( dateTimes, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -591,21 +375,6 @@ void RimPlotCurve::curveNameUiOrdering( caf::PdmUiOrdering& uiOrdering )
uiOrdering.add( &m_curveName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateUiIconFromPlotSymbol()
{
if ( m_curveAppearance->symbol() != RiuQwtSymbol::SYMBOL_NONE && m_qwtPlotCurve )
{
CVF_ASSERT( RiaGuiApplication::isRunning() );
QSizeF iconSize( 24, 24 );
QwtGraphic graphic = m_qwtPlotCurve->legendIcon( 0, iconSize );
QPixmap pixmap = graphic.toPixmap();
setUiIcon( caf::IconProvider( pixmap ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -631,7 +400,7 @@ void RimPlotCurve::updateCurveAppearanceForFilesOlderThan_2021_06()
//--------------------------------------------------------------------------------------------------
bool RimPlotCurve::canCurveBeAttached() const
{
if ( !m_parentQwtPlot )
if ( !hasParentPlot() )
{
return false;
}
@@ -656,19 +425,6 @@ bool RimPlotCurve::canCurveBeAttached() const
return isVisibleInPossibleParent;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::attachCurveAndErrorBars()
{
m_qwtPlotCurve->attach( m_parentQwtPlot );
if ( m_showErrorBars )
{
m_qwtCurveErrorBars->attach( m_parentQwtPlot );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -680,88 +436,6 @@ void RimPlotCurve::checkAndApplyDefaultFillColor()
// }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateCurveAppearance()
{
QColor curveColor = RiaColorTools::toQColor( m_curveAppearance->color() );
QwtSymbol* symbol = nullptr;
if ( m_curveAppearance->symbol() != RiuQwtSymbol::SYMBOL_NONE )
{
int legendFontSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(),
caf::FontTools::RelativeSize::Small );
RimPlotWindow* plotWindow = nullptr;
this->firstAncestorOrThisOfType( plotWindow );
if ( plotWindow )
{
legendFontSize = plotWindow->legendFontSize();
}
// QwtPlotCurve will take ownership of the symbol
symbol = new RiuQwtSymbol( m_curveAppearance->symbol(),
m_curveAppearance->symbolLabel(),
m_curveAppearance->symbolLabelPosition(),
legendFontSize );
symbol->setSize( m_curveAppearance->symbolSize(), m_curveAppearance->symbolSize() );
symbol->setColor( curveColor );
// If the symbol is a "filled" symbol, we can have a different edge color
// Otherwise we'll have to use the curve color.
if ( RiuQwtSymbol::isFilledSymbol( m_curveAppearance->symbol() ) )
{
QColor symbolEdgeColor = RiaColorTools::toQColor( m_curveAppearance->symbolEdgeColor() );
symbol->setPen( symbolEdgeColor );
}
else
{
symbol->setPen( curveColor );
}
}
if ( m_qwtCurveErrorBars )
{
QwtIntervalSymbol* newSymbol = new QwtIntervalSymbol( QwtIntervalSymbol::Bar );
newSymbol->setPen( QPen( curveColor ) );
m_qwtCurveErrorBars->setSymbol( newSymbol );
}
if ( m_qwtPlotCurve )
{
QColor fillColor = RiaColorTools::toQColor( m_curveAppearance->fillColor() );
fillColor = RiaColorTools::blendQColors( fillColor, QColor( Qt::white ), 3, 1 );
QBrush fillBrush( fillColor, m_curveAppearance->fillStyle() );
m_qwtPlotCurve->setAppearance( m_curveAppearance->lineStyle(),
m_curveAppearance->interpolation(),
m_curveAppearance->lineThickness(),
curveColor,
fillBrush );
m_qwtPlotCurve->setSymbol( symbol );
m_qwtPlotCurve->setSymbolSkipPixelDistance( m_curveAppearance->symbolSkipDistance() );
// Make sure the legend lines are long enough to distinguish between line types.
// Standard width in Qwt is 8 which is too short.
// Use 10 and scale this by curve thickness + add space for displaying symbol.
if ( m_curveAppearance->lineStyle() != RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_NONE )
{
QSize legendIconSize = m_qwtPlotCurve->legendIconSize();
int symbolWidth = 0;
if ( symbol )
{
symbolWidth = symbol->boundingRect().size().width() + 2;
}
int width = std::max( 10 * m_curveAppearance->lineThickness(), ( symbolWidth * 3 ) / 2 );
legendIconSize.setWidth( width );
m_qwtPlotCurve->setLegendIconSize( legendIconSize );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -786,44 +460,6 @@ void RimPlotCurve::loadDataAndUpdate( bool updateParentPlot )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotCurve::xValueRangeInQwt( double* minimumValue, double* maximumValue ) const
{
CVF_ASSERT( minimumValue && maximumValue );
CVF_ASSERT( m_qwtPlotCurve );
if ( m_qwtPlotCurve->data()->size() < 1 )
{
return false;
}
*minimumValue = m_qwtPlotCurve->minXValue();
*maximumValue = m_qwtPlotCurve->maxXValue();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotCurve::yValueRangeInQwt( double* minimumValue, double* maximumValue ) const
{
CVF_ASSERT( minimumValue && maximumValue );
CVF_ASSERT( m_qwtPlotCurve );
if ( m_qwtPlotCurve->data()->size() < 1 )
{
return false;
}
*minimumValue = m_qwtPlotCurve->minYValue();
*maximumValue = m_qwtPlotCurve->maxYValue();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -835,7 +471,7 @@ void RimPlotCurve::setLineStyle( RiuQwtPlotCurveDefines::LineStyleEnum lineStyle
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSymbol( RiuQwtSymbol::PointSymbolEnum symbolStyle )
void RimPlotCurve::setSymbol( RiuPlotCurveSymbol::PointSymbolEnum symbolStyle )
{
m_curveAppearance->setSymbol( symbolStyle );
}
@@ -851,7 +487,7 @@ void RimPlotCurve::setInterpolation( RiuQwtPlotCurveDefines::CurveInterpolationE
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuQwtSymbol::PointSymbolEnum RimPlotCurve::symbol()
RiuPlotCurveSymbol::PointSymbolEnum RimPlotCurve::symbol()
{
return m_curveAppearance->symbol();
}
@@ -899,7 +535,7 @@ void RimPlotCurve::setSymbolLabel( const QString& label )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSymbolLabelPosition( RiuQwtSymbol::LabelPosition labelPosition )
void RimPlotCurve::setSymbolLabelPosition( RiuPlotCurveSymbol::LabelPosition labelPosition )
{
m_curveAppearance->setSymbolLabelPosition( labelPosition );
}
@@ -929,7 +565,7 @@ void RimPlotCurve::resetAppearance()
setSymbolEdgeColor( RiaColorTools::textColor3f() );
setLineThickness( 2 );
setLineStyle( RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_SOLID );
setSymbol( RiuQwtSymbol::SYMBOL_NONE );
setSymbol( RiuPlotCurveSymbol::SYMBOL_NONE );
setSymbolSkipDistance( 10 );
}
@@ -979,18 +615,9 @@ bool RimPlotCurve::errorBarsVisible() const
void RimPlotCurve::setShowInLegend( bool show )
{
m_showLegend = show;
updateLegendEntryVisibilityNoPlotUpdate();
}
if ( m_plotCurve ) m_plotCurve->setVisibleInLegend( show );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setZOrder( double z )
{
if ( m_qwtPlotCurve != nullptr )
{
m_qwtPlotCurve->setZ( z );
}
updateLegendEntryVisibilityNoPlotUpdate();
}
//--------------------------------------------------------------------------------------------------
@@ -1002,12 +629,124 @@ void RimPlotCurve::updateLegendEntryVisibilityAndPlotLegend()
updateLegendsInPlot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::onCurveAppearanceChanged( const caf::SignalEmitter* emitter )
{
checkAndApplyDefaultFillColor();
updateCurveAppearance();
appearanceChanged.send();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::onFillColorChanged( const caf::SignalEmitter* emitter )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateLegendsInPlot()
{
nameChanged.send( curveName() );
if ( m_parentPlot != nullptr )
{
m_parentPlot->updateLegend();
}
}
void RimPlotCurve::setTitle( const QString& title )
{
if ( m_plotCurve ) m_plotCurve->setTitle( title );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::replotParentPlot()
{
if ( m_parentPlot ) m_parentPlot->replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotCurve::hasParentPlot() const
{
return ( m_parentPlot != nullptr );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromXYValues( const std::vector<double>& xValues,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_plotCurve )
{
m_plotCurve->setSamplesFromXValuesAndYValues( xValues, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromDatesAndYValues( const std::vector<QDateTime>& dateTimes,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_plotCurve )
{
m_plotCurve->setSamplesFromDatesAndYValues( dateTimes, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromTimeTAndYValues( const std::vector<time_t>& dateTimes,
const std::vector<double>& yValues,
bool keepOnlyPositiveValues )
{
if ( m_plotCurve )
{
m_plotCurve->setSamplesFromTimeTAndYValues( dateTimes, yValues, keepOnlyPositiveValues );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setSamplesFromXYErrorValues( const std::vector<double>& xValues,
const std::vector<double>& yValues,
const std::vector<double>& errorValues,
bool keepOnlyPositiveValues,
RiaCurveDataTools::ErrorAxis errorAxis )
{
if ( m_plotCurve )
{
m_plotCurve->setSamplesFromXYErrorValues( xValues, yValues, errorValues, keepOnlyPositiveValues, errorAxis );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateAxisInPlot( RiaDefines::PlotAxis plotAxis )
{
if ( m_plotCurve ) m_plotCurve->setYAxis( plotAxis );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateLegendEntryVisibilityNoPlotUpdate()
{
if ( !m_qwtPlotCurve ) return;
if ( !m_plotCurve ) return;
RimEnsembleCurveSet* ensembleCurveSet = nullptr;
this->firstAncestorOrThisOfType( ensembleCurveSet );
@@ -1016,7 +755,7 @@ void RimPlotCurve::updateLegendEntryVisibilityNoPlotUpdate()
return;
}
bool showLegendInQwt = m_showLegend();
bool showLegendInPlot = m_showLegend();
RimSummaryPlot* summaryPlot = nullptr;
this->firstAncestorOrThisOfType( summaryPlot );
@@ -1037,25 +776,279 @@ void RimPlotCurve::updateLegendEntryVisibilityNoPlotUpdate()
summaryPlot->curveCount() == 1 )
{
// Disable display of legend if the summary plot has only one single curve
showLegendInQwt = false;
showLegendInPlot = false;
}
}
m_qwtPlotCurve->setItemAttribute( QwtPlotItem::Legend, showLegendInQwt );
m_plotCurve->setVisibleInLegend( showLegendInPlot );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::onCurveAppearanceChanged( const caf::SignalEmitter* emitter )
bool RimPlotCurve::xValueRange( double* minimumValue, double* maximumValue ) const
{
checkAndApplyDefaultFillColor();
updateCurveAppearance();
appearanceChanged.send();
CAF_ASSERT( minimumValue && maximumValue );
CAF_ASSERT( m_plotCurve );
if ( m_plotCurve->numSamples() < 1 )
{
return false;
}
auto [min, max] = m_plotCurve->xDataRange();
*minimumValue = min;
*maximumValue = max;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::onFillColorChanged( const caf::SignalEmitter* emitter )
bool RimPlotCurve::yValueRange( double* minimumValue, double* maximumValue ) const
{
CAF_ASSERT( minimumValue && maximumValue );
CAF_ASSERT( m_plotCurve );
if ( m_plotCurve->numSamples() < 1 )
{
return false;
}
auto [min, max] = m_plotCurve->yDataRange();
*minimumValue = min;
*maximumValue = max;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setZOrder( double z )
{
if ( m_plotCurve != nullptr )
{
m_plotCurve->setZ( z );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateCurveAppearance()
{
QColor curveColor = RiaColorTools::toQColor( m_curveAppearance->color() );
if ( !m_plotCurve ) return;
RiuPlotCurveSymbol* symbol = nullptr;
if ( m_curveAppearance->symbol() != RiuPlotCurveSymbol::SYMBOL_NONE )
{
int legendFontSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(),
caf::FontTools::RelativeSize::Small );
RimPlotWindow* plotWindow = nullptr;
this->firstAncestorOrThisOfType( plotWindow );
if ( plotWindow )
{
legendFontSize = plotWindow->legendFontSize();
}
// Plot curve will take ownership of the symbol
symbol = m_plotCurve->createSymbol( m_curveAppearance->symbol() );
if ( symbol )
{
symbol->setLabelPosition( m_curveAppearance->symbolLabelPosition() );
symbol->setGlobalLabel( m_curveAppearance->symbolLabel() );
symbol->setSize( m_curveAppearance->symbolSize(), m_curveAppearance->symbolSize() );
symbol->setColor( curveColor );
symbol->setLabelFontSize( legendFontSize );
// If the symbol is a "filled" symbol, we can have a different edge color
// Otherwise we'll have to use the curve color.
if ( RiuPlotCurveSymbol::isFilledSymbol( m_curveAppearance->symbol() ) )
{
QColor symbolEdgeColor = RiaColorTools::toQColor( m_curveAppearance->symbolEdgeColor() );
symbol->setPen( symbolEdgeColor );
}
else
{
symbol->setPen( curveColor );
}
}
}
m_plotCurve->updateErrorBarsAppearance( m_showErrorBars, curveColor );
QColor fillColor = RiaColorTools::toQColor( m_curveAppearance->fillColor() );
fillColor = RiaColorTools::blendQColors( fillColor, QColor( Qt::white ), 3, 1 );
QBrush fillBrush( fillColor, m_curveAppearance->fillStyle() );
m_plotCurve->setAppearance( m_curveAppearance->lineStyle(),
m_curveAppearance->interpolation(),
m_curveAppearance->lineThickness(),
curveColor,
fillBrush );
m_plotCurve->setSymbol( symbol );
m_plotCurve->setSymbolSkipPixelDistance( m_curveAppearance->symbolSkipDistance() );
// Make sure the legend lines are long enough to distinguish between line types.
// Standard width in Qwt is 8 which is too short.
// Use 10 and scale this by curve thickness + add space for displaying symbol.
if ( m_curveAppearance->lineStyle() != RiuQwtPlotCurveDefines::LineStyleEnum::STYLE_NONE )
{
QSize legendIconSize = m_plotCurve->legendIconSize();
int symbolWidth = 0;
if ( symbol )
{
symbolWidth = symbol->boundingRect().size().width() + 2;
}
int width = std::max( 10 * m_curveAppearance->lineThickness(), ( symbolWidth * 3 ) / 2 );
legendIconSize.setWidth( width );
m_plotCurve->setLegendIconSize( legendIconSize );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::clearErrorBars()
{
if ( m_plotCurve ) m_plotCurve->clearErrorBars();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateUiIconFromPlotSymbol()
{
if ( m_curveAppearance->symbol() != RiuPlotCurveSymbol::SYMBOL_NONE && m_plotCurve )
{
CAF_ASSERT( RiaGuiApplication::isRunning() );
QSizeF iconSize( 24, 24 );
QPixmap pixmap = m_plotCurve->legendIcon( iconSize );
setUiIcon( caf::IconProvider( pixmap ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::updateCurveVisibility()
{
if ( canCurveBeAttached() )
{
reattach();
}
else
{
detach();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimPlotCurve::dataSize() const
{
if ( m_plotCurve )
return m_plotCurve->numSamples();
else
return 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<double, double> RimPlotCurve::sample( int index ) const
{
CAF_ASSERT( m_plotCurve );
CAF_ASSERT( index >= 0 && index <= dataSize() );
return m_plotCurve->sample( index );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setParentPlotNoReplot( RiuPlotWidget* plotWidget )
{
if ( !plotWidget ) return;
m_parentPlot = plotWidget;
if ( !m_plotCurve )
{
m_plotCurve = m_parentPlot->createPlotCurve( this, "", RiaColorTools::toQColor( m_curveAppearance->color() ) );
}
m_plotCurve->attachToPlot( plotWidget );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setParentPlotAndReplot( RiuPlotWidget* plotWidget )
{
CAF_ASSERT( plotWidget );
setParentPlotNoReplot( plotWidget );
plotWidget->replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::attach( RiuPlotWidget* plotWidget )
{
setParentPlotAndReplot( plotWidget );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::detach()
{
if ( m_plotCurve )
{
m_plotCurve->detach();
}
replotParentPlot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::reattach()
{
if ( m_parentPlot ) attach( m_parentPlot );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotCurve::isSameCurve( const RiuPlotCurve* plotCurve ) const
{
return m_plotCurve == plotCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPlotCurve::curveName() const
{
return m_curveName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPlotCurve::curveExportDescription( const RifEclipseSummaryAddress& address ) const
{
return m_curveName;
}