diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml index 0fd529c..8f36f66 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml @@ -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. diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/TextSetting.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/TextSetting.qml index 706281e..b0a054a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/TextSetting.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/TextSetting.qml @@ -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() } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs index df8219b..20732ba 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs @@ -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)}` +