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 id: createRow
property var objectEditor property var objectEditor
property var objectLists 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 { Label {
id: createTitle id: createTitle
@ -89,13 +105,26 @@ Column {
ToolTip.text: label.text ToolTip.text: label.text
onClicked: { onClicked: {
var newObj = Objects.createNewRegisteredObject(modelData) let newObj = Objects.createNewRegisteredObject(modelData)
history.addToHistory(new HistoryLib.CreateNewObject(newObj.name, modelData, newObj.export())) history.addToHistory(new HistoryLib.CreateNewObject(newObj.name, modelData, newObj.export()))
objectLists.update() objectLists.update()
objectEditor.obj = Objects.currentObjects[modelData][Objects.currentObjects[modelData].length - 1]
objectEditor.objType = modelData let hasXProp = newObj.constructor.properties().hasOwnProperty('x')
objectEditor.objIndex = Objects.currentObjects[modelData].length - 1 let hasYProp = newObj.constructor.properties().hasOwnProperty('y')
objectEditor.open() 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 width: objectsListView.width
objectEditor: objEditor objectEditor: objEditor
objectLists: objectListList objectLists: objectListList
posPicker: positionPicker
} }
} }

View file

@ -39,6 +39,14 @@ Item {
visible: false visible: false
clip: true 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 \qmlproperty var PickLocationOverlay::canvas
logGraphCanvas instance. logGraphCanvas instance.
@ -116,6 +124,7 @@ Item {
obj[propertyY] = newValueY obj[propertyY] = newValueY
obj.update() obj.update()
objectLists.update() objectLists.update()
pickerRoot.picked(obj)
} else if(parent.userPickX) { } else if(parent.userPickX) {
history.addToHistory(new HistoryLib.EditedProperty( history.addToHistory(new HistoryLib.EditedProperty(
objName, objType, propertyX, obj[propertyX], newValueX objName, objType, propertyX, obj[propertyX], newValueX
@ -123,6 +132,7 @@ Item {
obj[propertyX] = newValueX obj[propertyX] = newValueX
obj.update() obj.update()
objectLists.update() objectLists.update()
pickerRoot.picked(obj)
} else if(parent.userPickY) { } else if(parent.userPickY) {
history.addToHistory(new HistoryLib.EditedProperty( history.addToHistory(new HistoryLib.EditedProperty(
objName, objType, propertyY, obj[propertyY], newValueY objName, objType, propertyY, obj[propertyY], newValueY
@ -130,6 +140,7 @@ Item {
obj[propertyY] = newValueY obj[propertyY] = newValueY
obj.update() obj.update()
objectLists.update() objectLists.update()
pickerRoot.picked(obj)
} }
} }
pickerRoot.visible = false; pickerRoot.visible = false;