From 4fe1086d681f774963aa59f024e89ab7619b3b94 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 8 Oct 2023 22:36:23 +0200 Subject: [PATCH] Adding new behavior for object creation to default on picker when pickable. --- .../ObjectLists/ObjectCreationGrid.qml | 39 ++++++++++++++++--- .../ObjectLists/ObjectLists.qml | 1 + .../LogarithmPlotter/PickLocationOverlay.qml | 11 ++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectCreationGrid.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectCreationGrid.qml index 133971d..0c632e7 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectCreationGrid.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectCreationGrid.qml @@ -34,6 +34,22 @@ Column { id: createRow property var objectEditor property var objectLists + property var posPicker + + /*! + \qmlmethod int ObjectCreationGrid::openEditorDialog(var obj) + Opens the editor dialog for an object \c obj. + */ + function openEditorDialog(obj) { + // Open editor + console.log(obj, obj.prototype) + objectEditor.obj = obj + objectEditor.objType = obj.type + objectEditor.objIndex = Objects.currentObjects[obj.type].indexOf(obj) + objectEditor.open() + // Disconnect potential link + posPicker.picked.disconnect(openEditorDialog) + } Label { id: createTitle @@ -89,13 +105,26 @@ Column { ToolTip.text: label.text onClicked: { - var newObj = Objects.createNewRegisteredObject(modelData) + let newObj = Objects.createNewRegisteredObject(modelData) history.addToHistory(new HistoryLib.CreateNewObject(newObj.name, modelData, newObj.export())) objectLists.update() - objectEditor.obj = Objects.currentObjects[modelData][Objects.currentObjects[modelData].length - 1] - objectEditor.objType = modelData - objectEditor.objIndex = Objects.currentObjects[modelData].length - 1 - objectEditor.open() + + let hasXProp = newObj.constructor.properties().hasOwnProperty('x') + let hasYProp = newObj.constructor.properties().hasOwnProperty('y') + if(hasXProp || hasYProp) { + // Open picker + posPicker.objType = newObj.type + posPicker.objName = newObj.name + posPicker.pickX = hasXProp + posPicker.pickY = hasYProp + posPicker.propertyX = 'x' + posPicker.propertyY = 'y' + posPicker.visible = true + posPicker.picked.connect(openEditorDialog) + } else { + // Open editor + openEditorDialog(newObj) + } } } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml index a964d94..03b04c6 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml @@ -110,6 +110,7 @@ ScrollView { width: objectsListView.width objectEditor: objEditor objectLists: objectListList + posPicker: positionPicker } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml index e26da61..565069a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml @@ -39,6 +39,14 @@ Item { visible: false clip: true + /*! + \qmlsignal PickLocationOverlay::picked(var obj) + + Emitted when a location has been picked + The corresponding handler is \c onPicked. + */ + signal picked(var obj) + /*! \qmlproperty var PickLocationOverlay::canvas logGraphCanvas instance. @@ -116,6 +124,7 @@ Item { obj[propertyY] = newValueY obj.update() objectLists.update() + pickerRoot.picked(obj) } else if(parent.userPickX) { history.addToHistory(new HistoryLib.EditedProperty( objName, objType, propertyX, obj[propertyX], newValueX @@ -123,6 +132,7 @@ Item { obj[propertyX] = newValueX obj.update() objectLists.update() + pickerRoot.picked(obj) } else if(parent.userPickY) { history.addToHistory(new HistoryLib.EditedProperty( objName, objType, propertyY, obj[propertyY], newValueY @@ -130,6 +140,7 @@ Item { obj[propertyY] = newValueY obj.update() objectLists.update() + pickerRoot.picked(obj) } } pickerRoot.visible = false;