Skip to content

Commit 4b2f2df

Browse files
committed
[ImageGallery] Add option in clearMultiSelection to keep current index
If enabled, the index in the gallery will not be reset to -1 by default, as it may cause a major move across the gallery. The option is enabled when a selection of images is removed, as it makes sense to remain close to where the last selected image was.
1 parent 3c690d7 commit 4b2f2df

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

meshroom/ui/qml/ImageGallery/ImageGallery.qml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Panel {
5353

5454
function onCameraInitChanged() {
5555
nodesCB.currentIndex = root.cameraInitIndex
56-
sortedModel.clearMultiSelection()
56+
sortedModel.clearMultiSelection(false)
5757
}
5858
}
5959

@@ -254,9 +254,18 @@ Panel {
254254
selectedIndices = newArr
255255
}
256256

257-
function clearMultiSelection() {
257+
function clearMultiSelection(keepPosition) {
258+
if (keepPosition) {
259+
// Pick the lowest selected index as the landing position; after removal
260+
// the next surviving item slides up to that slot.
261+
// Clamp to the last remaining item in case the selection was at the tail.
262+
var sortedSel = selectedIndices.slice().sort(function(a, b){ return a - b })
263+
var remainingCount = count - selectedIndices.length
264+
selectedIndex = Math.min(sortedSel[0], remainingCount - 1)
265+
} else {
266+
selectedIndex = -1
267+
}
258268
selectedIndices = []
259-
selectedIndex = -1
260269
}
261270

262271
delegate: ImageDelegate {
@@ -305,6 +314,7 @@ Panel {
305314
// cases where "sortedModel" is unresolvable because the delegate has been destroyed before
306315
// the line accessing "sortedModel" is reached
307316
var model = sortedModel
317+
var view = root.galleryGrid
308318

309319
// If all the images are selected, we can just remove all of them at once
310320
if (model.selectedIndices.length === m.viewpoints.count) {
@@ -320,7 +330,16 @@ Panel {
320330
}
321331
if (objects.length > 0) {
322332
root.removeSelectedImagesRequest(objects)
323-
model.clearMultiSelection()
333+
model.clearMultiSelection(true)
334+
335+
// Restore a sensible position once the model has finished updating
336+
var targetIndex = model.selectedIndex
337+
Qt.callLater(function() {
338+
if (targetIndex >= 0 && view) {
339+
view.currentIndex = targetIndex
340+
view.makeCurrentItemVisible()
341+
}
342+
})
324343
}
325344

326345
// If the last image has been removed, make sure the viewpoints and intrinsics are reset

0 commit comments

Comments
 (0)