[ui] AttributeEditor: fix value setting by slider + avoid scientific notation

* fix reference to non-existing slider.value 
* convert values to string to avoid e+XX notation on large numbers
* fix number of decimals based on stepSize to avoid floating point approximations
This commit is contained in:
Yann Lanthony 2018-07-24 15:14:31 +02:00
parent 6bb70895f3
commit d3885331b2

View file

@ -202,7 +202,9 @@ RowLayout {
}
implicitWidth: 70
enabled: root.editable
text: slider.active && slider.item.pressed ? slider.value : attribute.value
// cast value to string to avoid intrusive scientific notations on numbers
property string displayValue: String(slider.active && slider.item.pressed ? slider.item.formattedValue : attribute.value)
text: displayValue
selectByMouse: true
validator: attribute.type == "FloatParam" ? doubleValidator : intValidator
onEditingFinished: setTextFieldAttribute(text)
@ -214,6 +216,8 @@ RowLayout {
Layout.fillWidth: true
active: attribute.desc.range != undefined
sourceComponent: Slider {
readonly property int stepDecimalCount: stepSize < 1 ? String(stepSize).split(".").pop().length : 0
readonly property real formattedValue: value.toFixed(stepDecimalCount)
enabled: root.editable
value: attribute.value
from: attribute.desc.range[0]
@ -223,7 +227,7 @@ RowLayout {
onPressedChanged: {
if(!pressed)
_reconstruction.setAttribute(attribute, value)
_reconstruction.setAttribute(attribute, formattedValue)
}
}
}