Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 1844 - QML ScaleLayout scale charges dialog to accept floats #1848

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/gui/qml/modifyCharges/ScaleLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,35 @@ ColumnLayout {
}
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: -100
from: decimalToInt(-100)
objectName: "scaleSpinBox"
stepSize: 1
to: 100
value: dialogModel.scaleValue
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);
}

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
Expand All @@ -41,7 +62,7 @@ ColumnLayout {

onClicked: {
dialogModel.cancelSelection();
spinBox.value = dialogModel.scaleValue;
spinBox.realValue = dialogModel.scaleValue;
}
}
D.Button {
Expand All @@ -51,7 +72,7 @@ ColumnLayout {

onClicked: {
dialogModel.setScaleType(dialogModel.Scale);
dialogModel.updateScaleValue(spinBox.value);
dialogModel.updateScaleValue(spinBox.realValue);
dialogModel.acceptSelection();
}
}
Expand All @@ -62,7 +83,7 @@ ColumnLayout {

onClicked: {
dialogModel.setScaleType(dialogModel.ScaleTo);
dialogModel.updateScaleValue(spinBox.value);
dialogModel.updateScaleValue(spinBox.realValue);
dialogModel.acceptSelection();
}
}
Expand Down