Meshroom/meshroom/ui/qml/Controls/DelegateSelectionBox.qml
waaake 499c99469e [ui] DelegateSelectionBox: Fetch children indices when box selecting backdrops
This allows selecting children explicitly during this call rather than implicitly invoking select children which was inducing a binding loop on selection property
2025-02-13 07:44:11 +01:00

41 lines
1.6 KiB
QML

import QtQuick
import Meshroom.Helpers
/*
A SelectionBox that can be used to select delegates in a model instantiator (Repeater, ListView...).
Interesection test is done in the coordinate system of the container Item, using delegate's bounding boxes.
The list of selected indices is emitted when the selection ends.
*/
SelectionBox {
id: root
// The Item instantiating the delegates.
property Item modelInstantiator
// The Item containing the delegates (used for coordinate mapping).
property Item container
// Emitted when the selection has ended, with the list of selected indices and modifiers.
signal delegateSelectionEnded(list<int> indices, int modifiers)
onSelectionEnded: function(selectionRect, modifiers) {
let selectedIndices = [];
const mappedSelectionRect = mapToItem(container, selectionRect);
for (var i = 0; i < modelInstantiator.count; ++i) {
const delegate = modelInstantiator.getItemAt(i);
const delegateRect = Qt.rect(delegate.x, delegate.y, delegate.width, delegate.height);
if (Geom2D.rectRectIntersect(mappedSelectionRect, delegateRect)) {
selectedIndices.push(i);
// Check if the node is a backdrop
// If so add all of it's children indices as well
if (delegate.isBackdrop) {
let children = delegate.getChildrenIndices(true);
for (var c = 0; c < children.length; c++) {
selectedIndices.push(children[c]);
}
}
}
}
delegateSelectionEnded(selectedIndices, modifiers);
}
}