diff options
-rw-r--r-- | plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml | 1 | ||||
-rw-r--r-- | resources/qml/MachineSettings/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. |