Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 21, 2023
1 parent 5cc3db0 commit bb6f1fe
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "cafPdmUiDateEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiSliderEditor.h"
#include "cafPdmUiSliderTools.h"
#include "cafPdmUiTextEditor.h"

#include "ExponentialRegression.hpp"
Expand Down Expand Up @@ -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" );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -419,6 +415,32 @@ void RimSummaryRegressionAnalysisCurve::defineEditorAttribute( const caf::PdmFie
myAttr->font = font;
}
}
else if ( field == &m_valueRangeX )
{
auto myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( 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<caf::PdmUiDoubleSliderEditorAttribute*>( 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() );
}
}
}
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve
caf::PdmField<int> m_forecastBackward;
caf::PdmField<caf::AppEnum<ForecastUnit>> m_forecastUnit;

caf::PdmField<bool> m_filterValuesX;
caf::PdmField<double> m_minValueX;
caf::PdmField<double> m_maxValueX;
caf::PdmField<bool> m_filterValuesX;
caf::PdmField<std::pair<double, double>> m_valueRangeX;

caf::PdmField<bool> m_filterValuesY;
caf::PdmField<double> m_minValueY;
caf::PdmField<double> m_maxValueY;
caf::PdmField<bool> m_filterValuesY;
caf::PdmField<std::pair<double, double>> m_valueRangeY;

caf::PdmPointer<RimTimeAxisAnnotation> m_timeRangeAnnotation;
std::vector<double> m_valuesX;
Expand Down
133 changes: 51 additions & 82 deletions Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,10 @@
#include "cafPdmUiOrdering.h"
#include "cafQShortenedLabel.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QTextEdit>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 );
Expand All @@ -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<std::pair<T, U>>
auto getTwoDoublesFromVariant = [=]() -> std::pair<double, double>
{
// A pair is converted into a list of QVariant in PdmValueFieldSpecialization<std::pair<T, U>>
double firstValue = 0.0;
double secondValue = 0.0;

auto variantValue = uiField()->uiValue();
if ( variantValue.canConvert<QList<QVariant>>() )
{
Expand All @@ -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 );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 0 additions & 8 deletions Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiSliderTools.h"

#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QSlider>
#include <QString>
#include <QWidget>

namespace caf
{
//==================================================================================================
Expand Down

0 comments on commit bb6f1fe

Please sign in to comment.