Fixing another bug with X Cursor relating to rounding to a superior precision than what the number originally has.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
370402f303
commit
9b5356f8e7
3 changed files with 25 additions and 14 deletions
|
@ -49,7 +49,7 @@ Repeater {
|
||||||
*/
|
*/
|
||||||
property var positionPicker
|
property var positionPicker
|
||||||
|
|
||||||
readonly property var textTypes: ['Domain', 'string', 'number']
|
readonly property var textTypes: ['Domain', 'string', 'number', 'int']
|
||||||
readonly property var comboBoxTypes: ['ObjectType', 'Enum']
|
readonly property var comboBoxTypes: ['ObjectType', 'Enum']
|
||||||
readonly property var listTypes: ['List', 'Dict']
|
readonly property var listTypes: ['List', 'Dict']
|
||||||
|
|
||||||
|
@ -102,13 +102,16 @@ Repeater {
|
||||||
height: 30
|
height: 30
|
||||||
label: propertyLabel
|
label: propertyLabel
|
||||||
icon: `settings/custom/${propertyIcon}.svg`
|
icon: `settings/custom/${propertyIcon}.svg`
|
||||||
|
min: propertyType == "int" ? 0 : -Infinity
|
||||||
|
isInt: propertyType == "int"
|
||||||
isDouble: propertyType == "number"
|
isDouble: propertyType == "number"
|
||||||
defValue: obj[propertyName] == null ? '' : obj[propertyName].toString()
|
defValue: obj[propertyName] == null ? '' : obj[propertyName].toString()
|
||||||
category: {
|
category: {
|
||||||
return {
|
return {
|
||||||
"Domain": "domain",
|
"Domain": "domain",
|
||||||
"string": "all",
|
"string": "all",
|
||||||
"number": "all"
|
"number": "all",
|
||||||
|
"int": "all",
|
||||||
}[propertyType]
|
}[propertyType]
|
||||||
}
|
}
|
||||||
onChanged: function(newValue) {
|
onChanged: function(newValue) {
|
||||||
|
@ -116,7 +119,8 @@ Repeater {
|
||||||
var newValueParsed = {
|
var newValueParsed = {
|
||||||
"Domain": () => MathLib.parseDomain(newValue),
|
"Domain": () => MathLib.parseDomain(newValue),
|
||||||
"string": () => newValue,
|
"string": () => newValue,
|
||||||
"number": () => parseFloat(newValue)
|
"number": () => newValue,
|
||||||
|
"int": () => newValue
|
||||||
}[propertyType]()
|
}[propertyType]()
|
||||||
|
|
||||||
// Ensuring old and new values are different to prevent useless adding to history.
|
// Ensuring old and new values are different to prevent useless adding to history.
|
||||||
|
|
|
@ -127,12 +127,15 @@ Item {
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
onEditingFinished: function() {
|
onEditingFinished: function() {
|
||||||
if(insertButton.focus || insertPopup.focus) return
|
if(insertButton.focus || insertPopup.focus) return
|
||||||
var value = text
|
let value = text
|
||||||
if(control.isInt)
|
if(control.isInt) {
|
||||||
value = isNaN(parseInt(value)) ? control.min : Math.max(control.min,parseInt(value))
|
let parsed = parseInt(value)
|
||||||
if(control.isDouble)
|
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
|
||||||
value = isNaN(parseFloat(value)) ? control.min : Math.max(control.min,parseFloat(value))
|
} else if(control.isDouble) {
|
||||||
if(value != "" && value.toString() != defValue) {
|
let parsed = parseFloat(value)
|
||||||
|
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
|
||||||
|
}
|
||||||
|
if(value !== "" && value.toString() != defValue) {
|
||||||
control.changed(value)
|
control.changed(value)
|
||||||
defValue = value.toString()
|
defValue = value.toString()
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ export default class XCursor extends DrawableObject {
|
||||||
[QT_TRANSLATE_NOOP('prop','targetElement')]: new P.ObjectType('ExecutableObject', true),
|
[QT_TRANSLATE_NOOP('prop','targetElement')]: new P.ObjectType('ExecutableObject', true),
|
||||||
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
|
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
|
||||||
[QT_TRANSLATE_NOOP('prop','approximate')]: 'boolean',
|
[QT_TRANSLATE_NOOP('prop','approximate')]: 'boolean',
|
||||||
[QT_TRANSLATE_NOOP('prop','rounding')]: 'number',
|
[QT_TRANSLATE_NOOP('prop','rounding')]: 'int',
|
||||||
[QT_TRANSLATE_NOOP('prop','displayStyle')]: new P.Enum(
|
[QT_TRANSLATE_NOOP('prop','displayStyle')]: new P.Enum(
|
||||||
'— — — — — — —',
|
'— — — — — — —',
|
||||||
'⸺⸺⸺⸺⸺⸺',
|
'⸺⸺⸺⸺⸺⸺',
|
||||||
|
@ -77,8 +77,10 @@ export default class XCursor extends DrawableObject {
|
||||||
var t = this.targetElement
|
var t = this.targetElement
|
||||||
var approx = ''
|
var approx = ''
|
||||||
if(this.approximate) {
|
if(this.approximate) {
|
||||||
approx = t.execute(this.x.execute())
|
approx = (t.execute(this.x.execute()))
|
||||||
approx = approx.toPrecision(this.rounding + Math.round(approx).toString().length)
|
let intLength = Math.round(approx).toString().length
|
||||||
|
let rounding = Math.min(this.rounding, approx.toString().length - intLength - 1)
|
||||||
|
approx = approx.toPrecision(rounding + intLength)
|
||||||
}
|
}
|
||||||
return `${t.name}(${this.name}) = ${t.simplify(this.x.toEditableString())}` +
|
return `${t.name}(${this.name}) = ${t.simplify(this.x.toEditableString())}` +
|
||||||
(this.approximate ? ' ≈ ' + approx : '')
|
(this.approximate ? ' ≈ ' + approx : '')
|
||||||
|
@ -88,8 +90,10 @@ export default class XCursor extends DrawableObject {
|
||||||
let t = this.targetElement
|
let t = this.targetElement
|
||||||
let approx = ''
|
let approx = ''
|
||||||
if(this.approximate) {
|
if(this.approximate) {
|
||||||
approx = t.execute(this.x.execute())
|
approx = (t.execute(this.x.execute()))
|
||||||
approx = approx.toPrecision(this.rounding + Math.round(approx).toString().length)
|
let intLength = Math.round(approx).toString().length
|
||||||
|
let rounding = Math.min(this.rounding, approx.toString().length - intLength - 1)
|
||||||
|
approx = approx.toPrecision(rounding + intLength)
|
||||||
}
|
}
|
||||||
let simpl = t.simplify(this.x.toEditableString())
|
let simpl = t.simplify(this.x.toEditableString())
|
||||||
return `${Latex.variable(t.name)}(${Latex.variable(this.name)}) = ${simpl.latexMarkup ? simpl.latexMarkup : Latex.variable(simpl)}` +
|
return `${Latex.variable(t.name)}(${Latex.variable(this.name)}) = ${simpl.latexMarkup ? simpl.latexMarkup : Latex.variable(simpl)}` +
|
||||||
|
|
Loading…
Reference in a new issue