diff --git a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotRegressionCurve.cpp b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotRegressionCurve.cpp index a1197a59a9..54b9cd7dc7 100644 --- a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotRegressionCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotRegressionCurve.cpp @@ -392,12 +392,7 @@ void RimGridCrossPlotRegressionCurve::defineEditorAttribute( const caf::PdmField } else if ( field == &m_minExtrapolationRangeX || field == &m_maxExtrapolationRangeX ) { - auto doubleAttr = dynamic_cast( attribute ); - if ( doubleAttr ) - { - doubleAttr->m_decimals = 2; - doubleAttr->m_numberFormat = caf::PdmUiDoubleValueEditorAttribute::NumberFormat::FIXED; - } + caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute ); } else if ( field == &m_expressionText ) diff --git a/ApplicationLibCode/ProjectDataModel/RimDepthTrackPlot.cpp b/ApplicationLibCode/ProjectDataModel/RimDepthTrackPlot.cpp index 9a0f59a664..9fb0c84135 100644 --- a/ApplicationLibCode/ProjectDataModel/RimDepthTrackPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimDepthTrackPlot.cpp @@ -1228,12 +1228,7 @@ void RimDepthTrackPlot::defineEditorAttribute( const caf::PdmFieldHandle* field, { if ( field == &m_minVisibleDepth || field == &m_maxVisibleDepth ) { - auto doubleAttr = dynamic_cast( attribute ); - if ( doubleAttr ) - { - doubleAttr->m_decimals = 2; - doubleAttr->m_numberFormat = caf::PdmUiDoubleValueEditorAttribute::NumberFormat::FIXED; - } + caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute ); } } diff --git a/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModel.cpp b/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModel.cpp index 84554e9cd3..7fc1ba1220 100644 --- a/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModel.cpp +++ b/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModel.cpp @@ -896,12 +896,7 @@ void RimStimPlanModel::defineEditorAttribute( const caf::PdmFieldHandle* field, { if ( field == &m_formationDip || field == &m_barrierDip || field == &m_distanceToBarrier ) { - auto doubleAttr = dynamic_cast( attribute ); - if ( doubleAttr ) - { - doubleAttr->m_decimals = 2; - doubleAttr->m_numberFormat = caf::PdmUiDoubleValueEditorAttribute::NumberFormat::FIXED; - } + caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute ); } if ( field == &m_MD ) diff --git a/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModelTemplate.cpp b/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModelTemplate.cpp index dead357728..5863d3d8ce 100644 --- a/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModelTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModelTemplate.cpp @@ -307,12 +307,7 @@ void RimStimPlanModelTemplate::defineEditorAttribute( const caf::PdmFieldHandle* { if ( field == &m_stressDepth || field == &m_verticalStress ) { - auto doubleAttr = dynamic_cast( attribute ); - if ( doubleAttr ) - { - doubleAttr->m_decimals = 2; - doubleAttr->m_numberFormat = caf::PdmUiDoubleValueEditorAttribute::NumberFormat::FIXED; - } + caf::PdmUiDoubleValueEditorAttribute::testAndSetFixedWithTwoDecimals( attribute ); } if ( field == &m_faciesInitialPressureConfigs ) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleValueEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleValueEditor.h index b03dc1d450..6c208a2397 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleValueEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDoubleValueEditor.h @@ -66,6 +66,21 @@ public: m_numberFormat = NumberFormat::AUTOMATIC; } + void setFixedWithTwoDecimals() + { + m_decimals = 2; + m_numberFormat = NumberFormat::FIXED; + } + + // Convenience function to set the number format to fixed with two decimals + static void testAndSetFixedWithTwoDecimals( caf::PdmUiEditorAttribute* attr ) + { + if ( auto doubleAttr = dynamic_cast( attr ) ) + { + doubleAttr->setFixedWithTwoDecimals(); + } + } + public: int m_decimals; NumberFormat m_numberFormat;