Enable reordering of plots within a multiplot

This commit is contained in:
Gaute Lindkvist 2020-09-16 13:10:37 +02:00 committed by Magne Sjaastad
parent a3161047af
commit ab3e43d8fb
4 changed files with 32 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "RiuPlotMainWindow.h"
#include "RiuPlotMainWindowTools.h"
#include "cafPdmFieldReorderCapability.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiToolButtonEditor.h"
@ -74,6 +75,8 @@ RimMultiPlot::RimMultiPlot()
CAF_PDM_InitFieldNoDefault( &m_plots, "Plots", "", "", "", "" );
m_plots.uiCapability()->setUiHidden( true );
auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_plots );
reorderability->orderChanged.connect( this, &RimMultiPlot::onPlotsReordered );
CAF_PDM_InitFieldNoDefault( &m_columnCount, "NumberOfColumns", "Number of Columns", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_rowsPerPage, "RowsPerPage", "Rows per Page", "", "", "" );
@ -203,6 +206,8 @@ void RimMultiPlot::insertPlot( RimPlot* plot, size_t index )
m_viewer->insertPlot( plot->viewer(), index );
}
plot->setShowWindow( true );
plot->setLegendsVisible( false );
plot->setPlotTitleVisible( false );
plot->updateAfterInsertingIntoMultiPlot();
onPlotAdditionOrRemoval();
@ -484,6 +489,16 @@ void RimMultiPlot::onPlotAdditionOrRemoval()
RiuPlotMainWindowTools::refreshToolbars();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimMultiPlot::onPlotsReordered( const caf::SignalEmitter* emitter )
{
updateSubPlotNames();
recreatePlotWidgets();
loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -704,6 +719,7 @@ void RimMultiPlot::onLoadDataAndUpdate()
applyPlotWindowTitleToWidgets();
updatePlots();
updateLayout();
RiuPlotMainWindowTools::refreshToolbars();
}
//--------------------------------------------------------------------------------------------------
@ -760,6 +776,8 @@ void RimMultiPlot::recreatePlotWidgets()
{
CVF_ASSERT( m_viewer );
m_viewer->removeAllPlots();
auto plotVector = plots();
for ( size_t tIdx = 0; tIdx < plotVector.size(); ++tIdx )

View File

@ -135,6 +135,7 @@ private:
void updatePlotWindowTitle();
void doRenderWindowContent( QPaintDevice* paintDevice ) override;
void onPlotAdditionOrRemoval();
void onPlotsReordered( const caf::SignalEmitter* emitter );
protected:
caf::PdmField<bool> m_showPlotWindowTitle;

View File

@ -186,6 +186,18 @@ void RiuMultiPlotBook::removePlot( RiuQwtPlotWidget* plotWidget )
scheduleUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::removeAllPlots()
{
auto plotWidgets = m_plotWidgets;
for ( RiuQwtPlotWidget* plotWidget : plotWidgets )
{
removePlot( plotWidget );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -67,6 +67,7 @@ public:
void addPlot( RiuQwtPlotWidget* plotWidget );
void insertPlot( RiuQwtPlotWidget* plotWidget, size_t index );
void removePlot( RiuQwtPlotWidget* plotWidget );
void removeAllPlots();
void setPlotTitle( const QString& plotTitle );