Clamp UI values if field supports clampValue method

Added a compile-time check to call clampValue on fields that support it before setting values from the UI. This ensures values are clamped to valid limits automatically when applicable.
This commit is contained in:
Magne Sjaastad committed 2026-02-16 16:54:22 +01:00
1 parent 8f884c684b
commit 483a4a9b7b
1 file changed
+7
@@ -95,6 +95,13 @@ void PdmFieldUiCap<FieldType>::setValueFromUiEditor( const QVariant& uiValue, bo
{
typename FieldType::FieldDataType value;
PdmUiFieldSpecialization<typename FieldType::FieldDataType>::setFromVariant( uiValue, value );
// Clamp value if the field has a clampValue method
if constexpr ( requires { m_field->clampValue( value ); } )
{
value = m_field->clampValue( value );
}
m_field->setValue( value );
}