From 0075c03c9d199577c8c9c2f5ee4bc08004942b3c Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 26 Jan 2022 12:02:10 +0100 Subject: [PATCH] Fixing a LOT of issues stemming from X cursor --- .../LogarithmPlotter/LogarithmPlotter.qml | 7 +++-- .../ObjectLists/EditorDialog.qml | 26 ++++++++++++------- .../ad5001/LogarithmPlotter/js/historylib.js | 17 ++++++++++-- .../eu/ad5001/LogarithmPlotter/js/objects.js | 14 +++++----- .../ad5001/LogarithmPlotter/js/objs/common.js | 4 +++ package-linux.sh | 2 +- 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 3c13c2d..dc48111 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -224,8 +224,6 @@ ApplicationWindow { settings.linewidth = data["linewidth"] if("textsize" in data) settings.textsize = data["textsize"] - if("history" in data) - history.unserialize(...data["history"]) root.height = data["height"] root.width = data["width"] @@ -242,6 +240,11 @@ ApplicationWindow { error += qsTr("Unknown object type: %1.").arg(objType) + "\n"; } } + + // Importing history + if("history" in data) + history.unserialize(...data["history"]) + // Refreshing sidebar if(sidebarSelector.currentIndex == 0) { // For some reason, if we load a file while the tab is on object, diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/EditorDialog.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/EditorDialog.qml index 54618a3..1430159 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/EditorDialog.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/EditorDialog.qml @@ -179,9 +179,13 @@ D.Dialog { icon: visible ? `icons/settings/custom/${parent.label}.svg` : '' // True to select an object of type, false for enums. property bool selectObjMode: paramTypeIn(modelData[1], ['ObjectType']) + property bool isRealObject: !selectedObj || (modelData[1].objType != "ExecutableObject" && modelData[1].objType != "DrawableObject") property var baseModel: visible ? - (selectObjMode ? Objects.getObjectsName(modelData[1].objType).concat([qsTr("+ Create new %1").arg(modelData[1].objType)]) : modelData[1].values) + (selectObjMode ? Objects.getObjectsName(modelData[1].objType) + .concat( + isRealObject ? [qsTr("+ Create new %1").arg(modelData[1].objType)] : []) + : modelData[1].values) : [] // Translate the model if necessary. model: selectObjMode ? baseModel : baseModel.map(x => qsTr(x)) @@ -193,16 +197,20 @@ D.Dialog { // This is only done when what we're selecting are Objects. // Setting object property. var selectedObj = Objects.getObjectByName(baseModel[newIndex], modelData[1].objType) - if(selectedObj == null) { - // Creating new object. - selectedObj = Objects.createNewRegisteredObject(modelData[1].objType) - history.addToHistory(new HistoryLib.CreateNewObject(selectedObj.name, modelData[1].objType, selectedObj.export())) - baseModel = Objects.getObjectsName(modelData[1].objType).concat([qsTr("+ Create new %1").arg(Objects.types[modelData[1].objType].displayType())]) - currentIndex = baseModel.indexOf(selectedObj.name) + if(newIndex != 0) { + // Make sure we don't set the object to null. + if(selectedObj == null) { + // Creating new object. + selectedObj = Objects.createNewRegisteredObject(modelData[1].objType) + history.addToHistory(new HistoryLib.CreateNewObject(selectedObj.name, modelData[1].objType, selectedObj.export())) + baseModel = Objects.getObjectsName(modelData[1].objType).concat( + isRealObject ? [qsTr("+ Create new %1").arg(modelData[1].objType)] : []) + currentIndex = baseModel.indexOf(selectedObj.name) + } + selectedObj.requiredBy.push(Objects.currentObjects[objEditor.objType][objEditor.objIndex]) + //Objects.currentObjects[objEditor.objType][objEditor.objIndex].requiredBy = objEditor.obj[modelData[0]].filter((obj) => objEditor.obj.name != obj.name) } - //Objects.currentObjects[objEditor.objType][objEditor.objIndex].requiredBy = objEditor.obj[modelData[0]].filter((obj) => objEditor.obj.name != obj.name) objEditor.obj.requiredBy = objEditor.obj.requiredBy.filter((obj) => objEditor.obj.name != obj.name) - selectedObj.requiredBy.push(Objects.currentObjects[objEditor.objType][objEditor.objIndex]) history.addToHistory(new HistoryLib.EditedProperty( objEditor.obj.name, objEditor.objType, modelData[0], objEditor.obj[modelData[0]], selectedObj diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js index d72bc17..d474b1b 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js @@ -21,6 +21,7 @@ .pragma library .import "objects.js" as Objects +.import "objs/common.js" as Common .import "utils.js" as Utils .import "mathlib.js" as MathLib @@ -106,8 +107,17 @@ class EditedProperty extends Action { this.previousValue = previousValue this.newValue = newValue if(valueIsExpressionNeedingImport) { - this.previousValue = new MathLib.Expression(this.previousValue); - this.newValue = new MathLib.Expression(this.newValue); + if(targetType == "Expression") { + this.previousValue = new MathLib.Expression(this.previousValue); + this.newValue = new MathLib.Expression(this.newValue); + } else if(targetType == "Domain") { + this.previousValue = MathLib.parseDomain(this.previousValue); + this.newValue = MathLib.parseDomain(this.newValue); + } else { + // Objects + this.previousValue = Objects.getObjectByName(this.previousValue); + this.newValue = Objects.getObjectByName(this.newValue); + } } } @@ -122,6 +132,9 @@ class EditedProperty extends Action { export() { if(this.previousValue instanceof MathLib.Expression) { return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true] + } else if(this.previousValue instanceof Common.DrawableObject) { + return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true] + } else { return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false] } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js index 27681a0..b2378cb 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.js @@ -28,7 +28,7 @@ var currentObjects = {} function getObjectByName(objName, objType = null) { var objectTypes = Object.keys(currentObjects) - if(typeof objType == 'string') { + if(typeof objType == 'string' && objType != "") { if(objType == "ExecutableObject") { objectTypes = getExecutableTypes() } else if(currentObjects[objType] != undefined) { @@ -37,12 +37,14 @@ function getObjectByName(objName, objType = null) { } if(Array.isArray(objType)) objectTypes = objType var retObj = null - objectTypes.forEach(function(objType){ - if(currentObjects[objType] == undefined) return null - currentObjects[objType].forEach(function(obj){ - if(obj.name == objName) retObj = obj + if(objName != "" && objName != null) { + objectTypes.forEach(function(objType){ + if(currentObjects[objType] == undefined) return null + currentObjects[objType].forEach(function(obj){ + if(obj.name == objName) retObj = obj + }) }) - }) + } return retObj } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js index 32fda9d..417d491 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js @@ -110,6 +110,10 @@ class DrawableObject { } draw(canvas, ctx) {} + + toString() { + return this.name; + } } class ExecutableObject extends DrawableObject { diff --git a/package-linux.sh b/package-linux.sh index b29636e..ba53904 100755 --- a/package-linux.sh +++ b/package-linux.sh @@ -6,7 +6,7 @@ bash release.sh cd ../../ # Deb -python3 setup.py --remove-git-version --command-packages=stdeb.command sdist_dsc \ +sudo python3 setup.py --remove-git-version --command-packages=stdeb.command sdist_dsc \ --package logarithmplotter --copyright-file linux/debian/copyright --suite impish --depends3 "$(cat linux/debian/depends)" --section science \ bdist_deb