Missing legend (#9095)

* Make sure ensemble curveset legends are shown in multiplot legend.
* Remove information already shown in title from curve legend.
* Fix missing legend when creating curve plot from ensemble curves
* Show actual curve color in legend
This commit is contained in:
jonjenssen 2022-06-29 11:49:46 +02:00 committed by GitHub
parent aeab09eceb
commit d4ff0a0175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 28 deletions

View File

@ -49,6 +49,8 @@ void RicNewSummaryPlotFromCurveFeature::onActionTriggered( bool isChecked )
auto curveCopy =
dynamic_cast<RimSummaryCurve*>( curve->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
curveCopy->setShowInLegend( true );
RimSummaryPlot* plot = RicSummaryPlotBuilder::createPlot( { curveCopy } );
std::vector<RimSummaryPlot*> plots = { plot };

View File

@ -304,11 +304,6 @@ void RimEnsembleCurveSet::setParentPlotNoReplot( RiuPlotWidget* plot )
{
curve->setParentPlotNoReplot( plot );
}
if ( !m_plotCurveForLegendText )
{
m_plotCurveForLegendText = plot->createPlotCurve( nullptr, "", Qt::black );
}
}
//--------------------------------------------------------------------------------------------------
@ -338,15 +333,6 @@ void RimEnsembleCurveSet::reattachPlotCurves()
{
curve->reattach();
}
if ( m_plotCurveForLegendText )
{
m_plotCurveForLegendText->detach();
RimSummaryPlot* plot = nullptr;
firstAncestorOrThisOfType( plot );
if ( plot && plot->plotWidget() ) m_plotCurveForLegendText->attachToPlot( plot->plotWidget() );
}
}
//--------------------------------------------------------------------------------------------------
@ -625,15 +611,6 @@ void RimEnsembleCurveSet::fieldChangedByUi( const caf::PdmFieldHandle* changedFi
if ( changedField == &m_showCurves )
{
if ( !m_showCurves() && m_plotCurveForLegendText )
{
// Need to detach the legend since the plot type might change from Qwt to QtCharts.
// The plot curve for legend text needs to be recreated when curves are shown next time.
m_plotCurveForLegendText->detach();
delete m_plotCurveForLegendText;
m_plotCurveForLegendText = nullptr;
}
loadDataAndUpdate( true );
updateConnectedEditors();
@ -1589,6 +1566,11 @@ void RimEnsembleCurveSet::updateCurveColors()
curvesToColor[i]->updateCurveAppearance();
}
if ( m_plotCurveForLegendText )
{
m_plotCurveForLegendText->setColor( RiaColorTools::toQColor( m_color ) );
}
RimSummaryPlot* plot;
firstAncestorOrThisOfType( plot );
if ( plot && plot->plotWidget() )
@ -1730,9 +1712,6 @@ void RimEnsembleCurveSet::updateEnsembleCurves( const std::vector<RimSummaryCase
newSummaryCurves[i]->updatePlotAxis();
newSummaryCurves[i]->setShowInLegend( false );
}
if ( plot->plotWidget() && m_plotCurveForLegendText )
m_plotCurveForLegendText->attachToPlot( plot->plotWidget() );
}
if ( plot->plotWidget() )
@ -1741,6 +1720,14 @@ void RimEnsembleCurveSet::updateEnsembleCurves( const std::vector<RimSummaryCase
plot->scheduleReplotIfVisible();
plot->updateAxes();
plot->updatePlotInfoLabel();
if ( !m_plotCurveForLegendText )
{
m_plotCurveForLegendText =
plot->plotWidget()->createPlotCurve( nullptr, "", RiaColorTools::toQColor( m_color ) );
}
m_plotCurveForLegendText->attachToPlot( plot->plotWidget() );
updateEnsembleLegendItem();
}
}
updateCurveColors();
@ -2044,8 +2031,8 @@ QString RimEnsembleCurveSet::createAutoName() const
RimSummaryPlot* plot = nullptr;
firstAncestorOrThisOfTypeAsserted( plot );
QString curveSetName = m_summaryAddressNameTools->curveNameY( m_yValuesSummaryAddress->address(),
plot->activePlotTitleHelperAllCurves() );
QString curveSetName =
m_summaryAddressNameTools->curveNameY( m_yValuesSummaryAddress->address(), plot->plotTitleHelper() );
if ( curveSetName.isEmpty() )
{
curveSetName = m_summaryAddressNameTools->curveNameY( m_yValuesSummaryAddress->address(), nullptr );

View File

@ -94,6 +94,7 @@ public:
const QBrush& fillBrush = QBrush( Qt::NoBrush ) ) = 0;
virtual void setBrush( const QBrush& brush ) = 0;
virtual void setColor( const QColor& color ) = 0;
void setBlackAndWhiteLegendIcon( bool blackAndWhite );
virtual void setVisibleInLegend( bool isVisibleInLegend ) = 0;

View File

@ -164,6 +164,20 @@ void RiuQtChartsPlotCurve::setBrush( const QBrush& brush )
areaSeries()->setBrush( brush );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQtChartsPlotCurve::setColor( const QColor& color )
{
QPen curvePen = lineSeries()->pen();
curvePen.setColor( color );
lineSeries()->setPen( curvePen );
curvePen = areaSeries()->pen();
curvePen.setColor( color );
areaSeries()->setPen( curvePen );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -49,6 +49,7 @@ public:
const QBrush& fillBrush = QBrush( Qt::NoBrush ) ) override;
void setBrush( const QBrush& brush ) override;
void setColor( const QColor& color ) override;
void setLegendIconSize( const QSize& iconSize ) override;
QSize legendIconSize() const override;

View File

@ -263,6 +263,16 @@ void RiuQwtPlotCurve::setBrush( const QBrush& brush )
QwtPlotCurve::setBrush( brush );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotCurve::setColor( const QColor& color )
{
QPen curvePen = pen();
curvePen.setColor( color );
setPen( curvePen );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -45,6 +45,7 @@ public:
const QBrush& fillBrush = QBrush( Qt::NoBrush ) ) override;
void setBrush( const QBrush& brush ) override;
void setColor( const QColor& color ) override;
void setLegendIconSize( const QSize& iconSize ) override;
QSize legendIconSize() const override;