From bb6f1fe9964d3c73401b77ae22fc209d3cbf7836 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 11:23:00 +0200 Subject: [PATCH] Cleanup --- .../RimSummaryRegressionAnalysisCurve.cpp | 56 +++++--- .../RimSummaryRegressionAnalysisCurve.h | 10 +- .../cafPdmUiValueRangeEditor.cpp | 133 +++++++----------- .../cafPdmUiValueRangeEditor.h | 8 -- 4 files changed, 94 insertions(+), 113 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp index 5dd77c5248..7838f221a1 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp @@ -27,7 +27,7 @@ #include "cafPdmUiDateEditor.h" #include "cafPdmUiLineEditor.h" -#include "cafPdmUiSliderEditor.h" +#include "cafPdmUiSliderTools.h" #include "cafPdmUiTextEditor.h" #include "ExponentialRegression.hpp" @@ -96,12 +96,11 @@ RimSummaryRegressionAnalysisCurve::RimSummaryRegressionAnalysisCurve() m_expressionText.xmlCapability()->disableIO(); CAF_PDM_InitField( &m_filterValuesX, "FilterValuesX", false, "Filter X" ); - CAF_PDM_InitField( &m_minValueX, "MinValueX", 0.0, " Minimum Threshold X" ); - CAF_PDM_InitField( &m_maxValueX, "MaxValueX", 1.0, " Maximum Threshold X" ); + CAF_PDM_InitField( &m_valueRangeX, "ValueRangeX", std::make_pair( 0.0, 0.0 ), "Value Range X" ); + m_valueRangeX.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); CAF_PDM_InitField( &m_filterValuesY, "FilterValuesY", false, "Filter Y" ); - CAF_PDM_InitField( &m_minValueY, "MinValueY", 0.0, " Minimum Threshold Y" ); - CAF_PDM_InitField( &m_maxValueY, "MaxValueY", 1.0, " Maximum Threshold Y" ); + CAF_PDM_InitField( &m_valueRangeY, "ValueRangeY", std::make_pair( 0.0, 0.0 ), "Value Range Y" ); } //-------------------------------------------------------------------------------------------------- @@ -131,7 +130,7 @@ void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPl auto values = xValues; for ( size_t i = 0; i < values.size(); i++ ) { - if ( values[i] < m_minValueX || values[i] > m_maxValueX ) + if ( values[i] < m_valueRangeX().first || values[i] > m_valueRangeX().second ) { indicesToRemove.push_back( i ); } @@ -143,7 +142,7 @@ void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPl auto values = yValues; for ( size_t i = 0; i < values.size(); i++ ) { - if ( values[i] < m_minValueY || values[i] > m_maxValueY ) + if ( values[i] < m_valueRangeY().first || values[i] > m_valueRangeY().second ) { indicesToRemove.push_back( i ); } @@ -156,7 +155,7 @@ void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPl // Step 3: Remove elements at the specified indices for ( auto index : indicesToRemove ) { - if ( index >= 0 && index < xValues.size() ) + if ( index < xValues.size() ) { xValues.erase( xValues.begin() + index ); timeStepsX.erase( timeStepsX.begin() + index ); @@ -318,16 +317,12 @@ void RimSummaryRegressionAnalysisCurve::defineUiOrdering( QString uiConfigName, if ( axisTypeX() == RiaDefines::HorizontalAxisType::SUMMARY_VECTOR ) { timeSelectionGroup->add( &m_filterValuesX ); - timeSelectionGroup->add( &m_minValueX ); - timeSelectionGroup->add( &m_maxValueX ); - m_minValueX.uiCapability()->setUiReadOnly( !m_filterValuesX() ); - m_maxValueX.uiCapability()->setUiReadOnly( !m_filterValuesX() ); + timeSelectionGroup->add( &m_valueRangeX ); + m_valueRangeX.uiCapability()->setUiReadOnly( !m_filterValuesX() ); timeSelectionGroup->add( &m_filterValuesY ); - timeSelectionGroup->add( &m_minValueY ); - timeSelectionGroup->add( &m_maxValueY ); - m_minValueY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); - m_maxValueY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); + timeSelectionGroup->add( &m_valueRangeY ); + m_valueRangeY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); } caf::PdmUiGroup* forecastingGroup = uiOrdering.addNewGroup( "Forecasting" ); @@ -358,7 +353,8 @@ void RimSummaryRegressionAnalysisCurve::fieldChangedByUi( const caf::PdmFieldHan RimSummaryCurve::fieldChangedByUi( changedField, oldValue, newValue ); if ( changedField == &m_regressionType || changedField == &m_polynomialDegree || changedField == &m_forecastBackward || changedField == &m_forecastForward || changedField == &m_forecastUnit || changedField == &m_minTimeStep || - changedField == &m_maxTimeStep || changedField == &m_showTimeSelectionInPlot ) + changedField == &m_maxTimeStep || changedField == &m_showTimeSelectionInPlot || changedField == &m_valueRangeX || + changedField == &m_valueRangeY ) { loadAndUpdateDataAndPlot(); @@ -419,6 +415,32 @@ void RimSummaryRegressionAnalysisCurve::defineEditorAttribute( const caf::PdmFie myAttr->font = font; } } + else if ( field == &m_valueRangeX ) + { + auto myAttr = dynamic_cast( attribute ); + if ( myAttr ) + { + auto values = RimSummaryCurve::valuesX(); + if ( !values.empty() ) + { + myAttr->m_minimum = *std::min_element( values.begin(), values.end() ); + myAttr->m_maximum = *std::max_element( values.begin(), values.end() ); + } + } + } + else if ( field == &m_valueRangeY ) + { + auto myAttr = dynamic_cast( attribute ); + if ( myAttr ) + { + auto values = RimSummaryCurve::valuesY(); + if ( !values.empty() ) + { + myAttr->m_minimum = *std::min_element( values.begin(), values.end() ); + myAttr->m_maximum = *std::max_element( values.begin(), values.end() ); + } + } + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h index d72312dfb8..df4eac7273 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h @@ -126,13 +126,11 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve caf::PdmField m_forecastBackward; caf::PdmField> m_forecastUnit; - caf::PdmField m_filterValuesX; - caf::PdmField m_minValueX; - caf::PdmField m_maxValueX; + caf::PdmField m_filterValuesX; + caf::PdmField> m_valueRangeX; - caf::PdmField m_filterValuesY; - caf::PdmField m_minValueY; - caf::PdmField m_maxValueY; + caf::PdmField m_filterValuesY; + caf::PdmField> m_valueRangeY; caf::PdmPointer m_timeRangeAnnotation; std::vector m_valuesX; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index 593476a255..b8507ea540 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -44,40 +44,10 @@ #include "cafPdmUiOrdering.h" #include "cafQShortenedLabel.h" -#include #include +#include #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class PdmDoubleValidator : public QDoubleValidator -{ -public: - explicit PdmDoubleValidator( QObject* parent = nullptr ) - : QDoubleValidator( parent ) - { - } - - PdmDoubleValidator( double bottom, double top, int decimals, QObject* parent ) - : QDoubleValidator( bottom, top, decimals, parent ) - { - } - - ~PdmDoubleValidator() override {} - - //-------------------------------------------------------------------------------------------------- - /// - //-------------------------------------------------------------------------------------------------- - void fixup( QString& stringValue ) const override - { - double doubleValue = stringValue.toDouble(); - doubleValue = qBound( bottom(), doubleValue, top() ); - - stringValue = QString::number( doubleValue, 'g', decimals() ); - } -}; - namespace caf { CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT( PdmUiValueRangeEditor ); @@ -100,10 +70,12 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &m_attributes ); } - double firstValue = 0.0; - double secondValue = 0.0; + // A pair is represented as a list of QVariant in PdmValueFieldSpecialization> + auto getTwoDoublesFromVariant = [=]() -> std::pair { - // A pair is converted into a list of QVariant in PdmValueFieldSpecialization> + double firstValue = 0.0; + double secondValue = 0.0; + auto variantValue = uiField()->uiValue(); if ( variantValue.canConvert>() ) { @@ -114,43 +86,43 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) secondValue = lst[1].toDouble(); } } - } - { - m_sliderMin->blockSignals( true ); - m_sliderMin->setMaximum( m_attributes.m_sliderTickCount ); - m_sliderMin->blockSignals( false ); + return std::make_pair( firstValue, secondValue ); + }; - QString textValueMin = QString( "%1" ).arg( firstValue ); + auto [minimum, maximum] = getTwoDoublesFromVariant(); - PdmDoubleValidator* pdmValidator = - new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); - pdmValidator->fixup( textValueMin ); + m_sliderMin->blockSignals( true ); + m_sliderMin->setMaximum( m_attributes.m_sliderTickCount ); + m_sliderMin->blockSignals( false ); - m_lineEditMin->setValidator( pdmValidator ); - m_lineEditMin->setText( textValueMin ); + QString textValueMin = QString( "%1" ).arg( minimum ); - m_sliderValueMin = firstValue; - PdmUiSliderTools::updateSliderPosition( m_sliderMin, firstValue, m_attributes ); - } + PdmDoubleValidator* pdmValidator = + new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); + pdmValidator->fixup( textValueMin ); - { - m_sliderMax->blockSignals( true ); - m_sliderMax->setMaximum( m_attributes.m_sliderTickCount ); - m_sliderMax->blockSignals( false ); + m_lineEditMin->setValidator( pdmValidator ); + m_lineEditMin->setText( textValueMin ); - QString textValueMax = QString( "%1" ).arg( secondValue ); + m_sliderValueMin = minimum; + PdmUiSliderTools::updateSliderPosition( m_sliderMin, minimum, m_attributes ); - PdmDoubleValidator* pdmValidator = - new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); - pdmValidator->fixup( textValueMax ); + m_sliderMax->blockSignals( true ); + m_sliderMax->setMaximum( m_attributes.m_sliderTickCount ); + m_sliderMax->blockSignals( false ); - m_lineEditMax->setValidator( pdmValidator ); - m_lineEditMax->setText( textValueMax ); + QString textValueMax = QString( "%1" ).arg( maximum ); - m_sliderValueMax = secondValue; - PdmUiSliderTools::updateSliderPosition( m_sliderMax, secondValue, m_attributes ); - } + PdmDoubleValidator* pdmValidator = + new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); + pdmValidator->fixup( textValueMax ); + + m_lineEditMax->setValidator( pdmValidator ); + m_lineEditMax->setText( textValueMax ); + + m_sliderValueMax = maximum; + PdmUiSliderTools::updateSliderPosition( m_sliderMax, maximum, m_attributes ); } //-------------------------------------------------------------------------------------------------- @@ -287,39 +259,36 @@ PdmUiValueRangeEditor::~PdmUiValueRangeEditor() //-------------------------------------------------------------------------------------------------- QWidget* PdmUiValueRangeEditor::createEditorWidget( QWidget* parent ) { - QWidget* containerWidget = new QWidget( parent ); + auto containerWidget = new QWidget( parent ); auto layout = new QGridLayout(); layout->setMargin( 0 ); containerWidget->setLayout( layout ); - { - m_lineEditMin = new QLineEdit( containerWidget ); - m_lineEditMin->setMaximumWidth( 100 ); - connect( m_lineEditMin, SIGNAL( editingFinished() ), this, SLOT( slotMinEditingFinished() ) ); + m_lineEditMin = new QLineEdit( containerWidget ); + m_lineEditMin->setMaximumWidth( 100 ); + connect( m_lineEditMin, SIGNAL( editingFinished() ), this, SLOT( slotMinEditingFinished() ) ); - m_sliderMin = new QSlider( Qt::Horizontal, containerWidget ); + m_sliderMin = new QSlider( Qt::Horizontal, containerWidget ); - layout->addWidget( m_lineEditMin, 0, 0 ); - layout->addWidget( m_sliderMin, 0, 1 ); + layout->addWidget( m_lineEditMin, 0, 0 ); + layout->addWidget( m_sliderMin, 0, 1 ); - connect( m_sliderMin, SIGNAL( valueChanged( int ) ), this, SLOT( slotMinSliderValueChanged( int ) ) ); - connect( m_sliderMin, SIGNAL( sliderReleased() ), this, SLOT( slotSliderReleasedMin() ) ); - } + connect( m_sliderMin, SIGNAL( valueChanged( int ) ), this, SLOT( slotMinSliderValueChanged( int ) ) ); + connect( m_sliderMin, SIGNAL( sliderReleased() ), this, SLOT( slotSliderReleasedMin() ) ); - { - m_lineEditMax = new QLineEdit( containerWidget ); - m_lineEditMax->setMaximumWidth( 100 ); - connect( m_lineEditMax, SIGNAL( editingFinished() ), this, SLOT( slotMaxEditingFinished() ) ); + m_lineEditMax = new QLineEdit( containerWidget ); + m_lineEditMax->setMaximumWidth( 100 ); + connect( m_lineEditMax, SIGNAL( editingFinished() ), this, SLOT( slotMaxEditingFinished() ) ); - m_sliderMax = new QSlider( Qt::Horizontal, containerWidget ); + m_sliderMax = new QSlider( Qt::Horizontal, containerWidget ); - layout->addWidget( m_lineEditMax, 1, 0 ); - layout->addWidget( m_sliderMax, 1, 1 ); + layout->addWidget( m_lineEditMax, 1, 0 ); + layout->addWidget( m_sliderMax, 1, 1 ); + + connect( m_sliderMax, SIGNAL( valueChanged( int ) ), this, SLOT( slotMaxSliderValueChanged( int ) ) ); + connect( m_sliderMax, SIGNAL( sliderReleased() ), this, SLOT( slotSliderReleasedMax() ) ); - connect( m_sliderMax, SIGNAL( valueChanged( int ) ), this, SLOT( slotMaxSliderValueChanged( int ) ) ); - connect( m_sliderMax, SIGNAL( sliderReleased() ), this, SLOT( slotSliderReleasedMax() ) ); - } return containerWidget; } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index 1cf27adcd0..a7f3a7f1a5 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -39,14 +39,6 @@ #include "cafPdmUiFieldEditorHandle.h" #include "cafPdmUiSliderTools.h" -#include -#include -#include -#include -#include -#include -#include - namespace caf { //==================================================================================================