Simplify RiuPlotMainWindowTools (#9211)

* Janitor: Add and use onObjectAppended()
* Janitor: Simplify API
This commit is contained in:
Magne Sjaastad 2022-08-18 03:37:51 -07:00 committed by GitHub
parent febbdcf7a0
commit a1e7b64d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 66 additions and 93 deletions

View File

@ -96,9 +96,7 @@ void RicNewAnalysisPlotFeature::onActionTriggered( bool isChecked )
if ( analysisPlotColl ) analysisPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newPlot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -56,8 +56,7 @@ void RicNewPlotDataFilterFeature::onActionTriggered( bool isChecked )
analysisPlot->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newFilter );
RiuPlotMainWindowTools::selectAsCurrentItem( newFilter );
RiuPlotMainWindowTools::onObjectAppended( newFilter );
}
//--------------------------------------------------------------------------------------------------

View File

@ -175,11 +175,8 @@ RimStimPlanModelPlot* RicNewStimPlanModelPlotFeature::createPlot( RimStimPlanMod
plot->setAutoScaleDepthValuesEnabled( true );
}
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
RiuPlotMainWindowTools::refreshToolbars();
// Make sure the summary plot window is visible
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::onObjectAppended( plot );
plot->loadDataAndUpdate();

View File

@ -100,9 +100,7 @@ void RicNewCorrelationMatrixPlotFeature::onActionTriggered( bool isChecked )
if ( correlationPlotColl ) correlationPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newPlot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -95,9 +95,7 @@ void RicNewCorrelationPlotFeature::onActionTriggered( bool isChecked )
if ( correlationPlotColl ) correlationPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newPlot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -101,9 +101,7 @@ void RicNewCorrelationReportPlotFeature::onActionTriggered( bool isChecked )
if ( correlationPlotColl ) correlationPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newPlot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -105,9 +105,7 @@ void RicNewParameterResultCrossPlotFeature::onActionTriggered( bool isChecked )
if ( correlationPlotColl ) correlationPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newPlot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -81,10 +81,7 @@ void RicAddStoredFlowCharacteristicsPlotFeature::onActionTriggered( bool isCheck
flowPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( flowCharacteristicsPlot );
RiuPlotMainWindowTools::setExpanded( flowCharacteristicsPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( flowCharacteristicsPlot );
}
}
}

View File

@ -81,9 +81,7 @@ void RicAddStoredWellAllocationPlotFeature::onActionTriggered( bool isChecked )
flowPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( wellAllocationPlot );
RiuPlotMainWindowTools::setExpanded( wellAllocationPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( wellAllocationPlot );
}
}
}

View File

@ -96,9 +96,7 @@ void RicShowFlowCharacteristicsPlotFeature::onActionTriggered( bool isChecked )
flowPlotColl->defaultFlowCharacteristicsPlot()->setFromFlowSolution( eclCase->defaultFlowDiagSolution() );
flowPlotColl->defaultFlowCharacteristicsPlot()->updateConnectedEditors();
// Make sure the summary plot window is created and visible
RiuPlotMainWindowTools::selectAsCurrentItem( flowPlotColl->defaultFlowCharacteristicsPlot() );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( flowPlotColl->defaultFlowCharacteristicsPlot() );
}
}
}

View File

@ -111,10 +111,8 @@ void RicShowWellAllocationPlotFeature::onActionTriggered( bool isChecked )
flowPlotColl->defaultWellAllocPlot()->setFromSimulationWell( simWell );
flowPlotColl->defaultWellAllocPlot()->updateConnectedEditors();
// Make sure the summary plot window is created and visible
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( flowPlotColl->defaultWellAllocPlot() );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( flowPlotColl->defaultWellAllocPlot() );
}
}
}

View File

@ -82,8 +82,8 @@ void RicCreateGridCrossPlotFeature::onActionTriggered( bool isChecked )
collection->updateAllRequiredEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( dataSet );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( dataSet );
}
//--------------------------------------------------------------------------------------------------

View File

@ -199,8 +199,7 @@ void RicCreateSaturationPressurePlotsFeature::onActionTriggered( bool isChecked
if ( objectToSelect )
{
RiuPlotMainWindowTools::selectAsCurrentItem( objectToSelect );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( objectToSelect );
}
}

View File

