From 64d1419452b85b8077ab514d987e4a1144916ad9 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 18 Oct 2022 22:40:49 +0200 Subject: [PATCH] Fixing bugs in recursive object deletion and dependency. --- .../qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml | 6 +++++- .../eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml | 2 +- .../eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml | 3 +-- .../qml/eu/ad5001/LogarithmPlotter/js/expr-eval.js | 4 ++-- .../qml/eu/ad5001/LogarithmPlotter/js/history/create.js | 1 + .../qml/eu/ad5001/LogarithmPlotter/js/objects.js | 2 +- .../qml/eu/ad5001/LogarithmPlotter/js/objs/common.js | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 7ade306..4d7039a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -249,7 +249,11 @@ ApplicationWindow { // Importing objects Objects.currentObjects = {} - Objects.currentObjectsByName = {} + Object.keys(Objects.currentObjectsByName).forEach(key => { + delete Objects.currentObjectsByName[key]; + // Required to keep the same reference for the copy of the object used in expression variable detection. + // Another way would be to change the reference as well, but I feel like the code would be less clean. + }) for(let objType in data['objects']) { if(Object.keys(Objects.types).indexOf(objType) > -1) { Objects.currentObjects[objType] = [] diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml index 0d215ab..0ad35ff 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml @@ -96,7 +96,7 @@ ScrollView { posPicker: positionPicker onChanged: { - //obj = Objects.currentObjects[objType][index] + obj = Objects.currentObjects[objType][index] objectListList.update() } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml index 78d726b..11ce7aa 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml @@ -110,7 +110,6 @@ Item { MouseArea { anchors.fill: parent onClicked: { - console.log(obj.type) objEditor.obj = Objects.currentObjects[obj.type][index] objEditor.objType = obj.type objEditor.objIndex = index @@ -211,9 +210,9 @@ Item { Deletes an object and it's dependencies recursively. */ function deleteRecursively(object) { - console.log(object.name, object.requiredBy.length) for(let toRemove of object.requiredBy) deleteRecursively(toRemove) + object.requiredBy = [] history.addToHistory(new HistoryLib.DeleteObject( object.name, object.type, object.export() )) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/expr-eval.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/expr-eval.js index c615305..7ac669a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/expr-eval.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/expr-eval.js @@ -1836,9 +1836,9 @@ var optionNameMap = { 'not': 'logical', '?': 'conditional', ':': 'conditional', - '=': 'assignment', + //'=': 'assignment', // Disable assignment '[': 'array', - '()=': 'fndef' + //'()=': 'fndef' // Diable function definition }; function getOptionName(op) { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js index 00af298..7545372 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js @@ -45,6 +45,7 @@ class CreateNewObject extends C.Action { redo() { Objects.createNewRegisteredObject(this.targetType, this.targetProperties) + Objects.currentObjectsByName[this.targetName].update() } export() { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js index ada8150..9f3e972 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js @@ -47,8 +47,8 @@ function deleteObject(objName) { */ let obj = currentObjectsByName[objName] currentObjects[obj.type].splice(currentObjects[obj.type].indexOf(obj),1) - delete currentObjectsByName[objName] obj.delete() + delete currentObjectsByName[objName] } function getObjectsName(objType) { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js index 8968ed6..b966d55 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js @@ -200,7 +200,7 @@ class DrawableObject { if(properties[property] == 'Expression' && this[property] != null) { // Expressions with dependencies for(let objName of this[property].requiredObjects()) { - if(objName in C.currentObjectsByName && !this.requires.includes(objName)) { + if(objName in C.currentObjectsByName && !this.requires.includes(C.currentObjectsByName[objName])) { this.requires.push(C.currentObjectsByName[objName]) C.currentObjectsByName[objName].requiredBy.push(this) }