Replaces push buttons with new UI ordering

Removes the usage of `cafPdmUiPushButtonEditor` and implements the same functionality using the `addNewButton` method in `cafPdmUiOrdering`.

This change provides a more flexible and consistent way to add buttons to the UI and simplifies the code by removing the need for a dedicated editor class.
This commit is contained in:
Magne Sjaastad committed 2026-01-27 13:37:37 +01:00
1 parent 5be1a4feb7
commit 4ddace05fb
10 files changed
+86 -181

No files matched your search

@@ -30,7 +30,6 @@
#include "RiuSummaryVectorSelectionDialog.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTreeSelectionEditor.h"
CAF_PDM_SOURCE_INIT( RimCustomObjectiveFunctionWeight, "RimCustomObjectiveFunctionWeight" );
@@ -52,10 +51,6 @@ RimCustomObjectiveFunctionWeight::RimCustomObjectiveFunctionWeight()
CAF_PDM_InitFieldNoDefault( &m_objectiveValuesSummaryAddresses, "ObjectiveSummaryAddress", "Summary Address" );
m_objectiveValuesSummaryAddresses.uiCapability()->setUiTreeChildrenHidden( true );
CAF_PDM_InitFieldNoDefault( &m_objectiveValuesSelectSummaryAddressPushButton, "SelectObjectiveSummaryAddress", "" );
caf::PdmUiPushButtonEditor::configureEditorLabelHidden( &m_objectiveValuesSelectSummaryAddressPushButton );
m_objectiveValuesSelectSummaryAddressPushButton = false;
CAF_PDM_InitField( &m_weightValue, "WeightValue", 1.0, "Weight" );
m_weightValue.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() );
@@ -143,38 +138,6 @@ void RimCustomObjectiveFunctionWeight::fieldChangedByUi( const caf::PdmFieldHand
{
updateAddressesUiField();
}
else if ( changedField == &m_objectiveValuesSelectSummaryAddressPushButton )
{
RiuSummaryVectorSelectionDialog dlg( RiaGuiApplication::widgetToUseAsParent() );
RimObjectiveFunctionTools::configureDialogForObjectiveFunctions( &dlg );
RimSummaryEnsemble* candidateEnsemble = parentCurveSet()->summaryEnsemble();
std::vector<RifEclipseSummaryAddress> candidateAddresses;
for ( auto address : m_objectiveValuesSummaryAddresses().childrenByType() )
{
candidateAddresses.push_back( address->address() );
}
dlg.setEnsembleAndAddresses( candidateEnsemble, candidateAddresses );
if ( dlg.exec() == QDialog::Accepted )
{
auto curveSelection = dlg.curveSelection();
if ( !curveSelection.empty() )
{
m_objectiveValuesSummaryAddresses.deleteChildren();
for ( auto address : curveSelection )
{
RimSummaryAddress* summaryAddress = new RimSummaryAddress();
summaryAddress->setAddress( address.summaryAddressY() );
m_objectiveValuesSummaryAddresses.push_back( summaryAddress );
}
}
}
updateAddressesUiField();
m_objectiveValuesSelectSummaryAddressPushButton = false;
parentObjectiveFunction()->onWeightChanged();
}
else if ( changedField == &m_weightValue )
{
parentObjectiveFunction()->onWeightChanged();
@@ -191,7 +154,7 @@ void RimCustomObjectiveFunctionWeight::fieldChangedByUi( const caf::PdmFieldHand
void RimCustomObjectiveFunctionWeight::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_objectiveValuesSummaryAddressesUiField );
uiOrdering.add( &m_objectiveValuesSelectSummaryAddressPushButton, { .newRow = false, .totalColumnSpan = 1, .leftLabelColumnSpan = 0 } );
uiOrdering.addNewButton( "...", [this]() { selectSummaryAddress(); }, { .newRow = false, .totalColumnSpan = 1, .leftLabelColumnSpan = 0 } );
uiOrdering.add( &m_weightValue );
uiOrdering.add( &m_objectiveFunction );
@@ -215,14 +178,6 @@ void RimCustomObjectiveFunctionWeight::defineEditorAttribute( const caf::PdmFiel
myAttr->validator = new QDoubleValidator( 0.0, 9999.0, 2 );
}
else if ( field == &m_objectiveValuesSelectSummaryAddressPushButton )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = "...";
}
}
}
//--------------------------------------------------------------------------------------------------
@@ -261,3 +216,38 @@ void RimCustomObjectiveFunctionWeight::updateAddressesUiField()
}
m_objectiveValuesSummaryAddressesUiField = QString::fromStdString( RifEclipseSummaryAddress::generateStringFromAddresses( addressVector ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCustomObjectiveFunctionWeight::selectSummaryAddress()
{
RiuSummaryVectorSelectionDialog dlg( nullptr );
RimObjectiveFunctionTools::configureDialogForObjectiveFunctions( &dlg );
RimSummaryEnsemble* candidateEnsemble = parentCurveSet()->summaryEnsemble();
std::vector<RifEclipseSummaryAddress> candidateAddresses;
for ( auto address : m_objectiveValuesSummaryAddresses().childrenByType() )
{
candidateAddresses.push_back( address->address() );
}
dlg.setEnsembleAndAddresses( candidateEnsemble, candidateAddresses );
if ( dlg.exec() == QDialog::Accepted )
{
auto curveSelection = dlg.curveSelection();
if ( !curveSelection.empty() )
{
m_objectiveValuesSummaryAddresses.deleteChildren();
for ( auto address : curveSelection )
{
RimSummaryAddress* summaryAddress = new RimSummaryAddress();
summaryAddress->setAddress( address.summaryAddressY() );
m_objectiveValuesSummaryAddresses.push_back( summaryAddress );
}
}
}
updateAddressesUiField();
parentObjectiveFunction()->onWeightChanged();
}
@@ -66,12 +66,12 @@ private:
RimCustomObjectiveFunction* parentObjectiveFunction() const;
void updateAddressesUiField();
void selectSummaryAddress();
private:
caf::PdmProxyValueField<QString> m_title;
caf::PdmChildArrayField<RimSummaryAddress*> m_objectiveValuesSummaryAddresses;
caf::PdmField<QString> m_objectiveValuesSummaryAddressesUiField;
caf::PdmField<bool> m_objectiveValuesSelectSummaryAddressPushButton;
caf::PdmField<caf::AppEnum<RimObjectiveFunction::FunctionType>> m_objectiveFunction;
caf::PdmField<double> m_weightValue;
};
@@ -45,7 +45,6 @@
#include "RiuMainWindow.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTextEditor.h"
#include "cafPdmUiTreeSelectionEditor.h"
#include "cafProgressInfo.h"
@@ -81,10 +80,6 @@ RimEclipseStatisticsCase::RimEclipseStatisticsCase()
{
CAF_PDM_InitScriptableObject( "Case Group Statistics", ":/Histogram16x16.png" );
CAF_PDM_InitFieldNoDefault( &m_calculateEditCommand, "m_editingAllowed", "" );
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &m_calculateEditCommand );
m_calculateEditCommand = false;
CAF_PDM_InitField( &m_selectionSummary, "SelectionSummary", QString( "" ), "Summary of Calculation Setup" );
m_selectionSummary.xmlCapability()->disableIO();
m_selectionSummary.uiCapability()->setUiReadOnly( true );
@@ -491,7 +486,19 @@ void RimEclipseStatisticsCase::defineUiOrdering( QString uiConfigName, caf::PdmU
uiOrdering.add( &m_caseUserDescription );
uiOrdering.add( &m_caseId );
uiOrdering.add( &m_calculateEditCommand );
QString buttonText = hasComputedStatistics() ? "Edit (Will DELETE current results)" : "Compute";
uiOrdering.addNewButton( buttonText,
[this]()
{
if ( hasComputedStatistics() )
{
clearComputedStatistics();
}
else
{
computeStatisticsAndUpdateViews();
}
} );
{
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Summary of Calculation Setup" );
@@ -718,19 +725,6 @@ void RimEclipseStatisticsCase::fieldChangedByUi( const caf::PdmFieldHandle* chan
{
}
if ( &m_calculateEditCommand == changedField )
{
if ( hasComputedStatistics() )
{
clearComputedStatistics();
}
else
{
computeStatisticsAndUpdateViews();
}
m_calculateEditCommand = false;
}
if ( &m_dataSourceForStatistics == changedField && m_gridCalculation() == nullptr )
{
auto calculations = RimProject::current()->gridCalculationCollection()->calculations();
@@ -869,15 +863,6 @@ void RimEclipseStatisticsCase::defineEditorAttribute( const caf::PdmFieldHandle*
textEditAttrib->textMode = caf::PdmUiTextEditorAttribute::HTML;
}
}
if ( &m_calculateEditCommand == field )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = hasComputedStatistics() ? "Edit (Will DELETE current results)" : "Compute";
}
}
}
//--------------------------------------------------------------------------------------------------
@@ -75,8 +75,6 @@ public:
RimCaseCollection* parentStatisticsCaseCollection() const;
caf::PdmField<bool> m_calculateEditCommand;
void populateResultSelectionAfterLoadingGrid();
void setSourceProperties( RiaDefines::ResultCatType propertyType, const std::vector<QString>& propertyNames );
@@ -61,7 +61,6 @@
#include "cafPdmFieldCvfMat4d.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiToolButtonEditor.h"
#include "cvfMath.h"
@@ -203,9 +202,6 @@ RimRegularLegendConfig::RimRegularLegendConfig()
m_scalarMapperLegend = new caf::OverlayScalarMapperLegend( standardFont );
m_categoryLegend = new caf::CategoryLegend( standardFont, m_categoryMapper.p() );
CAF_PDM_InitField( &m_resetUserDefinedValuesButton, "ResetDefaultValues", false, "Reset Default Values" );
caf::PdmUiPushButtonEditor::configureEditorLabelHidden( &m_resetUserDefinedValuesButton );
CAF_PDM_InitField( &m_centerLegendAroundZero, "CenterLegendAroundZero", false, "Center Legend Around Zero" );
updateFieldVisibility();
@@ -282,13 +278,6 @@ void RimRegularLegendConfig::fieldChangedByUi( const caf::PdmFieldHandle* change
updateCategoryItems();
}
if ( changedField == &m_resetUserDefinedValuesButton )
{
resetUserDefinedValues();
m_resetUserDefinedValuesButton = false;
}
updateLegend();
auto view = firstAncestorOrThisOfType<RimGridView>();
@@ -375,10 +364,6 @@ void RimRegularLegendConfig::sendChangedSignal( const caf::PdmFieldHandle* chang
{
changed.send( ChangeType::COLORS );
}
else if ( changedField == &m_resetUserDefinedValuesButton )
{
changed.send( ChangeType::ALL );
}
}
auto computeAdjustedMinMax = []( double minimum, double maximum, double precision ) -> std::pair<double, double>
@@ -686,14 +671,6 @@ caf::PdmFieldHandle* RimRegularLegendConfig::objectToggleField()
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
if ( &m_resetUserDefinedValuesButton == field )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = "Reset User Defined Values";
}
}
}
//--------------------------------------------------------------------------------------------------
@@ -1309,7 +1286,12 @@ void RimRegularLegendConfig::defineUiOrdering( QString uiConfigName, caf::PdmUiO
mappingGr->add( &m_categoryColorMode );
mappingGr->add( &m_centerLegendAroundZero );
uiOrdering.add( &m_resetUserDefinedValuesButton );
uiOrdering.addNewButton( "Reset User Defined Values",
[this]()
{
resetUserDefinedValues();
changed.send( RimLegendConfigChangeType::ALL );
} );
}
updateFieldVisibility();
@@ -239,7 +239,6 @@ private:
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
caf::PdmField<bool> m_resetUserDefinedValuesButton;
caf::PdmField<bool> m_centerLegendAroundZero;
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
@@ -22,7 +22,6 @@
#include "RimEclipseCaseTools.h"
#include "RimEclipseResultDefinition.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTableViewEditor.h"
CAF_PDM_SOURCE_INIT( RimResultSelectionUi, "RimResultSelectionUi" );
@@ -47,7 +47,6 @@
#include "RivReservoirViewPartMgr.h"
#include "cafPdmUiCheckBoxTristateEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeSelectionEditor.h"
@@ -32,7 +32,6 @@
#include "RivTernarySaturationOverlayItem.h"
#include "RivTernaryScalarMapper.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTextEditor.h"
#include "cvfqtUtils.h"
@@ -58,18 +57,6 @@ RimTernaryLegendConfig::RimTernaryLegendConfig()
"Switches between automatic and user defined range on the legend",
"" );
CAF_PDM_InitFieldNoDefault( &applyLocalMinMax, "m_applyLocalMinMax", "" );
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &applyLocalMinMax );
applyLocalMinMax = false;
CAF_PDM_InitFieldNoDefault( &applyGlobalMinMax, "m_applyGlobalMinMax", "" );
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &applyGlobalMinMax );
applyGlobalMinMax = false;
CAF_PDM_InitFieldNoDefault( &applyFullRangeMinMax, "m_applyFullRangeMinMax", "" );
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &applyFullRangeMinMax );
applyFullRangeMinMax = false;
CAF_PDM_InitFieldNoDefault( &ternaryRangeSummary, "ternaryRangeSummary", "Range summary" );
ternaryRangeSummary.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() );
ternaryRangeSummary.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::LabelPosition::TOP );
@@ -106,40 +93,6 @@ RimTernaryLegendConfig::~RimTernaryLegendConfig()
//--------------------------------------------------------------------------------------------------
void RimTernaryLegendConfig::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
if ( changedField == &applyLocalMinMax )
{
userDefinedMaxValueSoil = m_localAutoMax[TERNARY_SOIL_IDX];
userDefinedMinValueSoil = m_localAutoMin[TERNARY_SOIL_IDX];
userDefinedMaxValueSgas = m_localAutoMax[TERNARY_SGAS_IDX];
userDefinedMinValueSgas = m_localAutoMin[TERNARY_SGAS_IDX];
userDefinedMaxValueSwat = m_localAutoMax[TERNARY_SWAT_IDX];
userDefinedMinValueSwat = m_localAutoMin[TERNARY_SWAT_IDX];
applyLocalMinMax = false;
}
else if ( changedField == &applyGlobalMinMax )
{
userDefinedMaxValueSoil = m_globalAutoMax[TERNARY_SOIL_IDX];
userDefinedMinValueSoil = m_globalAutoMin[TERNARY_SOIL_IDX];
userDefinedMaxValueSgas = m_globalAutoMax[TERNARY_SGAS_IDX];
userDefinedMinValueSgas = m_globalAutoMin[TERNARY_SGAS_IDX];
userDefinedMaxValueSwat = m_globalAutoMax[TERNARY_SWAT_IDX];
userDefinedMinValueSwat = m_globalAutoMin[TERNARY_SWAT_IDX];
applyGlobalMinMax = false;
}
else if ( changedField == &applyFullRangeMinMax )
{
userDefinedMaxValueSoil = 1.0;
userDefinedMinValueSoil = 0.0;
userDefinedMaxValueSgas = 1.0;
userDefinedMinValueSgas = 0.0;
userDefinedMaxValueSwat = 1.0;
userDefinedMinValueSwat = 0.0;
applyFullRangeMinMax = false;
}
updateLabelText();
updateLegend();
@@ -276,9 +229,36 @@ void RimTernaryLegendConfig::defineUiOrdering( QString uiConfigName, caf::PdmUiO
ternaryGroup->add( &userDefinedMaxValueSoil );
}
ternaryGroupContainer->add( &applyLocalMinMax );
ternaryGroupContainer->add( &applyGlobalMinMax );
ternaryGroupContainer->add( &applyFullRangeMinMax );
ternaryGroupContainer->addNewButton( "Apply local min/max values",
[this]()
{
userDefinedMaxValueSoil = m_localAutoMax[TERNARY_SOIL_IDX];
userDefinedMinValueSoil = m_localAutoMin[TERNARY_SOIL_IDX];
userDefinedMaxValueSgas = m_localAutoMax[TERNARY_SGAS_IDX];
userDefinedMinValueSgas = m_localAutoMin[TERNARY_SGAS_IDX];
userDefinedMaxValueSwat = m_localAutoMax[TERNARY_SWAT_IDX];
userDefinedMinValueSwat = m_localAutoMin[TERNARY_SWAT_IDX];
} );
ternaryGroupContainer->addNewButton( "Apply global min/max values",
[this]()
{
userDefinedMaxValueSoil = m_globalAutoMax[TERNARY_SOIL_IDX];
userDefinedMinValueSoil = m_globalAutoMin[TERNARY_SOIL_IDX];
userDefinedMaxValueSgas = m_globalAutoMax[TERNARY_SGAS_IDX];
userDefinedMinValueSgas = m_globalAutoMin[TERNARY_SGAS_IDX];
userDefinedMaxValueSwat = m_globalAutoMax[TERNARY_SWAT_IDX];
userDefinedMinValueSwat = m_globalAutoMin[TERNARY_SWAT_IDX];
} );
ternaryGroupContainer->addNewButton( "Apply full range",
[this]()
{
userDefinedMaxValueSoil = 1.0;
userDefinedMinValueSoil = 0.0;
userDefinedMaxValueSgas = 1.0;
userDefinedMinValueSgas = 0.0;
userDefinedMaxValueSwat = 1.0;
userDefinedMinValueSwat = 0.0;
} );
}
else
{
@@ -310,30 +290,6 @@ void RimTernaryLegendConfig::setTitle( const QString& title )
//--------------------------------------------------------------------------------------------------
void RimTernaryLegendConfig::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
if ( &applyLocalMinMax == field )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = "Apply local min/max values";
}
}
else if ( &applyGlobalMinMax == field )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = "Apply global min/max values";
}
}
else if ( &applyFullRangeMinMax == field )
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( attrib )
{
attrib->m_buttonText = "Apply full range";
}
}
}
//--------------------------------------------------------------------------------------------------
@@ -85,9 +85,6 @@ private:
caf::PdmField<double> userDefinedMaxValueSwat;
caf::PdmField<double> userDefinedMinValueSwat;
caf::PdmField<bool> applyLocalMinMax;
caf::PdmField<bool> applyGlobalMinMax;
caf::PdmField<bool> applyFullRangeMinMax;
caf::PdmField<QString> ternaryRangeSummary;
caf::PdmField<bool> m_showLegend;