#7107 Ensemble curves : Remove custom delete features, use default delete

Co-authored-by: Ruben Thoms <ruben.thoms@ceetronsolutions.com>
This commit is contained in:
Magne Sjaastad 2020-12-11 14:17:33 +01:00
parent 3af48f4109
commit b5729d538f
11 changed files with 6 additions and 309 deletions

View File

@ -95,7 +95,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RicThemeColorEditorFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewVfpPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeleteCustomObjectiveFunctionFeature.h
)
@ -195,7 +194,6 @@ ${CMAKE_CURRENT_LIST_DIR}/RicThemeColorEditorFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewVfpPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeleteCustomObjectiveFunctionFeature.cpp
)
if(Qt5Charts_FOUND)

View File

@ -1,70 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicDeleteCustomObjectiveFunctionFeature.h"
#include "RimCustomObjectiveFunction.h"
#include "RimCustomObjectiveFunctionCollection.h"
#include "RimEnsembleCurveSet.h"
#include "RiuPlotMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicDeleteCustomObjectiveFunctionFeature, "RicDeleteCustomObjectiveFunctionFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicDeleteCustomObjectiveFunctionFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteCustomObjectiveFunctionFeature::onActionTriggered( bool isChecked )
{
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
std::vector<RimCustomObjectiveFunction*> func;
selObj->allAncestorsOrThisOfType( func );
std::vector<RimCustomObjectiveFunctionCollection*> coll;
selObj->allAncestorsOrThisOfType( coll );
if ( func.size() == 1 && coll.size() == 1 )
{
coll[0]->removeObjectiveFunction( func[0] );
coll[0]->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( coll.front() );
}
selObj->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteCustomObjectiveFunctionFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Delete" );
actionToSetup->setShortcut( QKeySequence( QKeySequence::Delete ) );
actionToSetup->setIcon( QIcon( ":/Erase.svg" ) );
}

View File

@ -1,35 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicDeleteCustomObjectiveFunctionFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -1,68 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicDeleteCustomObjectiveFunctionWeightFeature.h"
#include "RimCustomObjectiveFunction.h"
#include "RimCustomObjectiveFunctionWeight.h"
#include "RiuPlotMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicDeleteCustomObjectiveFunctionWeightFeature, "RicDeleteCustomObjectiveFunctionWeightFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicDeleteCustomObjectiveFunctionWeightFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteCustomObjectiveFunctionWeightFeature::onActionTriggered( bool isChecked )
{
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
std::vector<RimCustomObjectiveFunction*> func;
selObj->descendantsIncludingThisOfType( func );
std::vector<RimCustomObjectiveFunctionWeight*> weight;
selObj->descendantsIncludingThisOfType( weight );
if ( func.size() == 1 && weight.size() == 1 )
{
func[0]->removeWeight( weight[0] );
func[0]->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( func.front() );
}
selObj->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteCustomObjectiveFunctionWeightFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Delete" );
actionToSetup->setIcon( QIcon( ":/Erase.svg" ) );
}

View File

