From 3446c1796a50a40637298e0f7b9b59b271ff9b91 Mon Sep 17 00:00:00 2001 From: Noella Spitz Date: Thu, 11 Apr 2024 15:35:42 +0100 Subject: [PATCH 1/5] fix: QML ScaleLayout scale charges dialog to accept floats --- src/gui/qml/modifyCharges/ScaleLayout.qml | 35 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/gui/qml/modifyCharges/ScaleLayout.qml b/src/gui/qml/modifyCharges/ScaleLayout.qml index ed5b4f6c44..ab15d0492e 100644 --- a/src/gui/qml/modifyCharges/ScaleLayout.qml +++ b/src/gui/qml/modifyCharges/ScaleLayout.qml @@ -23,12 +23,33 @@ ColumnLayout { id: spinBox Layout.alignment: Qt.AlignRight Layout.fillWidth: true - editable: true - from: -100 objectName: "scaleSpinBox" + editable: true + from: decimalToInt(-100) stepSize: 1 - to: 100 - value: dialogModel.scaleValue + to: decimalToInt(100) + value: decimalToInt(dialogModel.scaleValue) + + property int decimals: 2 + property real realValue: value / 100 + readonly property int decimalFactor: Math.pow(10, decimals) + + function decimalToInt(decimal) { + return decimal * decimalFactor + } + + validator: DoubleValidator { + bottom: Math.min(spinBox.from, spinBox.to) + top: Math.max(spinBox.from, spinBox.to) + decimals: spinBox.decimals + notation: DoubleValidator.StandardNotation + } + textFromValue: function(value) { + return String((parseFloat(value) / decimalFactor).toFixed(decimals)); + } + valueFromText: function(text) { + return Math.round(parseFloat(text) * decimalFactor); + } } RowLayout { Layout.alignment: Qt.AlignRight @@ -41,7 +62,7 @@ ColumnLayout { onClicked: { dialogModel.cancelSelection(); - spinBox.value = dialogModel.scaleValue; + spinBox.realValue = dialogModel.scaleValue; } } D.Button { @@ -51,7 +72,7 @@ ColumnLayout { onClicked: { dialogModel.setScaleType(dialogModel.Scale); - dialogModel.updateScaleValue(spinBox.value); + dialogModel.updateScaleValue(spinBox.realValue); dialogModel.acceptSelection(); } } @@ -62,7 +83,7 @@ ColumnLayout { onClicked: { dialogModel.setScaleType(dialogModel.ScaleTo); - dialogModel.updateScaleValue(spinBox.value); + dialogModel.updateScaleValue(spinBox.realValue); dialogModel.acceptSelection(); } } From 67d836fad9b0bc8574ee3e3f1c13947da73e0a6d Mon Sep 17 00:00:00 2001 From: Noella Spitz Date: Thu, 11 Apr 2024 16:01:32 +0100 Subject: [PATCH 2/5] Fix formatting. --- src/gui/qml/modifyCharges/ScaleLayout.qml | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/gui/qml/modifyCharges/ScaleLayout.qml b/src/gui/qml/modifyCharges/ScaleLayout.qml index ab15d0492e..1263ffa7f0 100644 --- a/src/gui/qml/modifyCharges/ScaleLayout.qml +++ b/src/gui/qml/modifyCharges/ScaleLayout.qml @@ -51,6 +51,40 @@ ColumnLayout { return Math.round(parseFloat(text) * decimalFactor); } } + SpinBox { + id: spinBox + readonly property int decimalFactor: Math.pow(10, decimals) + property int decimals: 2 + property real realValue: value / 100 + + Layout.alignment: Qt.AlignRight + Layout.fillWidth: true + objectName: "scaleSpinBox" + editable: true + from: decimalToInt(-100) + stepSize: 1 + to: decimalToInt(100) + value: decimalToInt(dialogModel.scaleValue) + + validator: DoubleValidator { + bottom: Math.min(spinBox.from, spinBox.to) + top: Math.max(spinBox.from, spinBox.to) + decimals: spinBox.decimals + notation: DoubleValidator.StandardNotation + } + + textFromValue: function(value) { + return String((parseFloat(value) / decimalFactor).toFixed(decimals)); + } + + valueFromText: function(text) { + return Math.round(parseFloat(text) * decimalFactor); + } + + function decimalToInt(decimal) { + return decimal * decimalFactor; + } + } RowLayout { Layout.alignment: Qt.AlignRight spacing: 10 From 1e604ba4f31c168bda600a698339513112bb5ddb Mon Sep 17 00:00:00 2001 From: Noella Spitz <101950441+rhinoella@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:50:42 +0100 Subject: [PATCH 3/5] Update Formatting --- src/gui/qml/modifyCharges/ScaleLayout.qml | 24 +++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/gui/qml/modifyCharges/ScaleLayout.qml b/src/gui/qml/modifyCharges/ScaleLayout.qml index 1263ffa7f0..2bc38e3353 100644 --- a/src/gui/qml/modifyCharges/ScaleLayout.qml +++ b/src/gui/qml/modifyCharges/ScaleLayout.qml @@ -56,27 +56,18 @@ ColumnLayout { readonly property int decimalFactor: Math.pow(10, decimals) property int decimals: 2 property real realValue: value / 100 - + Layout.alignment: Qt.AlignRight Layout.fillWidth: true - objectName: "scaleSpinBox" editable: true from: decimalToInt(-100) + objectName: "scaleSpinBox" stepSize: 1 - to: decimalToInt(100) - value: decimalToInt(dialogModel.scaleValue) - - validator: DoubleValidator { - bottom: Math.min(spinBox.from, spinBox.to) - top: Math.max(spinBox.from, spinBox.to) - decimals: spinBox.decimals - notation: DoubleValidator.StandardNotation - } - textFromValue: function(value) { return String((parseFloat(value) / decimalFactor).toFixed(decimals)); } - + to: decimalToInt(100) + value: decimalToInt(dialogModel.scaleValue) valueFromText: function(text) { return Math.round(parseFloat(text) * decimalFactor); } @@ -84,6 +75,13 @@ ColumnLayout { function decimalToInt(decimal) { return decimal * decimalFactor; } + + validator: DoubleValidator { + bottom: Math.min(spinBox.from, spinBox.to) + decimals: spinBox.decimals + notation: DoubleValidator.StandardNotation + top: Math.max(spinBox.from, spinBox.to) + } } RowLayout { Layout.alignment: Qt.AlignRight From 67bdd6ac602d19b9931db87a86d773941fb7e9ba Mon Sep 17 00:00:00 2001 From: Noella Spitz <101950441+rhinoella@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:32:42 +0100 Subject: [PATCH 4/5] Remove accidental duplicate (oops) --- src/gui/qml/modifyCharges/ScaleLayout.qml | 31 ----------------------- 1 file changed, 31 deletions(-) diff --git a/src/gui/qml/modifyCharges/ScaleLayout.qml b/src/gui/qml/modifyCharges/ScaleLayout.qml index 2bc38e3353..2f681cea6b 100644 --- a/src/gui/qml/modifyCharges/ScaleLayout.qml +++ b/src/gui/qml/modifyCharges/ScaleLayout.qml @@ -19,38 +19,7 @@ ColumnLayout { width: parent.width - 2 * parent.spacing wrapMode: Text.WordWrap } - SpinBox { - id: spinBox - Layout.alignment: Qt.AlignRight - Layout.fillWidth: true - objectName: "scaleSpinBox" - editable: true - from: decimalToInt(-100) - stepSize: 1 - to: decimalToInt(100) - value: decimalToInt(dialogModel.scaleValue) - property int decimals: 2 - property real realValue: value / 100 - readonly property int decimalFactor: Math.pow(10, decimals) - - function decimalToInt(decimal) { - return decimal * decimalFactor - } - - validator: DoubleValidator { - bottom: Math.min(spinBox.from, spinBox.to) - top: Math.max(spinBox.from, spinBox.to) - decimals: spinBox.decimals - notation: DoubleValidator.StandardNotation - } - textFromValue: function(value) { - return String((parseFloat(value) / decimalFactor).toFixed(decimals)); - } - valueFromText: function(text) { - return Math.round(parseFloat(text) * decimalFactor); - } - } SpinBox { id: spinBox readonly property int decimalFactor: Math.pow(10, decimals) From 432b97e8f9c1f34064f36dcd556c66ea23417b58 Mon Sep 17 00:00:00 2001 From: Noella Spitz Date: Fri, 12 Apr 2024 09:29:37 +0100 Subject: [PATCH 5/5] Formatting --- src/gui/qml/modifyCharges/ScaleLayout.qml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/qml/modifyCharges/ScaleLayout.qml b/src/gui/qml/modifyCharges/ScaleLayout.qml index 2f681cea6b..02098d61c4 100644 --- a/src/gui/qml/modifyCharges/ScaleLayout.qml +++ b/src/gui/qml/modifyCharges/ScaleLayout.qml @@ -19,25 +19,24 @@ ColumnLayout { width: parent.width - 2 * parent.spacing wrapMode: Text.WordWrap } - SpinBox { id: spinBox readonly property int decimalFactor: Math.pow(10, decimals) property int decimals: 2 property real realValue: value / 100 - + Layout.alignment: Qt.AlignRight Layout.fillWidth: true editable: true from: decimalToInt(-100) objectName: "scaleSpinBox" stepSize: 1 - textFromValue: function(value) { + textFromValue: function (value) { return String((parseFloat(value) / decimalFactor).toFixed(decimals)); } to: decimalToInt(100) value: decimalToInt(dialogModel.scaleValue) - valueFromText: function(text) { + valueFromText: function (text) { return Math.round(parseFloat(text) * decimalFactor); }