Fix validator for floats in Machine Settings dialog

The DoubleValidator depends on the system locale, requiring users with certain locales to enter floats with a comma instead of a dot (though confusingly floats are always represented with a decimal a dot). Instead of configuring the DoubleValidator with a locale that only accepts decimal dots, this commit uses a RegExpValidator, like other numeric fields in Cura does.
This commit is contained in:
fieldOfView 2020-12-07 16:04:21 +01:00
parent 19d432e50f
commit 0313b29dcf
2 changed files with 18 additions and 5 deletions

View file

@ -137,6 +137,7 @@ Item
labelWidth: base.labelWidth labelWidth: base.labelWidth
controlWidth: base.controlWidth controlWidth: base.controlWidth
unitText: "" unitText: ""
decimals: 0
forceUpdateOnChangeFunction: forceUpdateFunction forceUpdateOnChangeFunction: forceUpdateFunction
} }
} }

View file

@ -156,12 +156,24 @@ UM.TooltipArea
const value = propertyProvider.properties.value const value = propertyProvider.properties.value
return value ? value : "" return value ? value : ""
} }
validator: DoubleValidator property string validatorString:
{ {
bottom: numericTextFieldWithUnit.minimum var digits = Math.min(8, 1 + Math.floor(
top: numericTextFieldWithUnit.maximum Math.log(Math.max(Math.abs(numericTextFieldWithUnit.maximum), Math.abs(numericTextFieldWithUnit.minimum)))/Math.log(10)
decimals: numericTextFieldWithUnit.decimals ))
notation: DoubleValidator.StandardNotation var minus = numericTextFieldWithUnit.minimum < 0 ? "-?" : ""
if (numericTextFieldWithUnit.decimals == 0)
{
return "^%0\\d{1,%1}$".arg(minus).arg(digits)
}
else
{
return "^%0\\d{0,%1}[.,]?\\d{0,%2}$".arg(minus).arg(digits).arg(numericTextFieldWithUnit.decimals)
}
}
validator: RegExpValidator
{
regExp: new RegExp(textFieldWithUnit.validatorString)
} }
//Enforce actual minimum and maximum values. //Enforce actual minimum and maximum values.