mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9202 Summary Multi Plot: add option for having the legend inside the plot
This commit is contained in:
parent
be236cb644
commit
9d5a4e7939
@ -425,6 +425,7 @@ void RimSummaryMultiPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrde
|
|||||||
legendsGroup->setCollapsedByDefault( true );
|
legendsGroup->setCollapsedByDefault( true );
|
||||||
legendsGroup->add( &m_showPlotLegends );
|
legendsGroup->add( &m_showPlotLegends );
|
||||||
legendsGroup->add( &m_plotLegendsHorizontal );
|
legendsGroup->add( &m_plotLegendsHorizontal );
|
||||||
|
legendsGroup->add( &m_legendPosition );
|
||||||
legendsGroup->add( &m_legendFontSize );
|
legendsGroup->add( &m_legendFontSize );
|
||||||
|
|
||||||
uiOrdering.skipRemainingFields( true );
|
uiOrdering.skipRemainingFields( true );
|
||||||
|
@ -169,14 +169,13 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
|||||||
subTitle->setVisible( false );
|
subTitle->setVisible( false );
|
||||||
m_subTitles.insert( static_cast<int>( index ), subTitle );
|
m_subTitles.insert( static_cast<int>( index ), subTitle );
|
||||||
|
|
||||||
|
plotWidget->clearOverlayFrames();
|
||||||
|
|
||||||
RiuQwtPlotWidget* qwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
|
RiuQwtPlotWidget* qwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
|
||||||
|
|
||||||
RiuQwtPlotLegend* legend = new RiuQwtPlotLegend( this );
|
RiuQwtPlotLegend* legend = new RiuQwtPlotLegend( this );
|
||||||
RiuDraggableOverlayFrame* legendFrame = nullptr;
|
RiuDraggableOverlayFrame* legendFrame =
|
||||||
if ( qwtPlotWidget )
|
new RiuDraggableOverlayFrame( plotWidget->getParentForOverlay(), plotWidget->overlayMargins() );
|
||||||
{
|
|
||||||
legendFrame = new RiuDraggableOverlayFrame( qwtPlotWidget->qwtPlot()->canvas(), plotWidget->overlayMargins() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_plotDefinition->legendsVisible() && plotWidget->plotDefinition()->legendsVisible() )
|
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->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
|
||||||
legend->setVisible( false );
|
legend->setVisible( false );
|
||||||
|
|
||||||
|
legendFrame->setVisible( false );
|
||||||
|
|
||||||
plotWidget->updateLegend();
|
plotWidget->updateLegend();
|
||||||
}
|
}
|
||||||
m_legends.insert( static_cast<int>( index ), legend );
|
m_legends.insert( static_cast<int>( index ), legend );
|
||||||
@ -677,7 +678,6 @@ void RiuMultiPlotPage::reinsertPlotWidgets()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CAF_ASSERT( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE );
|
CAF_ASSERT( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE );
|
||||||
|
|
||||||
auto overlayFrame = new RiuQwtLegendOverlayContentFrame;
|
auto overlayFrame = new RiuQwtLegendOverlayContentFrame;
|
||||||
overlayFrame->setLegend( legends[visibleIndex] );
|
overlayFrame->setLegend( legends[visibleIndex] );
|
||||||
legendFrames[visibleIndex]->setContentFrame( overlayFrame );
|
legendFrames[visibleIndex]->setContentFrame( overlayFrame );
|
||||||
|
@ -168,6 +168,16 @@ void RiuPlotWidget::removeOverlayFrame( RiuDraggableOverlayFrame* overlayFrame )
|
|||||||
m_overlayFrames.removeOne( overlayFrame );
|
m_overlayFrames.removeOne( overlayFrame );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Remove all overlay widgets.
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuPlotWidget::clearOverlayFrames()
|
||||||
|
{
|
||||||
|
for ( auto p : m_overlayFrames )
|
||||||
|
p->deleteLater();
|
||||||
|
m_overlayFrames.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -165,6 +165,7 @@ public:
|
|||||||
|
|
||||||
void addOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
|
void addOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
|
||||||
void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
|
void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
|
||||||
|
void clearOverlayFrames();
|
||||||
virtual void updateLayout() = 0;
|
virtual void updateLayout() = 0;
|
||||||
|
|
||||||
virtual void renderTo( QPainter* painter, const QRect& targetRect, double scaling ) = 0;
|
virtual void renderTo( QPainter* painter, const QRect& targetRect, double scaling ) = 0;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "RimSummaryPlot.h"
|
#include "RimSummaryPlot.h"
|
||||||
|
|
||||||
#include "RiuPlotWidget.h"
|
#include "RiuPlotWidget.h"
|
||||||
|
#include "RiuQwtLegendOverlayContentFrame.h"
|
||||||
#include "RiuQwtPlotLegend.h"
|
#include "RiuQwtPlotLegend.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@ -69,9 +70,10 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
|
|||||||
int nCells = cols * rows;
|
int nCells = cols * rows;
|
||||||
reservePlaceholders( nCells - nPlots );
|
reservePlaceholders( nCells - nPlots );
|
||||||
|
|
||||||
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
|
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
|
||||||
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
|
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
|
||||||
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
|
QList<QPointer<RiuDraggableOverlayFrame>> legendFrames = this->legendFramesForVisiblePlots();
|
||||||
|
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
|
||||||
|
|
||||||
m_visibleIndexToPositionMapping.clear();
|
m_visibleIndexToPositionMapping.clear();
|
||||||
|
|
||||||
@ -101,7 +103,20 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
|
|||||||
m_gridLayout->addWidget( subTitles[visibleIndex], 3 * row, col, 1, colSpan );
|
m_gridLayout->addWidget( subTitles[visibleIndex], 3 * row, col, 1, colSpan );
|
||||||
if ( legends[visibleIndex] )
|
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 );
|
m_gridLayout->addWidget( plotWidget, 3 * row + 2, col, 1, colSpan );
|
||||||
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( plotWidget->plotDefinition() );
|
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( plotWidget->plotDefinition() );
|
||||||
@ -133,10 +148,20 @@ void RiuSummaryMultiPlotPage::reinsertPlotWidgets()
|
|||||||
updateLegendColumns( legends[visibleIndex] );
|
updateLegendColumns( legends[visibleIndex] );
|
||||||
updateLegendFont( legends[visibleIndex] );
|
updateLegendFont( legends[visibleIndex] );
|
||||||
legends[visibleIndex]->show();
|
legends[visibleIndex]->show();
|
||||||
|
|
||||||
|
if ( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE )
|
||||||
|
legendFrames[visibleIndex]->show();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plotWidget->removeOverlayFrame( legendFrames[visibleIndex] );
|
||||||
|
legendFrames[visibleIndex]->hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
legends[visibleIndex]->hide();
|
legends[visibleIndex]->hide();
|
||||||
|
legendFrames[visibleIndex]->hide();
|
||||||
|
plotWidget->removeOverlayFrame( legendFrames[visibleIndex] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set basic row and column stretches
|
// Set basic row and column stretches
|
||||||
|
Loading…
Reference in New Issue
Block a user