Skip to content

Commit

Permalink
Fix get name from parameter in entity graph
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Sep 5, 2023
1 parent 6b796ac commit 30f9dc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spinetoolbox/spine_db_editor/graphics_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def update_name(self):
"""Refreshes the name."""
db_map_ids_by_name = dict()
for db_map, id_ in self.db_map_ids:
name = self.db_mngr.get_item(db_map, self.entity_type, id_)["name"]
name = self._spine_db_editor.get_item_name(db_map, id_)
db_map_ids_by_name.setdefault(name, list()).append((db_map, id_))
if len(db_map_ids_by_name) == 1:
name = next(iter(db_map_ids_by_name))
Expand Down
20 changes: 10 additions & 10 deletions spinetoolbox/spine_db_editor/widgets/graph_view_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, *args, **kwargs):
self._extending_graph = False
self._object_fetch_parent = None
self._relationship_fetch_parent = None
self._name_by_db_map_object_id = {}

def _renew_fetch_parents(self):
if self._object_fetch_parent is not None:
Expand Down Expand Up @@ -425,13 +426,13 @@ def _update_graph_data(self):
db_map_object_id_lists[db_map, relationship["id"]] = db_map_object_id_list
db_map_object_ids_by_key = {}
db_map_relationship_ids_by_key = {}
self._name_by_db_map_object_id.clear()
for db_map_object_id in db_map_object_ids:
key = self._get_object_key(db_map_object_id)
db_map_object_ids_by_key.setdefault(key, set()).add(db_map_object_id)
for db_map_relationship_id in db_map_object_id_lists:
key = self._get_relationship_key(db_map_relationship_id)
db_map_relationship_ids_by_key.setdefault(key, set()).add(db_map_relationship_id)

new_db_map_object_id_sets = list(db_map_object_ids_by_key.values())
new_db_map_relationship_id_sets = list(db_map_relationship_ids_by_key.values())
if (
Expand Down Expand Up @@ -491,16 +492,15 @@ def get_item_name(self, db_map, object_id):
return ""
if not self.ui.graphicsView.name_parameter:
return object_["name"]
alternative = next(iter(self.db_mngr.get_items(db_map, "alternative", only_visible=False)), None)
table_cache = db_map.cache.table_cache("parameter_value")
name_pv = table_cache.find_item(
{
"parameter_definition_name": self.ui.graphicsView.name_parameter,
"entity_class_name": entity["class_name"],
"entity_byname": entity["byname"],
"alternative_name": alternative["name"],
if not self._name_by_db_map_object_id:
self._name_by_db_map_object_id = {
(db_map, pv["object_id"]): pv
for db_map in self.db_maps
for pv in self.db_mngr.get_items_by_field(
db_map, "parameter_value", "parameter_name", self.ui.graphicsView.name_parameter, only_visible=False
)
}
)
name_pv = self._name_by_db_map_object_id.get((db_map, object_id))
if not name_pv:
return ""
name = from_database(name_pv["value"], name_pv["type"])
Expand Down

0 comments on commit 30f9dc7

Please sign in to comment.