@ -342,11 +342,11 @@ RimMultiPlot* RicSummaryPlotBuilder::createAndAppendMultiPlot( const std::vector
if ( !plots.empty() )
{
RiuPlotMainWindowTools::selectAsCurrentItem( plots[0], true );
RiuPlotMainWindowTools::selectAsCurrentItem( plots[0] );
}
else
{
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true );
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow );
}
return plotWindow;
@ -374,12 +374,12 @@ RimSummaryMultiPlot*
if ( plotWindow->summaryPlots().size() == 1 )
{
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow->summaryPlots()[0] );
RiuPlotMainWindowTools::setExpanded( plotWindow->summaryPlots()[0], true );
RiuPlotMainWindowTools::setExpanded( plotWindow->summaryPlots()[0] );
}
else
{
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow );
RiuPlotMainWindowTools::setExpanded( plotWindow, true );
RiuPlotMainWindowTools::setExpanded( plotWindow );
}
return plotWindow;

View File

@ -59,8 +59,7 @@ void RicCreateEnsembleFractureStatisticsPlotFeature::onActionTriggered( bool isC
collection->addEnsembleFractureStatisticsPlot( plot );
collection->updateAllRequiredEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -272,8 +272,7 @@ void RicCreateEnsembleWellLogFeature::executeCommand( const RicCreateEnsembleWel
wellLogPlot->updateConnectedEditors();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( wellLogPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( wellLogPlot );
}
}
}

View File

@ -64,8 +64,7 @@ void RicCreateGridStatisticsPlotFeature::onActionTriggered( bool isChecked )
collection->addGridStatisticsPlot( plot );
collection->updateAllRequiredEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -143,9 +143,7 @@ bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles( const QStr
if ( plotToSelect )
{
RiuPlotMainWindowTools::setExpanded( plotToSelect );
RiuPlotMainWindowTools::selectAsCurrentItem( plotToSelect );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plotToSelect );
}
}

View File

@ -56,8 +56,7 @@ void RicNewCustomObjectiveFunctionWeightFeature::onActionTriggered( bool isCheck
auto newWeight = RimObjectiveFunctionTools::addWeight( firstObjectiveFunction );
firstObjectiveFunction->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( newWeight );
RiuPlotMainWindowTools::setExpanded( func.front() );
RiuPlotMainWindowTools::onObjectAppended( newWeight, func.front() );
}
selObj->updateConnectedEditors();

View File

@ -97,8 +97,7 @@ void RicNewVfpPlotFeature::onActionTriggered( bool isChecked )
if ( !vfpPlots.empty() )
{
RiuPlotMainWindowTools::selectAsCurrentItem( vfpPlots.front() );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( vfpPlots.front() );
}
}
}

View File

@ -75,9 +75,7 @@ void RicNewSummaryCrossPlotCurveFeature::onActionTriggered( bool isChecked )
plot->updateConnectedEditors();
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem( newCurve );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( newCurve );
}
}

View File

@ -88,9 +88,7 @@ void RicNewSummaryCrossPlotFeature::onActionTriggered( bool isChecked )
summaryPlot->loadDataAndUpdate();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( summaryPlot );
RiuPlotMainWindowTools::setExpanded( summaryPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( summaryPlot );
}
}

View File

@ -105,9 +105,7 @@ void RicAddWellLogToPlotFeature::onActionTriggered( bool isChecked )
plot->updateLayout();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
RiuPlotMainWindowTools::setExpanded( plotTrack );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plot, plotTrack );
}
//--------------------------------------------------------------------------------------------------

View File

@ -52,9 +52,9 @@ void RicNewEnsembleWellLogCurveSetFeature::onActionTriggered( bool isChecked )
RimEnsembleWellLogCurveSet* curveSet = new RimEnsembleWellLogCurveSet();
wellLogPlotTrack->setEnsembleWellLogCurveSet( curveSet );
wellLogPlotTrack->updateEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( curveSet );
RiuPlotMainWindowTools::onObjectAppended( curveSet );
}
RiuPlotMainWindowTools::refreshToolbars();
}
//--------------------------------------------------------------------------------------------------

View File

@ -121,9 +121,7 @@ void RicNewPltPlotFeature::onActionTriggered( bool isChecked )
pltPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::setExpanded( plotTrack );
RiuPlotMainWindowTools::selectAsCurrentItem( pltPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( pltPlot, plotTrack );
}
}

View File

@ -85,9 +85,7 @@ void RicNewRftPlotFeature::onActionTriggered( bool isChecked )
rftPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::setExpanded( plotTrack );
RiuPlotMainWindowTools::selectAsCurrentItem( rftPlot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( rftPlot, plotTrack );
}
}

View File

@ -84,8 +84,7 @@ void RicNewRftSegmentWellLogPlotFeature::onActionTriggered( bool isChecked )
appendTrackAndCurveForBranchType( plot, resultName, branchType, summaryCase );
}
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plot );
}
//--------------------------------------------------------------------------------------------------

View File

