From 0313b29dcf95bec65cbfdd721fde198154dceaa6 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 7 Dec 2020 16:04:21 +0100 Subject: [PATCH] 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. --- .../MachineSettingsExtruderTab.qml | 1 + .../NumericTextFieldWithUnit.qml | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml b/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml index 902388b669..293e7386b2 100644 --- a/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml @@ -137,6 +137,7 @@ Item labelWidth: base.labelWidth controlWidth: base.controlWidth unitText: "" + decimals: 0 forceUpdateOnChangeFunction: forceUpdateFunction } } diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index 031ef5241a..32e0e6dcaa 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -156,12 +156,24 @@ UM.TooltipArea const value = propertyProvider.properties.value return value ? value : "" } - validator: DoubleValidator + property string validatorString: { - bottom: numericTextFieldWithUnit.minimum - top: numericTextFieldWithUnit.maximum - decimals: numericTextFieldWithUnit.decimals - notation: DoubleValidator.StandardNotation + var digits = Math.min(8, 1 + Math.floor( + Math.log(Math.max(Math.abs(numericTextFieldWithUnit.maximum), Math.abs(numericTextFieldWithUnit.minimum)))/Math.log(10) + )) + 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.