use inner function instead of return value in _expand_where_necessary()

This commit is contained in:
Damien Elmes 2021-06-29 11:40:59 +10:00
parent 33e6662dda
commit ecabf35350

View file

@ -225,25 +225,29 @@ class SidebarTreeView(QTreeView):
parent: Optional[QModelIndex] = None, parent: Optional[QModelIndex] = None,
searching: bool = False, searching: bool = False,
scroll_to_first_match: bool = False, scroll_to_first_match: bool = False,
) -> bool: ) -> None:
parent = parent or QModelIndex() def expand_node(parent: QModelIndex) -> None:
for row in range(model.rowCount(parent)): nonlocal scroll_to_first_match
idx = model.index(row, 0, parent)
if not idx.isValid(): for row in range(model.rowCount(parent)):
continue idx = model.index(row, 0, parent)
scroll_to_first_match = self._expand_where_necessary( if not idx.isValid():
model, idx, searching, scroll_to_first_match continue
)
if item := model.item_for_index(idx): # descend into children first
if item.show_expanded(searching): expand_node(idx)
self.setExpanded(idx, True)
if item.is_highlighted() and scroll_to_first_match: if item := model.item_for_index(idx):
self.selectionModel().setCurrentIndex( if item.show_expanded(searching):
idx, QItemSelectionModel.SelectCurrent self.setExpanded(idx, True)
) if item.is_highlighted() and scroll_to_first_match:
self.scrollTo(idx) self.selectionModel().setCurrentIndex(
scroll_to_first_match = False idx, QItemSelectionModel.SelectCurrent
return scroll_to_first_match )
self.scrollTo(idx)
scroll_to_first_match = False
expand_node(parent or QModelIndex())
def update_search( def update_search(
self, self,