mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-30 09:00:20 -05:00
Use cafPdmUiButton instead of bool in PdmField
* Adopts dynamic PDM buttons with lambda callbacks Refactors PDM push buttons from boolean fields to use the `addNewButton` API with direct lambda callbacks. This change enforces a new coding guideline to extract complex or multi-line lambdas to dedicated `on*Clicked()` methods, improving code readability and maintainability. - Replaces `PdmField` button fields with `PdmUiOrdering::addNewButton` calls. - Extracts multi-line/control-flow lambdas into named methods in `RimFlowCharacteristicsPlot`, `RimGeoMechCase`, and `RimStatisticsContourMap`. - Removes obsolete `defineEditorAttribute` overrides and `fieldChangedByUi` logic for these buttons. - Updates `RimWellPathFracture` to utilize base class-provided button creation. - Adds new lambda line-count guideline to the coding style documentation. - Includes minor build fixes, such as adding `cafPdmUiButton.h` and correcting tooltip API usage.
This commit is contained in:
1 parent
76fe5fd4d5
commit
61a69bacc4
16 files changed
+210
-364
No files matched your search
@@ -53,8 +53,8 @@
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafCmdFeatureMenuBuilder.h"
|
||||
#include "cafPdmUiButton.h"
|
||||
#include "cafPdmUiDoubleSliderEditor.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
#include "cafProgressInfo.h"
|
||||
|
||||
@@ -128,10 +128,6 @@ RimStatisticsContourMap::RimStatisticsContourMap()
|
||||
"Eclipse Case used for wells and faults shown in views, initializing available result list, timesteps, "
|
||||
"etc." );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_computeStatisticsButton, "ComputeStatisticsButton", "" );
|
||||
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &m_computeStatisticsButton );
|
||||
m_computeStatisticsButton = false;
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_views, "ContourMapViews", "Contour Maps", ":/CrossSection16x16.png" );
|
||||
|
||||
CAF_PDM_InitField( &m_enableFormationFilter, "EnableFormationFilter", false, "Enable Formation Filter" );
|
||||
@@ -161,15 +157,11 @@ void RimStatisticsContourMap::defineUiOrdering( QString uiConfigName, caf::PdmUi
|
||||
computeOK = computeOK && !selectedTimeSteps().empty();
|
||||
|
||||
uiOrdering.add( nameField() );
|
||||
uiOrdering.add( &m_computeStatisticsButton );
|
||||
m_computeStatisticsButton.uiCapability()->setUiReadOnly( !computeOK );
|
||||
if ( computeOK )
|
||||
|
||||
{
|
||||
m_computeStatisticsButton.uiCapability()->setUiToolTip( "Start statistics computations." );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_computeStatisticsButton.uiCapability()->setUiToolTip( "Please check your time step and/or formation filter selections." );
|
||||
auto* btn = uiOrdering.addNewButton( "Compute", [this]() { onComputeStatisticsClicked(); } );
|
||||
btn->setUiToolTip( computeOK ? "Start statistics computations." : "Please check your time step and/or formation filter selections." );
|
||||
btn->setUiReadOnly( !computeOK );
|
||||
}
|
||||
|
||||
auto genGrp = uiOrdering.addNewGroup( "General" );
|
||||
@@ -307,32 +299,7 @@ std::set<RimEclipseCase*> RimStatisticsContourMap::ensembleCasesInViews() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsContourMap::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
||||
{
|
||||
if ( &m_computeStatisticsButton == changedField )
|
||||
{
|
||||
computeStatistics();
|
||||
m_computeStatisticsButton = false;
|
||||
|
||||
if ( m_views.empty() )
|
||||
{
|
||||
auto view = RicNewStatisticsContourMapViewFeature::createAndAddView( this );
|
||||
updateConnectedEditors();
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( view );
|
||||
Riu3DMainWindowTools::setExpanded( this );
|
||||
Riu3DMainWindowTools::setExpanded( view );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto& view : m_views )
|
||||
{
|
||||
auto proj = dynamic_cast<RimStatisticsContourMapProjection*>( view->contourMapProjection() );
|
||||
if ( proj != nullptr )
|
||||
proj->clearGridMappingAndRedraw();
|
||||
else
|
||||
view->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( &m_primaryCase == changedField )
|
||||
if ( &m_primaryCase == changedField )
|
||||
{
|
||||
switchToSelectedSourceCase();
|
||||
|
||||
@@ -428,14 +395,7 @@ QList<caf::PdmOptionItemInfo> RimStatisticsContourMap::calculateValueOptions( co
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsContourMap::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( &m_computeStatisticsButton == field )
|
||||
{
|
||||
if ( auto attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute ) )
|
||||
{
|
||||
attrib->m_buttonText = "Compute";
|
||||
}
|
||||
}
|
||||
else if ( ( &m_userDefinedFloodingOil == field ) || ( &m_userDefinedFloodingGas == field ) )
|
||||
if ( ( &m_userDefinedFloodingOil == field ) || ( &m_userDefinedFloodingGas == field ) )
|
||||
{
|
||||
if ( auto myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute ) )
|
||||
{
|
||||
@@ -523,13 +483,39 @@ void RimStatisticsContourMap::doStatisticsCalculation( std::map<size_t, std::vec
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsContourMap::onComputeStatisticsClicked()
|
||||
{
|
||||
computeStatistics();
|
||||
|
||||
if ( m_views.empty() )
|
||||
{
|
||||
auto view = RicNewStatisticsContourMapViewFeature::createAndAddView( this );
|
||||
updateConnectedEditors();
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( view );
|
||||
Riu3DMainWindowTools::setExpanded( this );
|
||||
Riu3DMainWindowTools::setExpanded( view );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto& view : m_views )
|
||||
{
|
||||
auto proj = dynamic_cast<RimStatisticsContourMapProjection*>( view->contourMapProjection() );
|
||||
if ( proj != nullptr )
|
||||
proj->clearGridMappingAndRedraw();
|
||||
else
|
||||
view->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsContourMap::computeStatistics()
|
||||
{
|
||||
if ( m_computeStatisticsButton.isReadOnly() ) return;
|
||||
|
||||
RiaLogging::info( "Computing statistics" );
|
||||
auto cases = ensembleCases();
|
||||
if ( cases.empty() ) return;
|
||||
|
||||
Reference in new issue
Block a user