forked from qt-creator/qt-creator
QmlDesigner: Remove trailing zeroes from numbers
Task-number: QDS-11578 Change-Id: Ifbbe5ef764ad383863db07dc2cfaf444af7c8805 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -90,6 +90,7 @@ Item {
|
|||||||
realTo: 9e9
|
realTo: 9e9
|
||||||
realStepSize: 1.0
|
realStepSize: 1.0
|
||||||
decimals: 6
|
decimals: 6
|
||||||
|
trailingZeroes: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,8 @@ T.SpinBox {
|
|||||||
property bool drag: false
|
property bool drag: false
|
||||||
property bool sliderDrag: sliderPopup.drag
|
property bool sliderDrag: sliderPopup.drag
|
||||||
|
|
||||||
|
property bool trailingZeroes: true
|
||||||
|
|
||||||
property bool dirty: false // user modification flag
|
property bool dirty: false // user modification flag
|
||||||
|
|
||||||
// TODO Not used anymore. Will be removed when all dependencies were removed.
|
// TODO Not used anymore. Will be removed when all dependencies were removed.
|
||||||
@@ -204,11 +206,14 @@ T.SpinBox {
|
|||||||
|
|
||||||
textFromValue: function (value, locale) {
|
textFromValue: function (value, locale) {
|
||||||
locale.numberOptions = Locale.OmitGroupSeparator
|
locale.numberOptions = Locale.OmitGroupSeparator
|
||||||
return Number(control.realValue).toLocaleString(locale, 'f', control.decimals)
|
var decimals = trailingZeroes ? control.decimals : decimalCounter(value)
|
||||||
|
|
||||||
|
return Number(control.realValue).toLocaleString(locale, 'f', decimals)
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFromText: function (text, locale) {
|
valueFromText: function (text, locale) {
|
||||||
control.setRealValue(Number.fromLocaleString(locale, spinBoxInput.text))
|
control.setRealValue(Number.fromLocaleString(locale, spinBoxInput.text))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,4 +405,14 @@ T.SpinBox {
|
|||||||
if (control.realValue !== currValue)
|
if (control.realValue !== currValue)
|
||||||
control.realValueModified()
|
control.realValueModified()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decimalCounter(number) {
|
||||||
|
var strNumber = Math.abs(number).toString()
|
||||||
|
var decimalIndex = strNumber.indexOf('.')
|
||||||
|
|
||||||
|
// Set 'index' to a minimum of 1 if there are no fractions
|
||||||
|
var index = decimalIndex == -1 ? 1 : strNumber.length - decimalIndex - 1
|
||||||
|
|
||||||
|
return Math.min(index, control.decimals);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user