[qt6] Use JS functions format to declare explicit parameters in slots

This fixes all the "Injection of parameters into signal handlers
is deprecated. Use JavaScript functions with formal parameters instead."
warnings.
This commit is contained in:
Candice Bentéjac 2024-10-01 13:14:18 +02:00
parent 1b9e75cd4f
commit 6d845376eb
12 changed files with 94 additions and 77 deletions

View file

@ -522,8 +522,8 @@ Page {
text: "Load Template"
onTriggered: {
ensureSaved(function() {
initFileDialogFolder(loadTemplateDialog);
loadTemplateDialog.open();
initFileDialogFolder(loadTemplateDialog)
loadTemplateDialog.open()
})
}
}
@ -1159,15 +1159,15 @@ Page {
uigraph: _reconstruction
nodeTypesModel: _nodeTypes
onNodeDoubleClicked: {
onNodeDoubleClicked: function(mouse, node) {
_reconstruction.setActiveNode(node);
workspaceView.viewNode(node, mouse);
}
onComputeRequest: {
onComputeRequest: function(nodes) {
_reconstruction.forceNodesStatusUpdate();
computeManager.compute(nodes)
}
onSubmitRequest: {
onSubmitRequest: function(nodes) {
_reconstruction.forceNodesStatusUpdate();
computeManager.submit(nodes)
}

View file

@ -152,7 +152,7 @@ RowLayout {
}
}
onClicked: {
onClicked: function(mouse) {
forceActiveFocus()
if (mouse.button == Qt.RightButton) {
var menu = menuComp.createObject(parameterLabel)
@ -268,7 +268,7 @@ RowLayout {
setTextFieldAttribute(text)
parameterLabel.forceActiveFocus()
}
Keys.onPressed: (event)=> {
Keys.onPressed: function(event) {
if ((event.key == Qt.Key_Escape)) {
event.accepted = true
parameterLabel.forceActiveFocus()
@ -281,7 +281,7 @@ RowLayout {
DropArea {
enabled: root.editable
anchors.fill: parent
onDropped: {
onDropped: function(drop) {
if (drop.hasUrls)
setTextFieldAttribute(Filepath.urlToString(drop.urls[0]))
else if (drop.hasText && drop.text != '')
@ -291,7 +291,7 @@ RowLayout {
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: (mouse)=> {
onClicked: function(mouse) {
// Do not loose the selection during the right click
textField.persistentSelection = true
// We store the status of the activeFocus before opening the popup

View file

@ -57,8 +57,8 @@ RowLayout {
Repeater {
id: childrenRepeater
model: isList && !attribute.isLink ? attribute.value : 0
onItemAdded: childPinCreated(item.childAttribute, item)
onItemRemoved: childPinDeleted(item.childAttribute, item)
onItemAdded: function(item) { childPinCreated(item.childAttribute, item) }
onItemRemoved: function(item) { childPinDeleted(item.childAttribute, item) }
delegate: Item {
property var childAttribute: object
}
@ -102,7 +102,7 @@ RowLayout {
anchors.rightMargin: -root.width * 0.3
keys: [inputDragTarget.objectName]
onEntered: {
onEntered: function(drag) {
// Check if attributes are compatible to create a valid connection
if (root.readOnly // cannot connect on a read-only attribute
|| drag.source.objectName != inputDragTarget.objectName // not an edge connector
@ -164,7 +164,7 @@ RowLayout {
anchors.margins: inputDropArea.anchors.margins
anchors.leftMargin: inputDropArea.anchors.leftMargin
anchors.rightMargin: inputDropArea.anchors.rightMargin
onPressed: {
onPressed: function(mouse) {
root.pressed(mouse)
}
onReleased: {
@ -255,7 +255,7 @@ RowLayout {
anchors.leftMargin: -root.width * 0.2
keys: [outputDragTarget.objectName]
onEntered: {
onEntered: function(drag) {
// Check if attributes are compatible to create a valid connection
if (drag.source.objectName != outputDragTarget.objectName // not an edge connector
|| drag.source.baseType !== outputDragTarget.baseType // not the same base type
@ -276,7 +276,7 @@ RowLayout {
acceptableDrop = false
}
onDropped: {
onDropped: function(drag) {
root.edgeAboutToBeRemoved(undefined)
_reconstruction.addEdge(outputDragTarget.attribute, drag.source.attribute)
}
@ -314,7 +314,7 @@ RowLayout {
anchors.leftMargin: outputDropArea.anchors.leftMargin
anchors.rightMargin: outputDropArea.anchors.rightMargin
onPressed: root.pressed(mouse)
onPressed: function(mouse) { root.pressed(mouse) }
onReleased: outputDragTarget.Drag.drop()
hoverEnabled: true

View file

@ -132,7 +132,7 @@ Item {
return mapToItem(draggable, mouseArea.width / 2, mouseArea.height / 2)
}
Keys.onPressed: {
Keys.onPressed: function(event) {
if (event.key === Qt.Key_F) {
fit()
} else if (event.key === Qt.Key_Delete) {
@ -172,7 +172,7 @@ Item {
drag.threshold: 0
cursorShape: drag.target == draggable ? Qt.ClosedHandCursor : Qt.ArrowCursor
onWheel: {
onWheel: function(wheel) {
var zoomFactor = wheel.angleDelta.y > 0 ? factor : 1 / factor
var scale = draggable.scale * zoomFactor
scale = Math.min(Math.max(minZoom, scale), maxZoom)
@ -185,7 +185,7 @@ Item {
workspaceMoved()
}
onPressed: {
onPressed: function(mouse) {
if (mouse.button != Qt.MiddleButton && mouse.modifiers == Qt.NoModifier) {
uigraph.clearNodeSelection()
}
@ -200,17 +200,19 @@ Item {
drag.target = draggable // start drag
}
}
onReleased: {
drag.target = undefined // stop drag
root.forceActiveFocus()
workspaceClicked()
}
onPositionChanged: {
if (drag.active)
workspaceMoved()
}
onClicked: {
onClicked: function(mouse) {
if (mouse.button == Qt.RightButton) {
// store mouse click position in 'draggable' coordinates as new node spawn position
newNodeMenu.spawnPosition = mouseArea.mapToItem(draggable, mouse.x, mouse.y)
@ -335,7 +337,7 @@ Item {
id: nodeMenuRepeater
model: searchBar.text !== "" ? Object.values(newNodeMenu.menuKeys) : undefined
// create Menu items from available items
// Create Menu items from available items
delegate: menuItemDelegateComponent
}
@ -343,8 +345,13 @@ Item {
Instantiator {
id: instantiator
model: (searchBar.text === "") ? Object.keys(newNodeMenu.parseCategories()).sort() : undefined
onObjectAdded: newNodeMenu.insertMenu(index + 1, object ) // add sub-menu under the search bar
onObjectRemoved: newNodeMenu.removeMenu(object)
onObjectAdded: function(index, object) {
// Add sub-menu under the search bar
newNodeMenu.insertMenu(index + 1, object)
}
onObjectRemoved: function(index, object) {
newNodeMenu.removeMenu(object)
}
delegate: Menu {
title: modelData
@ -352,8 +359,12 @@ Item {
Instantiator {
model: newNodeMenu.visible ? newNodeMenu.parseCategories()[modelData] : undefined
onObjectAdded: newNodeSubMenu.insertItem(index, object)
onObjectRemoved: newNodeSubMenu.removeItem(object)
onObjectAdded: function(index, object) {
newNodeSubMenu.insertItem(index, object)
}
onObjectRemoved: function(index, object) {
newNodeSubMenu.removeItem(object)
}
delegate: menuItemDelegateComponent
}
}
@ -505,7 +516,7 @@ Item {
point1y: isValidEdge ? src.globalY + src.outputAnchorPos.y : 0
point2x: isValidEdge ? dst.globalX + dst.inputAnchorPos.x : 0
point2y: isValidEdge ? dst.globalY + dst.inputAnchorPos.y : 0
onPressed: {
onPressed: function(event) {
const canEdit = !edge.dst.node.locked
if (event.button) {
@ -823,14 +834,14 @@ Item {
selected: uigraph.selectedNodes.contains(node)
hovered: uigraph.hoveredNode === node
onAttributePinCreated: registerAttributePin(attribute, pin)
onAttributePinDeleted: unregisterAttributePin(attribute, pin)
onAttributePinCreated: function(attribute, pin) { registerAttributePin(attribute, pin) }
onAttributePinDeleted: function(attribute, pin) { unregisterAttributePin(attribute, pin) }
onPressed: {
onPressed: function(mouse) {
if (mouse.button === Qt.LeftButton) {
if (mouse.modifiers & Qt.ControlModifier && !(mouse.modifiers & Qt.AltModifier)) {
if (mainSelected && selected) {
// left clicking a selected node twice with control will deselect it
// Left clicking a selected node twice with control will deselect it
uigraph.selectedNodes.remove(node)
uigraph.selectedNodesChanged()
selectNode(null)
@ -854,14 +865,14 @@ Item {
selectNode(node)
}
onDoubleClicked: root.nodeDoubleClicked(mouse, node)
onDoubleClicked: function(mouse) { root.nodeDoubleClicked(mouse, node) }
onMoved: uigraph.moveNode(node, position, uigraph.selectedNodes)
onMoved: function(position) { uigraph.moveNode(node, position, uigraph.selectedNodes) }
onEntered: uigraph.hoveredNode = node
onExited: uigraph.hoveredNode = null
onEdgeAboutToBeRemoved: {
onEdgeAboutToBeRemoved: function(input) {
/*
Sometimes the signals are not in the right order
because of weird Qt/QML update order (next DropArea

View file

@ -121,12 +121,12 @@ Item {
width: parent.width
height: body.height
drag.target: root
// small drag threshold to avoid moving the node by mistake
// Small drag threshold to avoid moving the node by mistake
drag.threshold: 2
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: root.pressed(mouse)
onDoubleClicked: root.doubleClicked(mouse)
onPressed: function(mouse) { root.pressed(mouse) }
onDoubleClicked: function(mouse) { root.doubleClicked(mouse) }
onEntered: root.entered()
onExited: root.exited()
drag.onActiveChanged: {
@ -412,8 +412,8 @@ Item {
property real globalX: root.x + nodeAttributes.x + outputs.x + outputLoader.x + outPin.x
property real globalY: root.y + nodeAttributes.y + outputs.y + outputLoader.y + outPin.y
onPressed: root.pressed(mouse)
onEdgeAboutToBeRemoved: root.edgeAboutToBeRemoved(input)
onPressed: function(mouse) { root.pressed(mouse) }
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
Component.onCompleted: attributePinCreated(attribute, outPin)
onChildPinCreated: attributePinCreated(childAttribute, outPin)
@ -449,10 +449,10 @@ Item {
readOnly: root.readOnly || object.isReadOnly
Component.onCompleted: attributePinCreated(attribute, inPin)
Component.onDestruction: attributePinDeleted(attribute, inPin)
onPressed: root.pressed(mouse)
onEdgeAboutToBeRemoved: root.edgeAboutToBeRemoved(input)
onChildPinCreated: attributePinCreated(childAttribute, inPin)
onChildPinDeleted: attributePinDeleted(childAttribute, inPin)
onPressed: function(mouse) { root.pressed(mouse) }
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
onChildPinCreated: function(childAttribute, inPin) { attributePinCreated(childAttribute, inPin) }
onChildPinDeleted: function(childAttribute, inPin) { attributePinDeleted(childAttribute, inPin) }
}
}
}
@ -512,10 +512,10 @@ Item {
readOnly: Boolean(root.readOnly || object.isReadOnly)
Component.onCompleted: attributePinCreated(attribute, inParamsPin)
Component.onDestruction: attributePinDeleted(attribute, inParamsPin)
onPressed: root.pressed(mouse)
onEdgeAboutToBeRemoved: root.edgeAboutToBeRemoved(input)
onChildPinCreated: attributePinCreated(childAttribute, inParamsPin)
onChildPinDeleted: attributePinDeleted(childAttribute, inParamsPin)
onPressed: function(mouse) { root.pressed(mouse) }
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
onChildPinCreated: function(childAttribute, inParamsPin) { attributePinCreated(childAttribute, inParamsPin) }
onChildPinDeleted: function(childAttribute, inParamsPin) { attributePinDeleted(childAttribute, inParamsPin) }
}
}
}

View file

@ -60,7 +60,7 @@ Item {
anchors.margins: 6
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
onPressed: function(mouse) {
if (mouse.button == Qt.RightButton)
imageMenu.popup()
root.pressed(mouse)

View file

@ -305,7 +305,7 @@ Panel {
}
onRemoveRequest: sendRemoveRequest()
Keys.onPressed: (event) => {
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Delete && event.modifiers === Qt.ShiftModifier) {
removeAllImages()
} else if (event.key === Qt.Key_Delete) {
@ -375,7 +375,7 @@ Panel {
// Keyboard shortcut to change current image group
Keys.priority: Keys.BeforeItem
Keys.onPressed: {
Keys.onPressed: function(event) {
if (event.modifiers & Qt.AltModifier) {
if (event.key === Qt.Key_Right) {
_reconstruction.cameraInitIndex = Math.min(root.cameraInits.count - 1, root.cameraInitIndex + 1)
@ -529,7 +529,7 @@ Panel {
MouseArea {
anchors.fill: parent
onPressed: {
onPressed: function(mouse) {
if (mouse.button == Qt.LeftButton)
grid.forceActiveFocus()
mouse.accepted = false

View file

@ -105,29 +105,29 @@ FocusScope {
}
function clear() {
source = ''
source = ""
}
// slots
Keys.onPressed: {
// Slots
Keys.onPressed: function(event) {
if (event.key === Qt.Key_F) {
root.fit()
event.accepted = true
}
}
// mouse area
// Mouse area
MouseArea {
anchors.fill: parent
property double factor: 1.2
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onPressed: {
onPressed: function(mouse) {
imgContainer.forceActiveFocus()
if (mouse.button & Qt.MiddleButton || (mouse.button & Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier))
drag.target = imgContainer // start drag
drag.target = imgContainer // Start drag
}
onReleased: {
drag.target = undefined // stop drag
onReleased: function(mouse) {
drag.target = undefined // Stop drag
if (mouse.button & Qt.RightButton) {
var menu = contextMenu.createObject(root)
menu.x = mouse.x
@ -135,7 +135,7 @@ FocusScope {
menu.open()
}
}
onWheel: {
onWheel: function(wheel) {
var zoomFactor = wheel.angleDelta.y > 0 ? factor : 1 / factor
if (Math.min(imgContainer.width, imgContainer.image.height) * imgContainer.scale * zoomFactor < 10)
@ -1178,7 +1178,7 @@ FocusScope {
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
onClicked: function(mouse) {
if (mouse.button & Qt.LeftButton) {
fit()
} else if (mouse.button & Qt.RightButton) {

View file

@ -47,26 +47,26 @@ Entity {
property point currentPosition
property bool hasMoved
sourceDevice: loseMouseFocus ? null : mouseSourceDevice
onPressed: {
onPressed: function(mouse) {
_pressed = true
currentPosition.x = lastPosition.x = mouse.x
currentPosition.y = lastPosition.y = mouse.y
hasMoved = false
mousePressed(mouse)
}
onReleased: {
onReleased: function(mouse) {
_pressed = false
mouseReleased(mouse, hasMoved)
}
onClicked: mouseClicked(mouse)
onPositionChanged: {
onClicked: function(mouse) { mouseClicked(mouse) }
onPositionChanged: function(mouse) {
currentPosition.x = mouse.x
currentPosition.y = mouse.y
const dt = 0.02
var d
if (panning) { // translate
if (panning) { // Translate
d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.03
var tx = axisMX.value * root.translateSpeed * d
var ty = axisMY.value * root.translateSpeed * d
@ -74,13 +74,13 @@ Entity {
root.camera.translate(Qt.vector3d(-tx, -ty, 0).times(dt))
return
}
if (moving){ // trackball rotation
if (moving){ // Trackball rotation
trackball.rotate(mouseHandler.lastPosition, mouseHandler.currentPosition, dt)
mouseHandler.lastPosition = mouseHandler.currentPosition
mouseHandler.hasMoved = true
return
}
if (zooming) { // zoom with alt + RMD
if (zooming) { // Zoom with alt + RMD
mouseHandler.hasMoved = true
d = root.camera.viewCenter.minus(root.camera.position).length() // Distance between camera position and center position
var zoomPower = 0.2
@ -100,8 +100,8 @@ Entity {
}
}
onDoubleClicked: mouseDoubleClicked(mouse)
onWheel: {
onDoubleClicked: function(mouse) { mouseDoubleClicked(mouse) }
onWheel: function(wheel) {
var d = root.camera.viewCenter.minus(root.camera.position).length() // Distance between camera position and center position
var zoomPower = 0.2
var angleStep = 120 // wheel.angleDelta.y = +- 120 * number of wheel rotations
@ -117,6 +117,7 @@ Entity {
if (tz > 0 && tz <= tzThreshold) {
return
}
root.camera.translate(Qt.vector3d(0, 0, tz), Camera.DontTranslateViewCenter)
}
}
@ -130,7 +131,10 @@ Entity {
// stays active, even when it's released.
// Handle this issue manually by keeping an additional _pressed state
// which is cleared when focus changes (used for 'pickingActive' property).
onFocusChanged: if (!focus) _pressed = false
onFocusChanged: function(focus) {
if (!focus)
_pressed = false
}
onPressed: _pressed = true
onReleased: _pressed = false
}

View file

@ -154,7 +154,7 @@ FocusScope {
camera: mainCamera
focus: scene3D.activeFocus
onMousePressed: {
onMousePressed: function(mouse) {
scene3D.forceActiveFocus()
if (mouse.button === Qt.LeftButton) {
if (!doubleClickTimer.running)
@ -162,7 +162,7 @@ FocusScope {
} else
doubleClickTimer.stop()
}
onMouseReleased: {
onMouseReleased: function(mouse, moved) {
if (moving)
return
if (!moved && mouse.button === Qt.RightButton) {

View file

@ -80,8 +80,8 @@ Item {
cameraInit: reconstruction ? reconstruction.cameraInit : null
tempCameraInit: reconstruction ? reconstruction.tempCameraInit : null
cameraInitIndex: reconstruction ? reconstruction.cameraInitIndex : -1
onRemoveImageRequest: reconstruction.removeImage(attribute)
onAllViewpointsCleared: { reconstruction.selectedViewId = "-1" }
onRemoveImageRequest: function(attribute) { reconstruction.removeImage(attribute) }
onAllViewpointsCleared: reconstruction.selectedViewId = "-1"
onFilesDropped: {
if (drop["meshroomScenes"].length == 1) {
ensureSaved(function() {
@ -226,8 +226,10 @@ Item {
DropArea {
anchors.fill: parent
keys: ["text/uri-list"]
onDropped: {
drop.urls.forEach(function(url){ load3DMedia(url); });
onDropped: function(drop) {
drop.urls.forEach(function(url) {
load3DMedia(url)
})
}
}

View file

@ -26,7 +26,7 @@ ApplicationWindow {
return t
}
onClosing: {
onClosing: function(close) {
// Make sure document is saved before exiting application
close.accepted = false
if (!ensureNotComputing())