[ui] ImageGallery: improve synced selection with 3D view

Fix synchronization with 3D camera selection when the corresponding image has not been instantiated in ImageGallery (outside visible viewport).

* SortFilterDelegateModel: add "find" method
* ImageGallery
    * move passive selection logic out of the Delegate as it's created only when visible in the GridView
    * use SortFilterDelegateModel.find to get item index based on selected "viewId" and set GridView's currentIndex
This commit is contained in:
Yann Lanthony 2018-05-28 16:10:19 +02:00
parent c606c1d3e2
commit df1dc2bab6
2 changed files with 30 additions and 15 deletions

View file

@ -48,6 +48,16 @@ Panel {
highlightFollowsCurrentItem: true
keyNavigationEnabled: true
// Update grid current item when selected view changes
Connections {
target: _reconstruction
onSelectedViewIdChanged: {
var idx = grid.model.find(_reconstruction.selectedViewId, "viewId")
if(idx >= 0)
grid.currentIndex = idx
}
}
model: SortFilterDelegateModel {
id: sortedModel
model: _reconstruction.viewpoints
@ -61,8 +71,11 @@ Panel {
// override modelData to return basename of viewpoint's path for sorting
function modelData(item, roleName) {
var value = item.model.object.value.get(roleName).value
if(roleName == sortRole)
return Filepath.basename(item.model.object.value.get(roleName).value)
return Filepath.basename(value)
else
return value
}
delegate: ImageDelegate {
@ -70,25 +83,17 @@ Panel {
viewpoint: object.value
width: grid.cellWidth
height: grid.cellHeight
property bool isGridCurrentItem: GridView.isCurrentItem
property bool isSelectedViewId: _reconstruction.selectedViewId == viewpoint.get("viewId").value
readOnly: root.readOnly
// need to handle this both ways
// since arrow keys navigation modifies GridView.isCurrentItem out of our scope
onIsGridCurrentItemChanged: {
if(isGridCurrentItem && !isSelectedViewId)
_reconstruction.selectedViewId = viewpoint.get("viewId").value
}
onIsSelectedViewIdChanged: {
if(isSelectedViewId && !isGridCurrentItem)
grid.currentIndex = DelegateModel.filteredIndex
}
isCurrentItem: GridView.isCurrentItem
onIsCurrentItemChanged: {
if(isCurrentItem)
_reconstruction.selectedViewId = viewpoint.get("viewId").value
}
onPressed: {
_reconstruction.selectedViewId = viewpoint.get("viewId").value
grid.currentIndex = DelegateModel.filteredIndex
if(mouse.button == Qt.LeftButton)
grid.forceActiveFocus()
}

View file

@ -65,6 +65,16 @@ DelegateModel {
return item.model[roleName]
}
/// Get the index of the first element which matches 'value' for the given 'roleName'
function find(value, roleName) {
for(var i = 0; i < filteredItems.count; ++i)
{
if(modelData(filteredItems.get(i), roleName) == value)
return i
}
return -1
}
/**
* Return whether 'value' respects 'filter' condition
*