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

This commit is contained in:
Adsooi 2024-09-20 19:28:11 +02:00
parent 370402f303
commit 9b5356f8e7
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 25 additions and 14 deletions

View file

@ -49,7 +49,7 @@ Repeater {
*/
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 listTypes: ['List', 'Dict']
@ -102,13 +102,16 @@ Repeater {
height: 30
label: propertyLabel
icon: `settings/custom/${propertyIcon}.svg`
min: propertyType == "int" ? 0 : -Infinity
isInt: propertyType == "int"
isDouble: propertyType == "number"
defValue: obj[propertyName] == null ? '' : obj[propertyName].toString()
category: {
return {
"Domain": "domain",
"string": "all",
"number": "all"
"number": "all",
"int": "all",
}[propertyType]
}
onChanged: function(newValue) {
@ -116,7 +119,8 @@ Repeater {
var newValueParsed = {
"Domain": () => MathLib.parseDomain(newValue),
"string": () => newValue,
"number": () => parseFloat(newValue)
"number": () => newValue,
"int": () => newValue
}[propertyType]()
// Ensuring old and new values are different to prevent useless adding to history.

View file

@ -127,12 +127,15 @@ Item {
selectByMouse: true
onEditingFinished: function() {
if(insertButton.focus || insertPopup.focus) return
var value = text
if(control.isInt)
value = isNaN(parseInt(value)) ? control.min : Math.max(control.min,parseInt(value))
if(control.isDouble)
value = isNaN(parseFloat(value)) ? control.min : Math.max(control.min,parseFloat(value))
if(value != "" && value.toString() != defValue) {
let value = text
if(control.isInt) {
let parsed = parseInt(value)
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
} else if(control.isDouble) {
let parsed = parseFloat(value)
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
}
if(value !== "" && value.toString() != defValue) {
control.changed(value)
defValue = value.toString()
}

View file

@ -33,7 +33,7 @@ export default class XCursor extends DrawableObject {
[QT_TRANSLATE_NOOP('prop','targetElement')]: new P.ObjectType('ExecutableObject', true),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[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(
'— — — — — — —',
'⸺⸺⸺⸺⸺⸺',
@ -77,8 +77,10 @@ export default class XCursor extends DrawableObject {
var t = this.targetElement
var approx = ''
if(this.approximate) {
approx = t.execute(this.x.execute())
approx = approx.toPrecision(this.rounding + Math.round(approx).toString().length)
approx = (t.execute(this.x.execute()))
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())}` +
(this.approximate ? ' ≈ ' + approx : '')
@ -88,8 +90,10 @@ export default class XCursor extends DrawableObject {
let t = this.targetElement
let approx = ''
if(this.approximate) {
approx = t.execute(this.x.execute())
approx = approx.toPrecision(this.rounding + Math.round(approx).toString().length)
approx = (t.execute(this.x.execute()))
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())
return `${Latex.variable(t.name)}(${Latex.variable(this.name)}) = ${simpl.latexMarkup ? simpl.latexMarkup : Latex.variable(simpl)}` +