Adding new behavior for object creation to default on picker when pickable.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Adsooi 2023-10-08 22:36:23 +02:00
parent a66ccd1319
commit 4fe1086d68
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 46 additions and 5 deletions

View file

@ -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)
}
}
}
}

View file

@ -110,6 +110,7 @@ ScrollView {
width: objectsListView.width
objectEditor: objEditor
objectLists: objectListList
posPicker: positionPicker
}
}

View file

@ -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;