Add support for placing legend at several positions

Show legends on top of preview plot
This commit is contained in:
Magne Sjaastad 2023-11-23 17:13:47 +01:00
parent 243b07c42f
commit 4b0f2b362e
10 changed files with 35 additions and 43 deletions

View File

@ -97,6 +97,7 @@ RicSummaryPlotEditorUi::RicSummaryPlotEditorUi()
CAF_PDM_InitFieldNoDefault( &m_regionAppearanceType, "RegionAppearanceType", "Region" );
m_previewPlot = std::make_unique<RimSummaryPlot>();
m_previewPlot->setLegendPosition( RiuPlotWidget::Legend::TOP );
CAF_PDM_InitFieldNoDefault( &m_applyButtonField, "ApplySelection", "" );
m_applyButtonField = false;

View File

@ -128,6 +128,7 @@ RimSummaryPlot::RimSummaryPlot()
, m_isValid( true )
, axisChangedReloadRequired( this )
, autoTitleChanged( this )
, m_legendPosition( RiuPlotWidget::Legend::BOTTOM )
{
CAF_PDM_InitScriptableObject( "Summary Plot", ":/SummaryPlotLight16x16.png", "", "A Summary Plot" );
@ -690,7 +691,14 @@ void RimSummaryPlot::updateLegend()
{
if ( plotWidget() )
{
plotWidget()->setInternalLegendVisible( m_showPlotLegends && !isSubPlot() );
if ( m_showPlotLegends && !isSubPlot() )
{
plotWidget()->insertLegend( m_legendPosition );
}
else
{
plotWidget()->clearLegend();
}
for ( auto c : summaryCurves() )
{
@ -705,6 +713,14 @@ void RimSummaryPlot::updateLegend()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setLegendPosition( RiuPlotWidget::Legend position )
{
m_legendPosition = position;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1941,7 +1957,14 @@ void RimSummaryPlot::onLoadDataAndUpdate()
if ( plotWidget() )
{
plotWidget()->setInternalLegendVisible( m_showPlotLegends && !isSubPlot() );
if ( m_showPlotLegends && !isSubPlot() )
{
plotWidget()->insertLegend( m_legendPosition );
}
else
{
plotWidget()->clearLegend();
}
plotWidget()->setLegendFontSize( legendFontSize() );
plotWidget()->updateLegend();
}

View File

@ -162,6 +162,7 @@ public:
void updateAll();
void updateLegend() override;
void setLegendPosition( RiuPlotWidget::Legend position );
void setPlotInfoLabel( const QString& label );
void showPlotInfoLabel( bool show );
@ -353,4 +354,5 @@ private:
caf::PdmChildField<RimSummaryPlotSourceStepping*> m_sourceStepping;
bool m_isValid;
RiuPlotWidget::Legend m_legendPosition;
};

View File

@ -118,7 +118,6 @@ public:
virtual void setPlotTitleFontSize( int titleFontSize ) = 0;
virtual void setLegendFontSize( int fontSize ) = 0;
virtual void setInternalLegendVisible( bool visible ) = 0;
virtual void insertLegend( RiuPlotWidget::Legend ) = 0;
virtual void clearLegend() = 0;
virtual void updateLegend() = 0;

View File

@ -287,21 +287,6 @@ void RiuQtChartsPlotWidget::setLegendFontSize( int fontSize )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQtChartsPlotWidget::setInternalLegendVisible( bool visible )
{
if ( visible )
{
insertLegend( RiuPlotWidget::Legend::BOTTOM );
}
else
{
clearLegend();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -112,7 +112,6 @@ public:
void setPlotTitleFontSize( int titleFontSize ) override;
void setLegendFontSize( int fontSize ) override;
void setInternalLegendVisible( bool visible ) override;
void insertLegend( RiuPlotWidget::Legend ) override;
void clearLegend() override;

View File

@ -270,22 +270,6 @@ void RiuQwtPlotWidget::setLegendFontSize( int fontSize )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setInternalLegendVisible( bool visible )
{
if ( visible )
{
auto* legend = new QwtLegend( this );
m_plot->insertLegend( legend, QwtPlot::BottomLegend );
}
else
{
m_plot->insertLegend( nullptr );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -103,7 +103,6 @@ public:
void setPlotTitleFontSize( int titleFontSize ) override;
void setLegendFontSize( int fontSize ) override;
void setInternalLegendVisible( bool visible ) override;
void insertLegend( RiuPlotWidget::Legend ) override;
void clearLegend() override;

View File

@ -42,7 +42,7 @@ RiuSummaryQtChartsPlot::RiuSummaryQtChartsPlot( RimSummaryPlot* plot, QWidget* p
RiuQtChartsPlotTools::setCommonPlotBehaviour( m_plotWidget );
RiuQtChartsPlotTools::setDefaultAxes( m_plotWidget );
m_plotWidget->setInternalLegendVisible( true );
m_plotWidget->insertLegend( RiuPlotWidget::Legend::BOTTOM );
}
//--------------------------------------------------------------------------------------------------
///

View File

@ -103,7 +103,7 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
// PERFORMANCE NOTE
// Do not set internal legends visible, as this will cause a performance hit.
m_plotWidget->setInternalLegendVisible( false );
m_plotWidget->clearLegend();
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>( new RiuPlotAnnotationTool() );
}