#9202 Summary Multi Plot: add option for having the legend inside the plot

This commit is contained in:
Kristian Bendiksen 2022-08-17 14:38:16 +02:00 committed by Magne Sjaastad
parent 318f187635
commit f9f49e9f58
5 changed files with 48 additions and 11 deletions

View File

@ -425,6 +425,7 @@ void RimSummaryMultiPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrde
legendsGroup->setCollapsedByDefault( true );
legendsGroup->add( &m_showPlotLegends );
legendsGroup->add( &m_plotLegendsHorizontal );
legendsGroup->add( &m_legendPosition );
legendsGroup->add( &m_legendFontSize );
uiOrdering.skipRemainingFields( true );

View File

@ -169,14 +169,13 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
subTitle->setVisible( false );
m_subTitles.insert( static_cast<int>( index ), subTitle );
plotWidget->clearOverlayFrames();
RiuQwtPlotWidget* qwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
RiuQwtPlotLegend* legend = new RiuQwtPlotLegend( this );
RiuDraggableOverlayFrame* legendFrame = nullptr;
if ( qwtPlotWidget )
{
legendFrame = new RiuDraggableOverlayFrame( qwtPlotWidget->qwtPlot()->canvas(), plotWidget->overlayMargins() );
}
RiuQwtPlotLegend* legend = new RiuQwtPlotLegend( this );
RiuDraggableOverlayFrame* legendFrame =
new RiuDraggableOverlayFrame( plotWidget->getParentForOverlay(), plotWidget->overlayMargins() );
if ( m_plotDefinition->legendsVisible() && plotWidget->plotDefinition()->legendsVisible() )
{
@ -209,6 +208,8 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
legend->setVisible( false );
legendFrame->setVisible( false );
plotWidget->updateLegend();
}
m_legends.insert( static_cast<int>( index ), legend );
@ -677,7 +678,6 @@ void RiuMultiPlotPage::reinsertPlotWidgets()
else
{
CAF_ASSERT( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE );
auto overlayFrame = new RiuQwtLegendOverlayContentFrame;
overlayFrame->setLegend( legends[visibleIndex] );
legendFrames[visibleIndex]->setContentFrame( overlayFrame );

View File

@ -168,6 +168,16 @@ void RiuPlotWidget::removeOverlayFrame( RiuDraggableOverlayFrame* overlayFrame )
m_overlayFrames.removeOne( overlayFrame );
}
//--------------------------------------------------------------------------------------------------
/// Remove all overlay widgets.
//--------------------------------------------------------------------------------------------------
void RiuPlotWidget::clearOverlayFrames()
{
for ( auto p : m_overlayFrames )
p->deleteLater();
m_overlayFrames.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -165,6 +165,7 @@ public:
void addOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
void clearOverlayFrames();
virtual void updateLayout() = 0;
virtual void renderTo( QPainter* painter, const QRect& targetRect, double scaling ) = 0;

View File

@ -22,6 +22,7 @@
#include "RimSummaryPlot.h"
#include "RiuPlotWidget.h"
#include "RiuQwtLegendOverlayContentFrame.h"
#include "RiuQwtPlotLegend.h"
#include <QLabel>
@ -69,9 +70,10 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
int nCells = cols * rows;
reservePlaceholders( nCells - nPlots );
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
QList<QPointer<RiuDraggableOverlayFrame>> legendFrames = this->legendFramesForVisiblePlots();
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
m_visibleIndexToPositionMapping.clear();
@ -101,7 +103,20 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
m_gridLayout->addWidget( subTitles[visibleIndex], 3 * row, col, 1, colSpan );
if ( legends[visibleIndex] )
{
m_gridLayout->addWidget( legends[visibleIndex], 3 * row + 1, col, 1, colSpan, Qt::AlignHCenter | Qt::AlignBottom );
if ( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::ABOVE )
{
m_gridLayout->addWidget( legends[visibleIndex], 3 * row + 1, col, 1, colSpan, Qt::AlignHCenter | Qt::AlignBottom );
}
else
{
CAF_ASSERT( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE );
auto overlayFrame = new RiuQwtLegendOverlayContentFrame;
overlayFrame->setLegend( legends[visibleIndex] );
legendFrames[visibleIndex]->setContentFrame( overlayFrame );
legendFrames[visibleIndex]->setAnchorCorner( RiuDraggableOverlayFrame::AnchorCorner::TopRight );
plotWidgets[visibleIndex]->removeOverlayFrame( legendFrames[visibleIndex] );
plotWidgets[visibleIndex]->addOverlayFrame( legendFrames[visibleIndex] );
}
}
m_gridLayout->addWidget( plotWidget, 3 * row + 2, col, 1, colSpan );
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( plotWidget->plotDefinition() );
@ -133,10 +148,20 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
updateLegendColumns( legends[visibleIndex] );
updateLegendFont( legends[visibleIndex] );
legends[visibleIndex]->show();
if ( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE )
legendFrames[visibleIndex]->show();
else
{
plotWidget->removeOverlayFrame( legendFrames[visibleIndex] );
legendFrames[visibleIndex]->hide();
}
}
else
{
legends[visibleIndex]->hide();
legendFrames[visibleIndex]->hide();
plotWidget->removeOverlayFrame( legendFrames[visibleIndex] );
}
}
// Set basic row and column stretches