@ -76,10 +76,7 @@ void RicNewRftWellLogPlotFeature::onActionTriggered( bool isChecked )
curve->updateAllRequiredEditors();
RiuPlotMainWindowTools::setExpanded( curve );
RiuPlotMainWindowTools::selectAsCurrentItem( curve );
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( curve );
}
//--------------------------------------------------------------------------------------------------

View File

@ -120,11 +120,8 @@ RimWellBoreStabilityPlot*
RicNewWellLogPlotFeatureImpl::updateAfterCreation( plot );
}
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
// Make sure the summary plot window is visible
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::refreshToolbars();
RiuPlotMainWindowTools::onObjectAppended( plot );
return plot;
}

View File

@ -122,8 +122,7 @@ bool RimObservedDataCollection::fileExists( const QString& fileName, QString* er
void updateNewObservedDataCreated( caf::PdmObject* object )
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( object );
RiuPlotMainWindowTools::setExpanded( object );
RiuPlotMainWindowTools::onObjectAppended( object );
caf::PdmUiObjectEditorHandle::updateUiAllObjectEditors();

View File

@ -1397,7 +1397,7 @@ void RimSummaryMultiPlot::appendSubPlotByStepping( int direction )
loadDataAndUpdate();
updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( newPlots.back(), true );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlots.back() );
updateSourceStepper();
RiuPlotMainWindowTools::refreshToolbars();

View File

@ -174,7 +174,7 @@ void RimSummaryMultiPlotCollection::duplicatePlot( RimSummaryMultiPlot* plotToDu
updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( plotCopy, true );
RiuPlotMainWindowTools::selectAsCurrentItem( plotCopy );
}
//--------------------------------------------------------------------------------------------------

View File

@ -47,25 +47,27 @@ void RiuPlotMainWindowTools::setActiveViewer( QWidget* subWindow )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::setExpanded( const caf::PdmUiItem* uiItem, bool expanded /*= true*/ )
void RiuPlotMainWindowTools::setExpanded( const caf::PdmUiItem* uiItem )
{
if ( RiaGuiApplication::isRunning() )
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
if ( mpw ) mpw->setExpanded( uiItem, expanded );
bool expand = true;
if ( mpw ) mpw->setExpanded( uiItem, expand );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::selectAsCurrentItem( const caf::PdmObject* object, bool allowActiveViewChange /*= true*/ )
void RiuPlotMainWindowTools::selectAsCurrentItem( const caf::PdmObject* object )
{
if ( RiaGuiApplication::isRunning() )
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
bool allowActiveViewChange = true;
if ( mpw ) mpw->selectAsCurrentItem( object, allowActiveViewChange );
}
}
@ -73,12 +75,13 @@ void RiuPlotMainWindowTools::selectAsCurrentItem( const caf::PdmObject* object,
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::toggleItemInSelection( const caf::PdmObject* object, bool allowActiveViewChange /*= true*/ )
void RiuPlotMainWindowTools::toggleItemInSelection( const caf::PdmObject* object )
{
if ( RiaGuiApplication::isRunning() )
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
bool allowActiveViewChange = true;
if ( mpw ) mpw->toggleItemInSelection( object, allowActiveViewChange );
}
}
@ -114,3 +117,16 @@ void RiuPlotMainWindowTools::refreshToolbars()
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::onObjectAppended( const caf::PdmObject* objectToSelect, const caf::PdmObject* objectToExpand )
{
if ( objectToExpand == nullptr ) objectToExpand = objectToSelect;
if ( objectToExpand ) RiuPlotMainWindowTools::setExpanded( objectToExpand );
if ( objectToSelect ) RiuPlotMainWindowTools::selectAsCurrentItem( objectToSelect );
RiuPlotMainWindowTools::refreshToolbars();
}

View File

@ -31,9 +31,15 @@ class RiuPlotMainWindowTools
public:
static void showPlotMainWindow();
static void setActiveViewer( QWidget* subWindow );
static void setExpanded( const caf::PdmUiItem* uiItem, bool expanded = true );
static void selectAsCurrentItem( const caf::PdmObject* object, bool allowActiveViewChange = true );
static void toggleItemInSelection( const caf::PdmObject* object, bool allowActiveViewChange = true );
static void setExpanded( const caf::PdmUiItem* uiItem );
static void selectAsCurrentItem( const caf::PdmObject* object );
static void selectOrToggleObject( const caf::PdmObject* object, bool toggle );
static void refreshToolbars();
// Use this function to select (and expand) an object in the project tree and update tool bars. Use the second
// parameter to expand a different object than the object to be selected.
static void onObjectAppended( const caf::PdmObject* objectToSelect, const caf::PdmObject* objectToExpand = nullptr );
private:
static void toggleItemInSelection( const caf::PdmObject* object );
};