From 981684174e77f41d30c74203033dcd35a30480f3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 20 Sep 2023 15:18:56 +0200 Subject: [PATCH 01/14] Convert cross plots into summary plots Hide cross plot collection from GUI --- .../RimMainPlotCollection.cpp | 49 ++++++++++++++++--- .../ProjectDataModel/RimProject.cpp | 5 -- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp index f66ceac04a..da6602489f 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp @@ -20,6 +20,7 @@ #include "RimMainPlotCollection.h" #include "RiaPlotCollectionScheduler.h" +#include "RiaSummaryDefines.h" #include "PlotBuilderCommands/RicSummaryPlotBuilder.h" @@ -42,6 +43,8 @@ #include "RimStimPlanModelPlotCollection.h" #include "RimSummaryAddress.h" #include "RimSummaryCrossPlotCollection.h" +#include "RimSummaryCurve.h" +#include "RimSummaryDataSourceStepping.h" #include "RimSummaryMultiPlot.h" #include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlotCollection.h" @@ -176,17 +179,51 @@ RimMainPlotCollection* RimMainPlotCollection::current() //-------------------------------------------------------------------------------------------------- void RimMainPlotCollection::initAfterRead() { - std::vector plotsToMove; - for ( auto singlePlot : m_summaryPlotCollection_OBSOLETE()->plots() ) { - plotsToMove.push_back( singlePlot ); + std::vector plotsToMove; + for ( auto singlePlot : m_summaryPlotCollection_OBSOLETE()->plots() ) + { + plotsToMove.push_back( singlePlot ); + } + + for ( auto singlePlot : plotsToMove ) + { + m_summaryPlotCollection_OBSOLETE()->removePlot( singlePlot ); + + RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlotNoAutoSettings( singlePlot ); + } } - for ( auto singlePlot : plotsToMove ) + // Move cross plots into summary plot collection + auto crossPlots = m_summaryCrossPlotCollection_OBSOLETE->plots(); + if ( !crossPlots.empty() ) { - m_summaryPlotCollection_OBSOLETE()->removePlot( singlePlot ); + auto* summaryMultiPlot = new RimSummaryMultiPlot; + summaryMultiPlot->setMultiPlotTitle( QString( "Multi Plot %1" ).arg( m_summaryMultiPlotCollection->multiPlots().size() + 1 ) ); + summaryMultiPlot->setAsPlotMdiWindow(); + m_summaryMultiPlotCollection->addSummaryMultiPlot( summaryMultiPlot ); + + for ( auto crossPlot : crossPlots ) + { + m_summaryCrossPlotCollection_OBSOLETE->removePlot( crossPlot ); + summaryMultiPlot->addPlot( crossPlot ); - RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlotNoAutoSettings( singlePlot ); + // We want to convert RimSummaryCrossPlot into a RimSummaryPlot. The cross plot is derived from RimSummaryPlot, but we need to + // create a new RimSummaryPlot to be able to store the PDM object as a RimSummaryPlot instead of RimSummaryCrossPlot + auto summaryPlot = new RimSummaryPlot; + summaryMultiPlot->addPlot( summaryPlot ); + + for ( auto curve : crossPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) ) + { + crossPlot->removeCurve( curve ); + + if ( curve->summaryCaseX() != nullptr ) curve->setAxisTypeX( RiaDefines::HorizontalAxisType::SUMMARY_VECTOR ); + + summaryPlot->insertCurve( curve, size_t( 999 ) ); + } + + delete crossPlot; + } } } diff --git a/ApplicationLibCode/ProjectDataModel/RimProject.cpp b/ApplicationLibCode/ProjectDataModel/RimProject.cpp index b03393407c..9ad3c7c769 100644 --- a/ApplicationLibCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimProject.cpp @@ -1422,11 +1422,6 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q uiTreeOrdering.add( m_mainPlotCollection->correlationPlotCollection() ); } - if ( m_mainPlotCollection->summaryCrossPlotCollection() ) - { - uiTreeOrdering.add( m_mainPlotCollection->summaryCrossPlotCollection() ); - } - if ( m_mainPlotCollection->summaryTableCollection() ) { uiTreeOrdering.add( m_mainPlotCollection->summaryTableCollection() ); From 9979da797cb7b6f20ad427ec46d688c6d2cce818 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 20 Sep 2023 15:32:43 +0200 Subject: [PATCH 02/14] Add UI for filtering regression curve data in X and Y --- .../RimSummaryRegressionAnalysisCurve.cpp | 23 +++++++++++++++++++ .../RimSummaryRegressionAnalysisCurve.h | 8 +++++++ 2 files changed, 31 insertions(+) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp index bd2b10a1e4..cd1e5fc54e 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp @@ -94,6 +94,14 @@ RimSummaryRegressionAnalysisCurve::RimSummaryRegressionAnalysisCurve() m_expressionText.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); m_expressionText.uiCapability()->setUiReadOnly( true ); 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_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" ); } //-------------------------------------------------------------------------------------------------- @@ -260,6 +268,21 @@ void RimSummaryRegressionAnalysisCurve::defineUiOrdering( QString uiConfigName, timeSelectionGroup->add( &m_maxTimeStep ); timeSelectionGroup->add( &m_showTimeSelectionInPlot ); + 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_filterValuesY ); + timeSelectionGroup->add( &m_minValueY ); + timeSelectionGroup->add( &m_maxValueY ); + m_minValueY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); + m_maxValueY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); + } + caf::PdmUiGroup* forecastingGroup = uiOrdering.addNewGroup( "Forecasting" ); forecastingGroup->add( &m_forecastForward ); forecastingGroup->add( &m_forecastBackward ); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h index 6739656bf0..04988c3a7e 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h @@ -125,6 +125,14 @@ 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_filterValuesY; + caf::PdmField m_minValueY; + caf::PdmField m_maxValueY; + caf::PdmPointer m_timeRangeAnnotation; std::vector m_valuesX; std::vector m_timeStepsX; From ab84532c0f23f49ee10ae2feb5a2897774f45134 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 07:51:29 +0200 Subject: [PATCH 03/14] Filter input data before creating regression curve --- .../RimSummaryRegressionAnalysisCurve.cpp | 51 ++++++++++++++++++- .../RimSummaryRegressionAnalysisCurve.h | 1 + 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp index cd1e5fc54e..5dd77c5248 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp @@ -118,11 +118,58 @@ RimSummaryRegressionAnalysisCurve::~RimSummaryRegressionAnalysisCurve() //-------------------------------------------------------------------------------------------------- void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPlot ) { + // NB! Assume that time stamps for X and Y are the same + std::vector indicesToRemove; + + auto xValues = RimSummaryCurve::valuesX(); + auto timeStepsX = RimSummaryCurve::timeStepsX(); + auto yValues = RimSummaryCurve::valuesY(); + auto timeStepsY = RimSummaryCurve::timeStepsY(); + + if ( m_filterValuesX ) + { + auto values = xValues; + for ( size_t i = 0; i < values.size(); i++ ) + { + if ( values[i] < m_minValueX || values[i] > m_maxValueX ) + { + indicesToRemove.push_back( i ); + } + } + } + + if ( m_filterValuesY ) + { + auto values = yValues; + for ( size_t i = 0; i < values.size(); i++ ) + { + if ( values[i] < m_minValueY || values[i] > m_maxValueY ) + { + indicesToRemove.push_back( i ); + } + } + } + + // Step 2: Sort indices in descending order + std::sort( indicesToRemove.rbegin(), indicesToRemove.rend() ); + + // Step 3: Remove elements at the specified indices + for ( auto index : indicesToRemove ) + { + if ( index >= 0 && index < xValues.size() ) + { + xValues.erase( xValues.begin() + index ); + timeStepsX.erase( timeStepsX.begin() + index ); + yValues.erase( yValues.begin() + index ); + timeStepsY.erase( timeStepsY.begin() + index ); + } + } + QString descriptionX; - std::tie( m_timeStepsX, m_valuesX, descriptionX ) = computeRegressionCurve( RimSummaryCurve::timeStepsX(), RimSummaryCurve::valuesX() ); + std::tie( m_timeStepsX, m_valuesX, descriptionX ) = computeRegressionCurve( timeStepsX, xValues ); QString descriptionY; - std::tie( m_timeStepsY, m_valuesY, descriptionY ) = computeRegressionCurve( RimSummaryCurve::timeStepsY(), RimSummaryCurve::valuesY() ); + std::tie( m_timeStepsY, m_valuesY, descriptionY ) = computeRegressionCurve( timeStepsY, yValues ); m_expressionText = descriptionY; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h index 04988c3a7e..d72312dfb8 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h @@ -114,6 +114,7 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve static void appendTimeSteps( std::vector& destinationTimeSteps, const std::set& sourceTimeSteps ); +private: caf::PdmField> m_regressionType; caf::PdmField m_minTimeStep; caf::PdmField m_maxTimeStep; From f3d2571917c96094c675e7f5eff773e9c5c53f6f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 09:17:04 +0200 Subject: [PATCH 04/14] Add state to constructor --- .../cafUserInterface/cafPdmUiCheckBoxAndTextEditor.cpp | 5 +---- Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp | 6 +++--- Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxAndTextEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxAndTextEditor.cpp index 14bcf20c52..51aae11d98 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxAndTextEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiCheckBoxAndTextEditor.cpp @@ -100,10 +100,7 @@ QWidget* PdmUiCheckBoxAndTextEditor::createEditorWidget( QWidget* parent ) { auto* containerWidget = new QWidget( parent ); - auto lineEditWidget = new PdmUiLineEdit( containerWidget ); - lineEditWidget->setAvoidSendingEnterEventToParentWidget( true ); - - m_lineEdit = lineEditWidget; + m_lineEdit = new PdmUiLineEdit( containerWidget, true ); connect( m_lineEdit, SIGNAL( editingFinished() ), this, SLOT( slotSetValueToField() ) ); m_checkBox = new QCheckBox( "", containerWidget ); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp index 3a3405107b..db582988bd 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.cpp @@ -88,7 +88,7 @@ void PdmUiLineEditor::updateLineEditFromReadOnlyState( QLineEdit* lineEdit, bool //-------------------------------------------------------------------------------------------------- QWidget* PdmUiLineEditor::createEditorWidget( QWidget* parent ) { - m_lineEdit = new PdmUiLineEdit( parent ); + m_lineEdit = new PdmUiLineEdit( parent, false ); connect( m_lineEdit, SIGNAL( editingFinished() ), this, SLOT( slotEditingFinished() ) ); @@ -394,9 +394,9 @@ bool PdmUiLineEditor::isMultipleFieldsWithSameKeywordSelected( PdmFieldHandle* e //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -PdmUiLineEdit::PdmUiLineEdit( QWidget* parent ) +PdmUiLineEdit::PdmUiLineEdit( QWidget* parent, bool avoidSendingEnterEvent ) : QLineEdit( parent ) - , m_avoidSendingEnterEvent( false ) + , m_avoidSendingEnterEvent( avoidSendingEnterEvent ) { } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h index 20b1fe51f9..0dccd8c03c 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h @@ -102,7 +102,7 @@ class PdmUiLineEdit : public QLineEdit { Q_OBJECT public: - PdmUiLineEdit( QWidget* parent ); + PdmUiLineEdit( QWidget* parent, bool avoidSendingEnterEvent ); void setAvoidSendingEnterEventToParentWidget( bool avoidSendingEnter ); protected: From 67afaeb5913be3d4b392bad757e0d106fd574cbd Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 09:49:24 +0200 Subject: [PATCH 05/14] Add value range editor --- .../cafTestApplication/MainWindow.cpp | 8 + Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 3 + .../cafPdmUiValueRangeEditor.cpp | 359 ++++++++++++++++++ .../cafPdmUiValueRangeEditor.h | 98 +++++ 4 files changed, 468 insertions(+) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp index c7a7979810..741d220360 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp @@ -41,6 +41,7 @@ #include "cafPdmUiTextEditor.h" #include "cafPdmUiTreeSelectionEditor.h" #include "cafPdmUiTreeView.h" +#include "cafPdmUiValueRangeEditor.h" #include "cafSelectionManager.h" #include @@ -956,6 +957,9 @@ class DemoPdmObject : public caf::PdmObject CAF_PDM_InitField( &m_filePath, "FilePath", QString( "" ), "Filename", "", "", "" ); CAF_PDM_InitField( &m_longText, "LongText", QString( "Test text" ), "Long Text", "", "", "" ); + CAF_PDM_InitField( &m_minMaxSlider, "MinMaxSlider", std::make_pair( 2.5, 10.1 ), "Min max slider", "", "", "" ); + m_minMaxSlider.uiCapability()->setUiEditorTypeName( caf::PdmUiValueRangeEditor::uiEditorTypeName() ); + CAF_PDM_InitFieldNoDefault( &m_multiSelectList, "MultiSelect", "Selection List", "", "List", "This is a multi selection list" ); CAF_PDM_InitFieldNoDefault( &m_objectList, "ObjectList", "Objects list Field", "", "List", "This is a list of PdmObjects" ); CAF_PDM_InitFieldNoDefault( &m_objectListOfSameType, @@ -984,6 +988,8 @@ class DemoPdmObject : public caf::PdmObject uiOrdering.add( &m_applyAutoOnChildObjectFields ); uiOrdering.add( &m_updateAutoValues ); + uiOrdering.add( &m_minMaxSlider ); + uiOrdering.add( &m_objectListOfSameType ); uiOrdering.add( &m_ptrField ); uiOrdering.add( &m_boolField ); @@ -1041,6 +1047,8 @@ class DemoPdmObject : public caf::PdmObject caf::PdmField m_filePath; + caf::PdmField> m_minMaxSlider; + caf::PdmField m_longText; caf::PdmField> m_multiSelectList; diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index 8581ee3334..9fa88573ef 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -52,6 +52,7 @@ set(MOC_HEADER_FILES cafPdmUiPickableLineEditor.h cafPdmUiLabelEditor.h cafPdmUiCheckBoxAndTextEditor.h + cafPdmUiValueRangeEditor.h ) find_package( @@ -108,6 +109,8 @@ set(PROJECT_FILES cafPdmUiLabelEditor.cpp cafPdmUiCheckBoxAndTextEditor.h cafPdmUiCheckBoxAndTextEditor.cpp + cafPdmUiValueRangeEditor.h + cafPdmUiValueRangeEditor.cpp # object editors cafPdmUiDefaultObjectEditor.cpp cafPdmUiDefaultObjectEditor.h diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp new file mode 100644 index 0000000000..916632c0a6 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -0,0 +1,359 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2023 Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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 <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiValueRangeEditor.h" + +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmUiDefaultObjectEditor.h" +#include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiLineEditor.h" +#include "cafPdmUiOrdering.h" +#include "cafQShortenedLabel.h" + +#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 ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) +{ + PdmUiFieldEditorHandle::updateLabelFromField( m_label, uiConfigName ); + + m_lineEditMin->setEnabled( !uiField()->isUiReadOnly( uiConfigName ) ); + m_sliderMin->setEnabled( !uiField()->isUiReadOnly( uiConfigName ) ); + m_lineEditMax->setEnabled( !uiField()->isUiReadOnly( uiConfigName ) ); + m_sliderMax->setEnabled( !uiField()->isUiReadOnly( uiConfigName ) ); + + caf::PdmUiObjectHandle* uiObject = uiObj( uiField()->fieldHandle()->ownerObject() ); + if ( uiObject ) + { + uiObject->editorAttribute( uiField()->fieldHandle(), uiConfigName, &m_attributes ); + } + + double firstValue = 0.0; + double secondValue = 0.0; + { + // A pair is converted into a list of QVariant in PdmValueFieldSpecialization> + auto variantValue = uiField()->uiValue(); + if ( variantValue.canConvert>() ) + { + QList lst = variantValue.toList(); + if ( lst.size() == 2 ) + { + firstValue = lst[0].toDouble(); + secondValue = lst[1].toDouble(); + } + } + } + + { + m_sliderMin->blockSignals( true ); + m_sliderMin->setMaximum( m_attributes.m_sliderTickCount ); + m_sliderMin->blockSignals( false ); + + QString textValueMin = QString( "%1" ).arg( firstValue ); + + PdmDoubleValidator* pdmValidator = + new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); + pdmValidator->fixup( textValueMin ); + + m_lineEditMin->setValidator( pdmValidator ); + m_lineEditMin->setText( textValueMin ); + + m_sliderValueMin = firstValue; + updateSliderPosition( m_sliderMin, firstValue ); + } + + { + m_sliderMax->blockSignals( true ); + m_sliderMax->setMaximum( m_attributes.m_sliderTickCount ); + m_sliderMax->blockSignals( false ); + + QString textValueMax = QString( "%1" ).arg( secondValue ); + + 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 = secondValue; + updateSliderPosition( m_sliderMax, secondValue ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotMinEditingFinished() +{ + QString minText = m_lineEditMin->text(); + QString maxText = m_lineEditMax->text(); + + double minValue = minText.toDouble(); + double maxValue = maxText.toDouble(); + + clampAndWriteValues( minValue, maxValue, true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotMaxEditingFinished() +{ + QString minText = m_lineEditMin->text(); + QString maxText = m_lineEditMax->text(); + + double minValue = minText.toDouble(); + double maxValue = maxText.toDouble(); + + clampAndWriteValues( minValue, maxValue, false ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotMinSliderValueChanged( int value ) +{ + double newDoubleValue = convertFromSliderValue( m_sliderMin, value ); + m_sliderValueMin = newDoubleValue; + + if ( m_attributes.m_delaySliderUpdateUntilRelease ) + { + m_lineEditMin->setText( QString( "%1" ).arg( m_sliderValueMin ) ); + } + else + { + clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, true ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotMaxSliderValueChanged( int value ) +{ + double newDoubleValue = convertFromSliderValue( m_sliderMax, value ); + m_sliderValueMax = newDoubleValue; + + if ( m_attributes.m_delaySliderUpdateUntilRelease ) + { + m_lineEditMax->setText( QString( "%1" ).arg( m_sliderValueMax ) ); + } + else + { + clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, false ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotSliderReleasedMin() +{ + clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::slotSliderReleasedMax() +{ + clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, false ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::updateSliderPosition( QSlider* slider, double value ) +{ + int newSliderPosition = convertToSliderValue( slider, value ); + if ( slider->value() != newSliderPosition ) + { + slider->blockSignals( true ); + slider->setValue( newSliderPosition ); + slider->blockSignals( false ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ) +{ + if ( isMinChanged ) + { + if ( valueMin > valueMax ) valueMax = valueMin; + } + else + { + if ( valueMax < valueMin ) valueMin = valueMax; + } + + valueMin = qBound( m_attributes.m_minimum, valueMin, valueMax ); + valueMax = qBound( valueMin, valueMax, m_attributes.m_maximum ); + m_sliderValueMin = valueMin; + m_sliderValueMax = valueMax; + + clampAndWriteValues( valueMin, valueMax ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMax ) +{ + auto pairValue = std::make_pair( valueMin, valueMax ); + + QVariant v = caf::PdmValueFieldSpecialization>::convert( pairValue ); + setValueToField( v ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int PdmUiValueRangeEditor::convertToSliderValue( QSlider* slider, double value ) +{ + double exactSliderValue = + slider->maximum() * ( value - m_attributes.m_minimum ) / ( m_attributes.m_maximum - m_attributes.m_minimum ); + + int sliderValue = static_cast( exactSliderValue + 0.5 ); + sliderValue = qBound( slider->minimum(), sliderValue, slider->maximum() ); + + return sliderValue; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double PdmUiValueRangeEditor::convertFromSliderValue( QSlider* slider, int sliderValue ) +{ + double newDoubleValue = m_attributes.m_minimum + + sliderValue * ( m_attributes.m_maximum - m_attributes.m_minimum ) / slider->maximum(); + newDoubleValue = qBound( m_attributes.m_minimum, newDoubleValue, m_attributes.m_maximum ); + + return newDoubleValue; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiValueRangeEditor::createEditorWidget( QWidget* parent ) +{ + QWidget* 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_sliderMin = new QSlider( Qt::Horizontal, containerWidget ); + + 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() ) ); + } + + { + m_lineEditMax = new QLineEdit( containerWidget ); + m_lineEditMax->setMaximumWidth( 100 ); + connect( m_lineEditMax, SIGNAL( editingFinished() ), this, SLOT( slotMaxEditingFinished() ) ); + + m_sliderMax = new QSlider( Qt::Horizontal, containerWidget ); + + 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() ) ); + } + return containerWidget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* PdmUiValueRangeEditor::createLabelWidget( QWidget* parent ) +{ + m_label = new QShortenedLabel( parent ); + return m_label; +} + +} // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h new file mode 100644 index 0000000000..6ecfa10b74 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -0,0 +1,98 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2023 Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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 <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiDoubleSliderEditor.h" +#include "cafPdmUiFieldEditorHandle.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace caf +{ +//================================================================================================== +/// +//================================================================================================== +class PdmUiValueRangeEditor : public PdmUiFieldEditorHandle +{ + Q_OBJECT + CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; + +public: + PdmUiValueRangeEditor() {} + ~PdmUiValueRangeEditor() override {} + +protected: + QWidget* createEditorWidget( QWidget* parent ) override; + QWidget* createLabelWidget( QWidget* parent ) override; + void configureAndUpdateUi( const QString& uiConfigName ) override; + +protected slots: + void slotMinEditingFinished(); + void slotMaxEditingFinished(); + void slotMinSliderValueChanged( int value ); + void slotMaxSliderValueChanged( int value ); + void slotSliderReleasedMin(); + void slotSliderReleasedMax(); + +private: + void updateSliderPosition( QSlider* slider, double value ); + void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); + void clampAndWriteValues( double valueMin, double valueMax); + + int convertToSliderValue( QSlider* slider, double value ); + double convertFromSliderValue( QSlider* slider, int sliderValue ); + +private: + QPointer m_lineEditMin; + QPointer m_sliderMin; + QPointer m_lineEditMax; + QPointer m_sliderMax; + + QPointer m_label; + double m_sliderValueMin; + double m_sliderValueMax; + + PdmUiDoubleSliderEditorAttribute m_attributes; +}; + +} // end namespace caf From 4f5257ac46f05197e9ab8f547442feda3bb0ca66 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:03:45 +0200 Subject: [PATCH 06/14] Move common code to UiSliderTools --- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 2 + .../cafPdmUiDoubleSliderEditor.cpp | 15 ++++ .../cafPdmUiDoubleSliderEditor.h | 28 +------ .../cafUserInterface/cafPdmUiSliderTools.cpp | 69 ++++++++++++++++ .../cafUserInterface/cafPdmUiSliderTools.h | 80 +++++++++++++++++++ .../cafPdmUiValueRangeEditor.cpp | 16 ++++ .../cafPdmUiValueRangeEditor.h | 8 +- 7 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index 9fa88573ef..81bc726a87 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -174,6 +174,8 @@ set(PROJECT_FILES cafPdmUiTreeAttributes.h cafUiAppearanceSettings.cpp cafUiIconFactory.cpp + cafPdmUiSliderTools.h + cafPdmUiSliderTools.cpp ) add_library( diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp index 63df36dbfd..f3dd01e153 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp @@ -78,6 +78,21 @@ namespace caf { CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT( PdmUiDoubleSliderEditor ); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiDoubleSliderEditor::PdmUiDoubleSliderEditor() + : m_sliderValue( 0.0 ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiDoubleSliderEditor::~PdmUiDoubleSliderEditor() +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h index bbfc903a4d..661b7fc601 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h @@ -35,7 +35,9 @@ //################################################################################################## #pragma once + #include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiSliderTools.h" #include #include @@ -46,28 +48,6 @@ namespace caf { -//================================================================================================== -/// -//================================================================================================== -class PdmUiDoubleSliderEditorAttribute : public PdmUiEditorAttribute -{ -public: - PdmUiDoubleSliderEditorAttribute() - { - m_minimum = 0; - m_maximum = 10; - m_decimals = 6; - m_sliderTickCount = 2000; - m_delaySliderUpdateUntilRelease = false; - } - -public: - double m_minimum; - double m_maximum; - int m_decimals; - int m_sliderTickCount; - bool m_delaySliderUpdateUntilRelease; -}; //================================================================================================== /// @@ -78,8 +58,8 @@ class PdmUiDoubleSliderEditor : public PdmUiFieldEditorHandle CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; public: - PdmUiDoubleSliderEditor() {} - ~PdmUiDoubleSliderEditor() override {} + PdmUiDoubleSliderEditor(); + ~PdmUiDoubleSliderEditor() override; protected: void configureAndUpdateUi( const QString& uiConfigName ) override; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp new file mode 100644 index 0000000000..ad192587e5 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp @@ -0,0 +1,69 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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 <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiSliderTools.h" + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmDoubleValidator::PdmDoubleValidator( QObject* parent /*= nullptr */ ) + : QDoubleValidator( parent ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmDoubleValidator::PdmDoubleValidator( double bottom, double top, int decimals, QObject* parent ) + : QDoubleValidator( bottom, top, decimals, parent ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmDoubleValidator::fixup( QString& stringValue ) const +{ + double doubleValue = stringValue.toDouble(); + doubleValue = qBound( bottom(), doubleValue, top() ); + + stringValue = QString::number( doubleValue, 'g', decimals() ); +} + +} //namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h new file mode 100644 index 0000000000..8c6ef3d448 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h @@ -0,0 +1,80 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library 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. +// +// This library 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 <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiFieldEditorHandle.h" + +#include + +namespace caf +{ +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class PdmDoubleValidator : public QDoubleValidator +{ +public: + explicit PdmDoubleValidator( QObject* parent = nullptr ); + explicit PdmDoubleValidator( double bottom, double top, int decimals, QObject* parent ); + + void fixup( QString& stringValue ) const override; +}; + +//================================================================================================== +/// +//================================================================================================== +class PdmUiDoubleSliderEditorAttribute : public PdmUiEditorAttribute +{ +public: + PdmUiDoubleSliderEditorAttribute() + { + m_minimum = 0; + m_maximum = 10; + m_decimals = 6; + m_sliderTickCount = 2000; + m_delaySliderUpdateUntilRelease = false; + } + +public: + double m_minimum; + double m_maximum; + int m_decimals; + int m_sliderTickCount; + bool m_delaySliderUpdateUntilRelease; +}; + +} //namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index 916632c0a6..42204176e5 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -306,6 +306,22 @@ double PdmUiValueRangeEditor::convertFromSliderValue( QSlider* slider, int slide return newDoubleValue; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiValueRangeEditor::PdmUiValueRangeEditor() + : m_sliderValueMin( 0.0 ) + , m_sliderValueMax( 0.0 ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiValueRangeEditor::~PdmUiValueRangeEditor() +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index 6ecfa10b74..4fba2e42ae 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -36,8 +36,8 @@ #pragma once -#include "cafPdmUiDoubleSliderEditor.h" #include "cafPdmUiFieldEditorHandle.h" +#include "cafPdmUiSliderTools.h" #include #include @@ -58,8 +58,8 @@ class PdmUiValueRangeEditor : public PdmUiFieldEditorHandle CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT; public: - PdmUiValueRangeEditor() {} - ~PdmUiValueRangeEditor() override {} + PdmUiValueRangeEditor(); + ~PdmUiValueRangeEditor() override; protected: QWidget* createEditorWidget( QWidget* parent ) override; @@ -77,7 +77,7 @@ protected slots: private: void updateSliderPosition( QSlider* slider, double value ); void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); - void clampAndWriteValues( double valueMin, double valueMax); + void clampAndWriteValues( double valueMin, double valueMax ); int convertToSliderValue( QSlider* slider, double value ); double convertFromSliderValue( QSlider* slider, int sliderValue ); From 6d0c5405bcf5fed78f4de2cff24a7420c40497d1 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:08:47 +0200 Subject: [PATCH 07/14] Create static functions --- .../cafPdmUiValueRangeEditor.cpp | 34 ++++++++++++------- .../cafPdmUiValueRangeEditor.h | 7 ++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index 42204176e5..e1928af9af 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -131,7 +131,7 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) m_lineEditMin->setText( textValueMin ); m_sliderValueMin = firstValue; - updateSliderPosition( m_sliderMin, firstValue ); + updateSliderPosition( m_sliderMin, firstValue, m_attributes ); } { @@ -149,7 +149,7 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) m_lineEditMax->setText( textValueMax ); m_sliderValueMax = secondValue; - updateSliderPosition( m_sliderMax, secondValue ); + updateSliderPosition( m_sliderMax, secondValue, m_attributes ); } } @@ -186,7 +186,7 @@ void PdmUiValueRangeEditor::slotMaxEditingFinished() //-------------------------------------------------------------------------------------------------- void PdmUiValueRangeEditor::slotMinSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( m_sliderMin, value ); + double newDoubleValue = convertFromSliderValue( m_sliderMin, value, m_attributes ); m_sliderValueMin = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -204,7 +204,7 @@ void PdmUiValueRangeEditor::slotMinSliderValueChanged( int value ) //-------------------------------------------------------------------------------------------------- void PdmUiValueRangeEditor::slotMaxSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( m_sliderMax, value ); + double newDoubleValue = convertFromSliderValue( m_sliderMax, value, m_attributes ); m_sliderValueMax = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -236,9 +236,13 @@ void PdmUiValueRangeEditor::slotSliderReleasedMax() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiValueRangeEditor::updateSliderPosition( QSlider* slider, double value ) +void PdmUiValueRangeEditor::updateSliderPosition( QSlider* slider, + double value, + const PdmUiDoubleSliderEditorAttribute& attributes ) { - int newSliderPosition = convertToSliderValue( slider, value ); + if ( !slider ) return; + + int newSliderPosition = convertToSliderValue( slider, value, attributes ); if ( slider->value() != newSliderPosition ) { slider->blockSignals( true ); @@ -283,10 +287,12 @@ void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMa //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -int PdmUiValueRangeEditor::convertToSliderValue( QSlider* slider, double value ) +int PdmUiValueRangeEditor::convertToSliderValue( QSlider* slider, + double value, + const PdmUiDoubleSliderEditorAttribute& attributes ) { double exactSliderValue = - slider->maximum() * ( value - m_attributes.m_minimum ) / ( m_attributes.m_maximum - m_attributes.m_minimum ); + slider->maximum() * ( value - attributes.m_minimum ) / ( attributes.m_maximum - attributes.m_minimum ); int sliderValue = static_cast( exactSliderValue + 0.5 ); sliderValue = qBound( slider->minimum(), sliderValue, slider->maximum() ); @@ -297,13 +303,15 @@ int PdmUiValueRangeEditor::convertToSliderValue( QSlider* slider, double value ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double PdmUiValueRangeEditor::convertFromSliderValue( QSlider* slider, int sliderValue ) +double PdmUiValueRangeEditor::convertFromSliderValue( QSlider* slider, + int sliderValue, + const PdmUiDoubleSliderEditorAttribute& attributes ) { - double newDoubleValue = m_attributes.m_minimum + - sliderValue * ( m_attributes.m_maximum - m_attributes.m_minimum ) / slider->maximum(); - newDoubleValue = qBound( m_attributes.m_minimum, newDoubleValue, m_attributes.m_maximum ); + double clampedValue = attributes.m_minimum + + sliderValue * ( attributes.m_maximum - attributes.m_minimum ) / slider->maximum(); + clampedValue = qBound( attributes.m_minimum, clampedValue, attributes.m_maximum ); - return newDoubleValue; + return clampedValue; } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index 4fba2e42ae..9bf54ecbed 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -75,12 +75,13 @@ protected slots: void slotSliderReleasedMax(); private: - void updateSliderPosition( QSlider* slider, double value ); void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); void clampAndWriteValues( double valueMin, double valueMax ); - int convertToSliderValue( QSlider* slider, double value ); - double convertFromSliderValue( QSlider* slider, int sliderValue ); + static void updateSliderPosition( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); + static int convertToSliderValue( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); + static double + convertFromSliderValue( QSlider* slider, int sliderValue, const PdmUiDoubleSliderEditorAttribute& attributes ); private: QPointer m_lineEditMin; From c0fc26f8a5f98c6903545cf1502865a641d694e1 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:13:00 +0200 Subject: [PATCH 08/14] Use static methods --- .../cafUserInterface/cafPdmUiSliderTools.cpp | 46 +++++++++++++++ .../cafUserInterface/cafPdmUiSliderTools.h | 11 ++++ .../cafPdmUiValueRangeEditor.cpp | 56 ++----------------- .../cafPdmUiValueRangeEditor.h | 5 -- 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp index ad192587e5..6ba2b5d2ba 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.cpp @@ -36,6 +36,8 @@ #include "cafPdmUiSliderTools.h" +#include + namespace caf { @@ -66,4 +68,48 @@ void PdmDoubleValidator::fixup( QString& stringValue ) const stringValue = QString::number( doubleValue, 'g', decimals() ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiSliderTools::updateSliderPosition( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ) +{ + if ( !slider ) return; + + int newSliderPosition = convertToSliderValue( slider, value, attributes ); + if ( slider->value() != newSliderPosition ) + { + slider->blockSignals( true ); + slider->setValue( newSliderPosition ); + slider->blockSignals( false ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int PdmUiSliderTools::convertToSliderValue( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ) +{ + double exactSliderValue = + slider->maximum() * ( value - attributes.m_minimum ) / ( attributes.m_maximum - attributes.m_minimum ); + + int sliderValue = static_cast( exactSliderValue + 0.5 ); + sliderValue = qBound( slider->minimum(), sliderValue, slider->maximum() ); + + return sliderValue; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double PdmUiSliderTools::convertFromSliderValue( QSlider* slider, + int sliderValue, + const PdmUiDoubleSliderEditorAttribute& attributes ) +{ + double clampedValue = attributes.m_minimum + + sliderValue * ( attributes.m_maximum - attributes.m_minimum ) / slider->maximum(); + clampedValue = qBound( attributes.m_minimum, clampedValue, attributes.m_maximum ); + + return clampedValue; +} + } //namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h index 8c6ef3d448..f5df6ee5a4 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiSliderTools.h @@ -40,6 +40,8 @@ #include +class QSlider; + namespace caf { //-------------------------------------------------------------------------------------------------- @@ -77,4 +79,13 @@ class PdmUiDoubleSliderEditorAttribute : public PdmUiEditorAttribute bool m_delaySliderUpdateUntilRelease; }; +class PdmUiSliderTools +{ +public: + static void updateSliderPosition( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); + static int convertToSliderValue( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); + static double + convertFromSliderValue( QSlider* slider, int sliderValue, const PdmUiDoubleSliderEditorAttribute& attributes ); +}; + } //namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index e1928af9af..593476a255 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -131,7 +131,7 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) m_lineEditMin->setText( textValueMin ); m_sliderValueMin = firstValue; - updateSliderPosition( m_sliderMin, firstValue, m_attributes ); + PdmUiSliderTools::updateSliderPosition( m_sliderMin, firstValue, m_attributes ); } { @@ -149,7 +149,7 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) m_lineEditMax->setText( textValueMax ); m_sliderValueMax = secondValue; - updateSliderPosition( m_sliderMax, secondValue, m_attributes ); + PdmUiSliderTools::updateSliderPosition( m_sliderMax, secondValue, m_attributes ); } } @@ -186,7 +186,7 @@ void PdmUiValueRangeEditor::slotMaxEditingFinished() //-------------------------------------------------------------------------------------------------- void PdmUiValueRangeEditor::slotMinSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( m_sliderMin, value, m_attributes ); + double newDoubleValue = PdmUiSliderTools::convertFromSliderValue( m_sliderMin, value, m_attributes ); m_sliderValueMin = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -204,7 +204,7 @@ void PdmUiValueRangeEditor::slotMinSliderValueChanged( int value ) //-------------------------------------------------------------------------------------------------- void PdmUiValueRangeEditor::slotMaxSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( m_sliderMax, value, m_attributes ); + double newDoubleValue = PdmUiSliderTools::convertFromSliderValue( m_sliderMax, value, m_attributes ); m_sliderValueMax = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -233,24 +233,6 @@ void PdmUiValueRangeEditor::slotSliderReleasedMax() clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, false ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void PdmUiValueRangeEditor::updateSliderPosition( QSlider* slider, - double value, - const PdmUiDoubleSliderEditorAttribute& attributes ) -{ - if ( !slider ) return; - - int newSliderPosition = convertToSliderValue( slider, value, attributes ); - if ( slider->value() != newSliderPosition ) - { - slider->blockSignals( true ); - slider->setValue( newSliderPosition ); - slider->blockSignals( false ); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -284,36 +266,6 @@ void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMa setValueToField( v ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int PdmUiValueRangeEditor::convertToSliderValue( QSlider* slider, - double value, - const PdmUiDoubleSliderEditorAttribute& attributes ) -{ - double exactSliderValue = - slider->maximum() * ( value - attributes.m_minimum ) / ( attributes.m_maximum - attributes.m_minimum ); - - int sliderValue = static_cast( exactSliderValue + 0.5 ); - sliderValue = qBound( slider->minimum(), sliderValue, slider->maximum() ); - - return sliderValue; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double PdmUiValueRangeEditor::convertFromSliderValue( QSlider* slider, - int sliderValue, - const PdmUiDoubleSliderEditorAttribute& attributes ) -{ - double clampedValue = attributes.m_minimum + - sliderValue * ( attributes.m_maximum - attributes.m_minimum ) / slider->maximum(); - clampedValue = qBound( attributes.m_minimum, clampedValue, attributes.m_maximum ); - - return clampedValue; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index 9bf54ecbed..1cf27adcd0 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -78,11 +78,6 @@ protected slots: void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); void clampAndWriteValues( double valueMin, double valueMax ); - static void updateSliderPosition( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); - static int convertToSliderValue( QSlider* slider, double value, const PdmUiDoubleSliderEditorAttribute& attributes ); - static double - convertFromSliderValue( QSlider* slider, int sliderValue, const PdmUiDoubleSliderEditorAttribute& attributes ); - private: QPointer m_lineEditMin; QPointer m_sliderMin; From 27c824c4f5a761d2359c60b3304081c38842ff0f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:16:38 +0200 Subject: [PATCH 09/14] Cleanup use of slider tools --- .../cafPdmUiDoubleSliderEditor.cpp | 74 +------------------ .../cafPdmUiDoubleSliderEditor.h | 7 +- 2 files changed, 4 insertions(+), 77 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp index f3dd01e153..890e8a7005 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.cpp @@ -44,36 +44,6 @@ #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( PdmUiDoubleSliderEditor ); @@ -126,7 +96,7 @@ void PdmUiDoubleSliderEditor::configureAndUpdateUi( const QString& uiConfigName m_lineEdit->setText( textValue ); m_sliderValue = doubleValue; - updateSliderPosition( doubleValue ); + PdmUiSliderTools::updateSliderPosition( m_slider, doubleValue, m_attributes ); } //-------------------------------------------------------------------------------------------------- @@ -182,7 +152,7 @@ void PdmUiDoubleSliderEditor::slotEditingFinished() //-------------------------------------------------------------------------------------------------- void PdmUiDoubleSliderEditor::slotSliderValueChanged( int value ) { - double newDoubleValue = convertFromSliderValue( value ); + double newDoubleValue = PdmUiSliderTools::convertFromSliderValue( m_slider, value, m_attributes ); m_sliderValue = newDoubleValue; if ( m_attributes.m_delaySliderUpdateUntilRelease ) @@ -203,20 +173,6 @@ void PdmUiDoubleSliderEditor::slotSliderReleased() writeValueToField( m_sliderValue ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void PdmUiDoubleSliderEditor::updateSliderPosition( double value ) -{ - int newSliderPosition = convertToSliderValue( value ); - if ( m_slider->value() != newSliderPosition ) - { - m_slider->blockSignals( true ); - m_slider->setValue( newSliderPosition ); - m_slider->blockSignals( false ); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -226,30 +182,4 @@ void PdmUiDoubleSliderEditor::writeValueToField( double value ) this->setValueToField( v ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int PdmUiDoubleSliderEditor::convertToSliderValue( double value ) -{ - double exactSliderValue = - m_slider->maximum() * ( value - m_attributes.m_minimum ) / ( m_attributes.m_maximum - m_attributes.m_minimum ); - - int sliderValue = static_cast( exactSliderValue + 0.5 ); - sliderValue = qBound( m_slider->minimum(), sliderValue, m_slider->maximum() ); - - return sliderValue; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -double PdmUiDoubleSliderEditor::convertFromSliderValue( int sliderValue ) -{ - double newDoubleValue = m_attributes.m_minimum + - sliderValue * ( m_attributes.m_maximum - m_attributes.m_minimum ) / m_slider->maximum(); - newDoubleValue = qBound( m_attributes.m_minimum, newDoubleValue, m_attributes.m_maximum ); - - return newDoubleValue; -} - } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h index 661b7fc601..34c73c5b6b 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleSliderEditor.h @@ -44,7 +44,8 @@ #include #include #include -#include + +class QWidget; namespace caf { @@ -72,12 +73,8 @@ protected slots: void slotSliderReleased(); private: - void updateSliderPosition( double value ); void writeValueToField( double value ); - int convertToSliderValue( double value ); - double convertFromSliderValue( int sliderValue ); - private: QPointer m_lineEdit; QPointer m_slider; From 5cc3db00eadff2525cdbb75b1cd8ec6b6de20aad Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 10:54:23 +0200 Subject: [PATCH 10/14] Define default editor --- .../cafPdmUiDefaultObjectEditor.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index b6a4d4d182..2ed1044be5 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -75,15 +75,22 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR( PdmUiTreeSelectionEditor, std::vector< CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR( PdmUiFilePathEditor, FilePath ); -// As the macro CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR() is not working correctly for std::pair the +// As the macro CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR() is not working correctly for std::pair<> the // registration of this type in the factory has to be written directly -static bool myPdmUiCheckBoxAndTextEditor73 = +static bool myPdmUiCheckBoxAndTextEditor = caf::Factory::instance()->registerCreator( QString( typeid( caf::PdmField> ).name() ) ); -static bool my2PdmUiCheckBoxAndTextEditor73 = +static bool myPdmUiCheckBoxAndTextEditor_proxy = caf::Factory::instance()->registerCreator( QString( typeid( caf::PdmProxyValueField> ).name() ) ); +static bool myPdmUiValueRangeEditor = + caf::Factory::instance()->registerCreator( + QString( typeid( caf::PdmField> ).name() ) ); +static bool myPdmUiValueRangeEditor_proxy = + caf::Factory::instance()->registerCreator( + QString( typeid( caf::PdmProxyValueField> ).name() ) ); + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- From bb6f1fe9964d3c73401b77ae22fc209d3cbf7836 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 11:23:00 +0200 Subject: [PATCH 11/14] 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 { //================================================================================================== From 40d2aa2dcc4dfd44bc0ee08e88cd7518e0e645e8 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 11:46:27 +0200 Subject: [PATCH 12/14] cleanup --- .../RimSummaryRegressionAnalysisCurve.cpp | 28 ++++++++++++------- .../RimSummaryRegressionAnalysisCurve.h | 3 -- .../cafPdmUiValueRangeEditor.cpp | 10 +++---- .../cafPdmUiValueRangeEditor.h | 6 ++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp index 7838f221a1..5a47421158 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.cpp @@ -27,6 +27,7 @@ #include "cafPdmUiDateEditor.h" #include "cafPdmUiLineEditor.h" +#include "cafPdmUiSliderEditor.h" #include "cafPdmUiSliderTools.h" #include "cafPdmUiTextEditor.h" @@ -95,12 +96,11 @@ RimSummaryRegressionAnalysisCurve::RimSummaryRegressionAnalysisCurve() m_expressionText.uiCapability()->setUiReadOnly( true ); m_expressionText.xmlCapability()->disableIO(); - CAF_PDM_InitField( &m_filterValuesX, "FilterValuesX", false, "Filter 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_valueRangeY, "ValueRangeY", std::make_pair( 0.0, 0.0 ), "Value Range Y" ); + m_valueRangeY.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); } //-------------------------------------------------------------------------------------------------- @@ -125,7 +125,6 @@ void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPl auto yValues = RimSummaryCurve::valuesY(); auto timeStepsY = RimSummaryCurve::timeStepsY(); - if ( m_filterValuesX ) { auto values = xValues; for ( size_t i = 0; i < values.size(); i++ ) @@ -137,7 +136,6 @@ void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPl } } - if ( m_filterValuesY ) { auto values = yValues; for ( size_t i = 0; i < values.size(); i++ ) @@ -316,13 +314,11 @@ void RimSummaryRegressionAnalysisCurve::defineUiOrdering( QString uiConfigName, if ( axisTypeX() == RiaDefines::HorizontalAxisType::SUMMARY_VECTOR ) { - timeSelectionGroup->add( &m_filterValuesX ); - timeSelectionGroup->add( &m_valueRangeX ); - m_valueRangeX.uiCapability()->setUiReadOnly( !m_filterValuesX() ); + caf::PdmUiGroup* valueRangeXGroup = uiOrdering.addNewGroup( "Value Range X" ); + valueRangeXGroup->add( &m_valueRangeX ); - timeSelectionGroup->add( &m_filterValuesY ); - timeSelectionGroup->add( &m_valueRangeY ); - m_valueRangeY.uiCapability()->setUiReadOnly( !m_filterValuesY() ); + caf::PdmUiGroup* valueRangeYGroup = uiOrdering.addNewGroup( "Value Range Y" ); + valueRangeYGroup->add( &m_valueRangeY ); } caf::PdmUiGroup* forecastingGroup = uiOrdering.addNewGroup( "Forecasting" ); @@ -643,6 +639,18 @@ void RimSummaryRegressionAnalysisCurve::updateDefaultValues() m_minTimeStep = timeSteps.front(); m_maxTimeStep = timeSteps.back(); } + + auto values = RimSummaryCurve::valuesX(); + if ( !values.empty() ) + { + m_valueRangeX = std::make_pair( *std::min_element( values.begin(), values.end() ), *std::max_element( values.begin(), values.end() ) ); + } + + values = RimSummaryCurve::valuesY(); + if ( !values.empty() ) + { + m_valueRangeY = std::make_pair( *std::min_element( values.begin(), values.end() ), *std::max_element( values.begin(), values.end() ) ); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h index df4eac7273..5fd94148de 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryRegressionAnalysisCurve.h @@ -126,10 +126,7 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve caf::PdmField m_forecastBackward; caf::PdmField> m_forecastUnit; - caf::PdmField m_filterValuesX; caf::PdmField> m_valueRangeX; - - caf::PdmField m_filterValuesY; caf::PdmField> m_valueRangeY; caf::PdmPointer m_timeRangeAnnotation; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index b8507ea540..9ff10d2fdb 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -114,8 +114,6 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) QString textValueMax = QString( "%1" ).arg( maximum ); - PdmDoubleValidator* pdmValidator = - new PdmDoubleValidator( m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this ); pdmValidator->fixup( textValueMax ); m_lineEditMax->setValidator( pdmValidator ); @@ -192,7 +190,7 @@ void PdmUiValueRangeEditor::slotMaxSliderValueChanged( int value ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiValueRangeEditor::slotSliderReleasedMin() +void PdmUiValueRangeEditor::slotMinSliderReleased() { clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, true ); } @@ -200,7 +198,7 @@ void PdmUiValueRangeEditor::slotSliderReleasedMin() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiValueRangeEditor::slotSliderReleasedMax() +void PdmUiValueRangeEditor::slotMaxSliderReleased() { clampAndWriteValues( m_sliderValueMin, m_sliderValueMax, false ); } @@ -275,7 +273,7 @@ QWidget* PdmUiValueRangeEditor::createEditorWidget( QWidget* parent ) 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( sliderReleased() ), this, SLOT( slotMinSliderReleased() ) ); m_lineEditMax = new QLineEdit( containerWidget ); m_lineEditMax->setMaximumWidth( 100 ); @@ -287,7 +285,7 @@ QWidget* PdmUiValueRangeEditor::createEditorWidget( QWidget* parent ) 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( sliderReleased() ), this, SLOT( slotMaxSliderReleased() ) ); return containerWidget; } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index a7f3a7f1a5..f4e09cb02e 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -58,13 +58,13 @@ class PdmUiValueRangeEditor : public PdmUiFieldEditorHandle QWidget* createLabelWidget( QWidget* parent ) override; void configureAndUpdateUi( const QString& uiConfigName ) override; -protected slots: +private slots: void slotMinEditingFinished(); void slotMaxEditingFinished(); void slotMinSliderValueChanged( int value ); void slotMaxSliderValueChanged( int value ); - void slotSliderReleasedMin(); - void slotSliderReleasedMax(); + void slotMinSliderReleased(); + void slotMaxSliderReleased(); private: void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); From 5a46bad72056a5ee4eb1fd1e53ccf8e077ea3fb3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 11:53:13 +0200 Subject: [PATCH 13/14] cleanup --- .../cafPdmUiValueRangeEditor.cpp | 16 ++++++++-------- .../cafUserInterface/cafPdmUiValueRangeEditor.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index 9ff10d2fdb..059ca4035a 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -208,27 +208,27 @@ void PdmUiValueRangeEditor::slotMaxSliderReleased() //-------------------------------------------------------------------------------------------------- void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ) { - if ( isMinChanged ) + if ( isMinChanged && valueMin > valueMax ) { - if ( valueMin > valueMax ) valueMax = valueMin; + valueMax = valueMin; } - else + else if ( valueMax < valueMin ) { - if ( valueMax < valueMin ) valueMin = valueMax; + valueMin = valueMax; } - valueMin = qBound( m_attributes.m_minimum, valueMin, valueMax ); - valueMax = qBound( valueMin, valueMax, m_attributes.m_maximum ); + valueMin = qBound( m_attributes.m_minimum, valueMin, m_attributes.m_maximum ); + valueMax = qBound( m_attributes.m_minimum, valueMax, m_attributes.m_maximum ); m_sliderValueMin = valueMin; m_sliderValueMax = valueMax; - clampAndWriteValues( valueMin, valueMax ); + writeValues( valueMin, valueMax ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiValueRangeEditor::clampAndWriteValues( double valueMin, double valueMax ) +void PdmUiValueRangeEditor::writeValues( double valueMin, double valueMax ) { auto pairValue = std::make_pair( valueMin, valueMax ); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index f4e09cb02e..ee8a23f2f8 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -68,7 +68,7 @@ private slots: private: void clampAndWriteValues( double valueMin, double valueMax, bool isMinChanged ); - void clampAndWriteValues( double valueMin, double valueMax ); + void writeValues( double valueMin, double valueMax ); private: QPointer m_lineEditMin; From 0f950042fbf35cb486beedc3fc1bd7d32994c15e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 21 Sep 2023 14:12:52 +0200 Subject: [PATCH 14/14] linux fixes --- Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp | 1 + Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp | 3 +-- Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 2ed1044be5..50392c715d 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -48,6 +48,7 @@ #include "cafPdmUiListEditor.h" #include "cafPdmUiTimeEditor.h" #include "cafPdmUiTreeSelectionEditor.h" +#include "cafPdmUiValueRangeEditor.h" #include diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp index 059ca4035a..bf3743ff6b 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.cpp @@ -46,7 +46,6 @@ #include #include -#include namespace caf { @@ -71,7 +70,7 @@ void PdmUiValueRangeEditor::configureAndUpdateUi( const QString& uiConfigName ) } // A pair is represented as a list of QVariant in PdmValueFieldSpecialization> - auto getTwoDoublesFromVariant = [=]() -> std::pair + auto getTwoDoublesFromVariant = [this]() -> std::pair { double firstValue = 0.0; double secondValue = 0.0; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h index ee8a23f2f8..20cabef17d 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiValueRangeEditor.h @@ -39,6 +39,8 @@ #include "cafPdmUiFieldEditorHandle.h" #include "cafPdmUiSliderTools.h" +class QLineEdit; + namespace caf { //==================================================================================================