@ -1,35 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicDeleteCustomObjectiveFunctionWeightFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -728,8 +728,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimCustomObjectiveFunction*>( firstUiItem ) )
{
menuBuilder << "RicNewCustomObjectiveFunctionWeightFeature";
menuBuilder << "Separator";
menuBuilder << "RicDeleteCustomObjectiveFunctionFeature";
}
else if ( dynamic_cast<RimEnsembleCurveFilterCollection*>( firstUiItem ) )
{

View File

@ -30,13 +30,6 @@
CAF_PDM_SOURCE_INIT( RimCustomObjectiveFunction, "RimCustomObjectiveFunction" );
//--------------------------------------------------------------------------------------------------
/// Internal variables
//--------------------------------------------------------------------------------------------------
static std::vector<RimCustomObjectiveFunctionWeight*> _removedWeights;
static void garbageCollectWeights();
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -53,6 +46,8 @@ RimCustomObjectiveFunction::RimCustomObjectiveFunction()
CAF_PDM_InitFieldNoDefault( &m_weights, "Weights", "", "", "", "" );
m_isValid = true;
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
@ -60,26 +55,11 @@ RimCustomObjectiveFunction::RimCustomObjectiveFunction()
//--------------------------------------------------------------------------------------------------
RimCustomObjectiveFunctionWeight* RimCustomObjectiveFunction::addWeight()
{
garbageCollectWeights();
auto newWeight = new RimCustomObjectiveFunctionWeight();
m_weights.push_back( newWeight );
return newWeight;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCustomObjectiveFunction::removeWeight( RimCustomObjectiveFunctionWeight* weight )
{
garbageCollectWeights();
size_t sizeBefore = m_weights.size();
m_weights.removeChildObject( weight );
size_t sizeAfter = m_weights.size();
if ( sizeAfter < sizeBefore ) _removedWeights.push_back( weight );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -308,15 +288,3 @@ RimCustomObjectiveFunctionCollection* RimCustomObjectiveFunction::parentCollecti
firstAncestorOrThisOfType( collection );
return collection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void garbageCollectWeights()
{
for ( auto weight : _removedWeights )
{
delete weight;
}
_removedWeights.clear();
}

View File

@ -43,7 +43,6 @@ public:
RimCustomObjectiveFunction();
RimCustomObjectiveFunctionWeight* addWeight();
void removeWeight( RimCustomObjectiveFunctionWeight* weight );
std::vector<RimCustomObjectiveFunctionWeight*> weights() const;
std::vector<double> values() const;
double value( RimSummaryCase* summaryCase ) const;

View File

@ -24,13 +24,6 @@
CAF_PDM_SOURCE_INIT( RimCustomObjectiveFunctionCollection, "RimCustomObjectiveFunctionCollection" );
//--------------------------------------------------------------------------------------------------
/// Internal variables
//--------------------------------------------------------------------------------------------------
static std::vector<RimCustomObjectiveFunction*> _removedFunctions;
static void garbageCollectObjectiveFunctions();
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -50,8 +43,6 @@ RimCustomObjectiveFunctionCollection::RimCustomObjectiveFunctionCollection()
//--------------------------------------------------------------------------------------------------
RimCustomObjectiveFunction* RimCustomObjectiveFunctionCollection::addObjectiveFunction()
{
garbageCollectObjectiveFunctions();
auto newFunction = new RimCustomObjectiveFunction();
m_objectiveFunctions.push_back( newFunction );
objectiveFunctionAdded.send( newFunction );
@ -66,25 +57,6 @@ void RimCustomObjectiveFunctionCollection::onObjectiveFunctionChanged( RimCustom
objectiveFunctionChanged.send( objectiveFunction );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCustomObjectiveFunctionCollection::removeObjectiveFunction( RimCustomObjectiveFunction* objectiveFunction )
{
objectiveFunction->invalidate();
objectiveFunctionAboutToBeDeleted.send( objectiveFunction );
garbageCollectObjectiveFunctions();
size_t sizeBefore = m_objectiveFunctions.size();
m_objectiveFunctions.removeChildObject( objectiveFunction );
size_t sizeAfter = m_objectiveFunctions.size();
if ( sizeAfter < sizeBefore ) _removedFunctions.push_back( objectiveFunction );
objectiveFunctionDeleted.send();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -105,15 +77,3 @@ void RimCustomObjectiveFunctionCollection::defineUiTreeOrdering( caf::PdmUiTreeO
}
uiTreeOrdering.skipRemainingChildren( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void garbageCollectObjectiveFunctions()
{
for ( auto func : _removedFunctions )
{
delete func;
}
_removedFunctions.clear();
}

View File

@ -45,7 +45,6 @@ public:
RimCustomObjectiveFunction* addObjectiveFunction();
void onObjectiveFunctionChanged( RimCustomObjectiveFunction* objectiveFunction );
void removeObjectiveFunction( RimCustomObjectiveFunction* objectiveFunction );
std::vector<RimCustomObjectiveFunction*> objectiveFunctions() const;
private:

View File

@ -32,13 +32,6 @@
CAF_PDM_SOURCE_INIT( RimEnsembleCurveFilterCollection, "RimEnsembleCurveFilterCollection" );
//--------------------------------------------------------------------------------------------------
/// Internal variables
//--------------------------------------------------------------------------------------------------
static std::vector<RimEnsembleCurveFilter*> _removedFilters;
static void garbageCollectFilters();
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -64,8 +57,6 @@ RimEnsembleCurveFilterCollection::RimEnsembleCurveFilterCollection()
//--------------------------------------------------------------------------------------------------
RimEnsembleCurveFilter* RimEnsembleCurveFilterCollection::addFilter( const QString& ensembleParameterName )
{
garbageCollectFilters();
auto newFilter = new RimEnsembleCurveFilter( ensembleParameterName );
m_filters.push_back( newFilter );
return newFilter;
@ -122,7 +113,7 @@ void RimEnsembleCurveFilterCollection::fieldChangedByUi( const caf::PdmFieldHand
const QVariant& oldValue,
const QVariant& newValue )
{
RimEnsembleCurveSet* curveSet;
RimEnsembleCurveSet* curveSet = nullptr;
firstAncestorOrThisOfType( curveSet );
if ( !curveSet ) return;
@ -285,16 +276,8 @@ void RimEnsembleCurveFilterCollection::onChildDeleted( caf::PdmChildArrayFieldHa
RimSummaryPlot* plot = nullptr;
firstAncestorOrThisOfType( plot );
if ( plot ) plot->loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void garbageCollectFilters()
{
for ( auto filter : _removedFilters )
{
delete filter;
}
_removedFilters.clear();
RimEnsembleCurveSet* curveSet = nullptr;
firstAncestorOrThisOfType( curveSet );
if ( curveSet ) curveSet->updateConnectedEditors();
}