From 17a832f52f14f2b7fae89e9a811cddb48725759a Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Thu, 19 Sep 2019 13:56:37 +0200 Subject: [PATCH 1/3] Do not transform negative printhead min max values to positive while displaying CURA-6690 --- .../MachineSettingsPrinterTab.qml | 4 ++-- .../NumericTextFieldWithUnit.qml | 1 + .../PrintHeadMinMaxTextField.qml | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml index d817450f41..63c32d36cc 100644 --- a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml @@ -245,7 +245,7 @@ Item axisName: "x" axisMinOrMax: "max" - allowNegativeValue: true + allowNegativeValue: false forceUpdateOnChangeFunction: forceUpdateFunction } @@ -266,7 +266,7 @@ Item axisName: "y" axisMinOrMax: "max" - allowNegativeValue: true + allowNegativeValue: false forceUpdateOnChangeFunction: forceUpdateFunction } diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index 5921a39933..049282a6a0 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -35,6 +35,7 @@ UM.TooltipArea property alias labelWidth: fieldLabel.width property alias unitText: unitLabel.text + property alias textField: textFieldWithUnit property alias valueText: textFieldWithUnit.text property alias valueValidator: textFieldWithUnit.validator property alias editingFinishedFunction: textFieldWithUnit.editingFinishedFunction diff --git a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml index 2eaaed4524..b78c1ae0db 100644 --- a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml +++ b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml @@ -43,11 +43,14 @@ NumericTextFieldWithUnit { result = func(result, polygon[i][item]) } - result = Math.abs(result) return result } - valueValidator: RegExpValidator { regExp: /[0-9\.,]{0,6}/ } + valueValidator: DoubleValidator { + bottom: allowNegativeValue ? Number.NEGATIVE_INFINITY : 0 + decimals: 6 + notation: DoubleValidator.StandardNotation + } valueText: axisValue editingFinishedFunction: function() @@ -55,19 +58,18 @@ NumericTextFieldWithUnit var polygon = JSON.parse(propertyProvider.properties.value) var newValue = parseFloat(valueText.replace(',', '.')) + if (axisName == "x") // x min/x max { var start_i1 = (axisMinOrMax == "min") ? 0 : 2 - var factor = (axisMinOrMax == "min") ? -1 : 1 - polygon[start_i1][0] = newValue * factor - polygon[start_i1 + 1][0] = newValue * factor + polygon[start_i1][0] = newValue + polygon[start_i1 + 1][0] = newValue } else // y min/y max { var start_i1 = (axisMinOrMax == "min") ? 1 : 0 - var factor = (axisMinOrMax == "min") ? -1 : 1 - polygon[start_i1][1] = newValue * factor - polygon[start_i1 + 2][1] = newValue * factor + polygon[start_i1][1] = newValue + polygon[start_i1 + 2][1] = newValue } var polygon_string = JSON.stringify(polygon) if (polygon_string != propertyProvider.properties.value) From c43cdb5c63546f6897374b1be042a81dcf647fc8 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Thu, 19 Sep 2019 14:49:18 +0200 Subject: [PATCH 2/3] Implement allowPositive for printhead settings CURA-6690 --- plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml | 4 ++++ resources/qml/MachineSettings/NumericTextFieldWithUnit.qml | 2 ++ resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml | 2 ++ 3 files changed, 8 insertions(+) diff --git a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml index 63c32d36cc..045b8d1e99 100644 --- a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml @@ -208,6 +208,7 @@ Item axisName: "x" axisMinOrMax: "min" allowNegativeValue: true + allowPositiveValue: false forceUpdateOnChangeFunction: forceUpdateFunction } @@ -227,6 +228,7 @@ Item axisName: "y" axisMinOrMax: "min" allowNegativeValue: true + allowPositiveValue: false forceUpdateOnChangeFunction: forceUpdateFunction } @@ -246,6 +248,7 @@ Item axisName: "x" axisMinOrMax: "max" allowNegativeValue: false + allowPositiveValue: true forceUpdateOnChangeFunction: forceUpdateFunction } @@ -267,6 +270,7 @@ Item axisName: "y" axisMinOrMax: "max" allowNegativeValue: false + allowPositiveValue: true forceUpdateOnChangeFunction: forceUpdateFunction } diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index 049282a6a0..bad7f5a867 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -44,6 +44,8 @@ UM.TooltipArea // whether negative value is allowed. This affects the validation of the input field. property bool allowNegativeValue: false + // whether positive value is allowed. This affects the validation of the input field. + property bool allowPositiveValue: true // callback functions property var afterOnEditingFinishedFunction: dummy_func diff --git a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml index b78c1ae0db..8919271f05 100644 --- a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml +++ b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml @@ -48,9 +48,11 @@ NumericTextFieldWithUnit valueValidator: DoubleValidator { bottom: allowNegativeValue ? Number.NEGATIVE_INFINITY : 0 + top: allowPositiveValue ? Number.POSITIVE_INFINITY : 0 decimals: 6 notation: DoubleValidator.StandardNotation } + valueText: axisValue editingFinishedFunction: function() From c661f82756f3bf48f9f5823b81dff245eff1ac46 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 19 Sep 2019 15:32:58 +0200 Subject: [PATCH 3/3] Recreate bindings for the text fields CURA-6690 --- .../NumericTextFieldWithUnit.qml | 8 +++++++- .../PrintHeadMinMaxTextField.qml | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index bad7f5a867..c46116e520 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -156,7 +156,13 @@ UM.TooltipArea const value = propertyProvider.properties.value return value ? value : "" } - validator: RegExpValidator { regExp: allowNegativeValue ? /-?[0-9\.,]{0,6}/ : /[0-9\.,]{0,6}/ } + validator: DoubleValidator + { + bottom: allowNegativeValue ? Number.NEGATIVE_INFINITY : 0 + top: allowPositiveValue ? Number.POSITIVE_INFINITY : 0 + decimals: 6 + notation: DoubleValidator.StandardNotation + } onEditingFinished: editingFinishedFunction() diff --git a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml index 8919271f05..a08fa92c78 100644 --- a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml +++ b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml @@ -55,10 +55,23 @@ NumericTextFieldWithUnit valueText: axisValue + Connections + { + target: textField + onActiveFocusChanged: + { + // When this text field loses focus and the entered text is not valid, make sure to recreate the binding to + // show the correct value. + if (!textField.activeFocus && !textField.acceptableInput) + { + valueText = axisValue + } + } + } + editingFinishedFunction: function() { var polygon = JSON.parse(propertyProvider.properties.value) - var newValue = parseFloat(valueText.replace(',', '.')) if (axisName == "x") // x min/x max @@ -79,5 +92,8 @@ NumericTextFieldWithUnit propertyProvider.setPropertyValue("value", polygon_string) forceUpdateOnChangeFunction() } + + // Recreate the binding to show the correct value. + valueText = axisValue } }