From fcf5ef9539e359aed58c08b56aad51bd6108c98b Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 18 Oct 2022 22:17:10 +0200 Subject: [PATCH] Fixing a few bugs related to dependency and text. --- .../ObjectLists/ObjectRow.qml | 20 +++++++++++++++---- .../eu/ad5001/LogarithmPlotter/js/objects.js | 2 +- .../ad5001/LogarithmPlotter/js/objs/common.js | 4 ++-- .../ad5001/LogarithmPlotter/js/objs/text.js | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml index 3937c4f..78d726b 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectRow.qml @@ -110,6 +110,7 @@ Item { MouseArea { anchors.fill: parent onClicked: { + console.log(obj.type) objEditor.obj = Objects.currentObjects[obj.type][index] objEditor.objType = obj.type objEditor.objIndex = index @@ -169,10 +170,7 @@ Item { ToolTip.text: qsTr("Delete %1 %2").arg(obj.constructor.displayType()).arg(obj.name) onClicked: { - history.addToHistory(new HistoryLib.DeleteObject( - obj.name, obj.type, obj.export() - )) - Objects.deleteObject(obj.name) + deleteRecursively(obj) changed() } } @@ -207,4 +205,18 @@ Item { changed() } } + + /*! + \qmlmethod void ObjectRow::deleteRecursively(var object) + 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) + history.addToHistory(new HistoryLib.DeleteObject( + object.name, object.type, object.export() + )) + Objects.deleteObject(object.name) + } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js index 1a23f7c..ada8150 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js @@ -46,8 +46,8 @@ function deleteObject(objName) { * @param {string} objName - Current name of the object. */ let obj = currentObjectsByName[objName] - delete currentObjectsByName[objName] currentObjects[obj.type].splice(currentObjects[obj.type].indexOf(obj),1) + delete currentObjectsByName[objName] obj.delete() } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js index 795d0a0..8968ed6 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) { + if(objName in C.currentObjectsByName && !this.requires.includes(objName)) { this.requires.push(C.currentObjectsByName[objName]) C.currentObjectsByName[objName].requiredBy.push(this) } @@ -224,7 +224,7 @@ class DrawableObject { * Callback method when the object is about to get deleted. */ delete() { - for(let toRemove of this.requiredBy) { + for(let toRemove of this.requiredBy) { // Normally, there should be none here, but better leave nothing just in case. Objects.deleteObject(toRemove.name) } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js index 77f5c5d..a8dcd4e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js @@ -45,7 +45,7 @@ class Text extends Common.DrawableObject { x = 1, y = 0, labelPosition = 'center', text = 'New text', disableLatex = false) { if(name == null) name = Common.getNewName('t') super(name, visible, color, labelContent) - this.type = 'Point' + this.type = 'Text' if(typeof x == 'number' || typeof x == 'string') x = new MathLib.Expression(x.toString()) this.x = x if(typeof y == 'number' || typeof y == 'string') y = new MathLib.Expression(y.toString())