diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp index cc85235e62..28b5a8b808 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicSummaryPlotEditorUi.cpp @@ -97,6 +97,7 @@ RicSummaryPlotEditorUi::RicSummaryPlotEditorUi() CAF_PDM_InitFieldNoDefault( &m_regionAppearanceType, "RegionAppearanceType", "Region" ); m_previewPlot = std::make_unique(); + m_previewPlot->setLegendPosition( RiuPlotWidget::Legend::TOP ); CAF_PDM_InitFieldNoDefault( &m_applyButtonField, "ApplySelection", "" ); m_applyButtonField = false; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index bc68f9e6a1..f8837fed73 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -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(); } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h index 3a5e96101c..f6e52613b6 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -162,6 +162,7 @@ public: void updateAll(); void updateLegend() override; + void setLegendPosition( RiuPlotWidget::Legend position ); void setPlotInfoLabel( const QString& label ); void showPlotInfoLabel( bool show ); @@ -352,5 +353,6 @@ private: std::unique_ptr m_nameHelperAllCurves; caf::PdmChildField m_sourceStepping; - bool m_isValid; + bool m_isValid; + RiuPlotWidget::Legend m_legendPosition; }; diff --git a/ApplicationLibCode/UserInterface/RiuPlotWidget.h b/ApplicationLibCode/UserInterface/RiuPlotWidget.h index 5885c06544..8668b6a1a6 100644 --- a/ApplicationLibCode/UserInterface/RiuPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuPlotWidget.h @@ -117,11 +117,10 @@ public: virtual bool plotTitleEnabled() const = 0; 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; + virtual void setLegendFontSize( int fontSize ) = 0; + virtual void insertLegend( RiuPlotWidget::Legend ) = 0; + virtual void clearLegend() = 0; + virtual void updateLegend() = 0; virtual void detachItems( RiuPlotWidget::PlotItemType plotItemType ) = 0; diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp index ba8351b023..9b40d74598 100644 --- a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp @@ -287,21 +287,6 @@ void RiuQtChartsPlotWidget::setLegendFontSize( int fontSize ) } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQtChartsPlotWidget::setInternalLegendVisible( bool visible ) -{ - if ( visible ) - { - insertLegend( RiuPlotWidget::Legend::BOTTOM ); - } - else - { - clearLegend(); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h index 470168cc9f..68bb3274dc 100644 --- a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h @@ -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; diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp index d80a1e58f9..edee3ec0ad 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp @@ -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 ); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h index 491070b391..5f34909a0c 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h @@ -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; diff --git a/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp index 4f9f10b4c2..1429eed536 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp @@ -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 ); } //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp index dfea11f16c..f821b33fac 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -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( new RiuPlotAnnotationTool() ); }