Fixing a few bugs related to dependency and text.
This commit is contained in:
parent
6116ffe4e7
commit
fcf5ef9539
4 changed files with 20 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue