[ui] Only update active CameraInit and its index when they are changed

Prior to this commit, when a `CameraInit` node was added to or removed
from the list of `CameraInit` nodes, the active `CameraInit` was always
reset to the first one in the list, independently from its previous
value.

This commit changes that behaviour by only modifying the active
`CameraInit` if no `CameraInit` node has been assigned yet, or if the
active `CameraInit` does not exist anymore (meaning it has been removed).

This requires to emit the `cameraInitChanged` signal every single time
the list of existing `CameraInit` nodes is modified even if the active one
is not changed, and to connect it to the ImageGallery in order to ensure
the index from the combo box always corresponds to the currently active
`CameraInit` node. Indeed, when the list of CameraInits is updated, the
model for the combo box is reset, and it needs to be re-updated with the
correct non-default value.
This commit is contained in:
Candice Bentéjac 2023-10-03 18:11:55 +02:00
parent 4c1a294ca2
commit a606a8f83c
2 changed files with 14 additions and 1 deletions

View file

@ -35,6 +35,14 @@ Panel {
title: "Image Gallery"
implicitWidth: (root.defaultCellSize + 2) * 2
Connections {
target: _reconstruction
function onCameraInitChanged() {
nodesCB.currentIndex = root.cameraInitIndex
}
}
QtObject {
id: m
property variant currentCameraInit: _reconstruction && _reconstruction.tempCameraInit ? _reconstruction.tempCameraInit : root.cameraInit

View file

@ -573,7 +573,12 @@ class Reconstruction(UIGraph):
if set(self._cameraInits.objectList()) == set(cameraInits):
return
self._cameraInits.setObjectList(cameraInits)
self.cameraInit = cameraInits[0] if cameraInits else None
if self.cameraInit is None or self.cameraInit not in cameraInits:
self.cameraInit = cameraInits[0] if cameraInits else None
# Manually emit the signal to ensure the active CameraInit index is always up-to-date in the UI
self.cameraInitChanged.emit()
def getCameraInitIndex(self):
if not self._cameraInit: