Skip to content

Commit 4ad6ebc

Browse files
authored
Merge pull request #1316 from marc-vdm/treeview_update_restore_state
Treeview restores open/close state on update
2 parents 196bca9 + e3d6b02 commit 4ad6ebc

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

activity_browser/layouts/tabs/project_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ def database_changed(self, database: bd.Database) -> None:
307307
self.mode_radio_list.show()
308308
self.mode_radio_tree.show()
309309
elif "ISIC rev.4 ecoinvent" in self.table.model._dataframe.columns:
310-
# a treeview exists
310+
# a treeview exists, update it
311+
self.tree.get_expand_state()
311312
self.tree.model.setup_and_sync()
313+
self.tree.set_expand_state()
312314

313315
# make sure that the radio buttons are available
314316
self.mode_radio_list.show()

activity_browser/ui/tables/inventory.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def __init__(self, parent=None, database_name=None):
281281
super().__init__(parent)
282282
self.database_name = database_name
283283
self.db_read_only = project_settings.db_is_readonly(self.database_name)
284+
self.expand_state = []
284285
self.HEADERS = AB_metadata.get_existing_fields(self.HEADERS)
285286

286287
# set drag ability
@@ -511,14 +512,25 @@ def find_levels(self, level=None) -> list:
511512
parent = parent.parent()
512513
return levels[::-1]
513514

514-
def expanded_list(self):
515+
def get_expand_state(self) -> None:
516+
"""Store the expanded state of the tree.
517+
518+
Does not return anything but stores the expanded items in a self.expand_state."""
515519
it = self.model.iterator(None)
516520
expanded_items = []
517521
while it != None:
518522
if self.isExpanded(self.model.createIndex(it.row(), 0, it)):
519523
expanded_items.append(self.build_path(it))
520524
it = self.model.iterator(it)
521-
return expanded_items
525+
self.expand_state = expanded_items
526+
527+
def set_expand_state(self) -> None:
528+
"""Sets any items in self.expand_state in the tree to expanded."""
529+
it = self.model.iterator(None)
530+
while it != None:
531+
if self.build_path(it) in self.expand_state:
532+
self.setExpanded(self.model.createIndex(it.row(), 0, it), True)
533+
it = self.model.iterator(it)
522534

523535
def build_path(self, iter):
524536
"""Given an iterator of the TreeItem type build the path back to the

0 commit comments

Comments
 (0)