Skip to content

Commit

Permalink
draft: try to make layer id unique, rename to iid
Browse files Browse the repository at this point in the history
Signed-off-by: minff <16268924+minff@users.noreply.github.com>
  • Loading branch information
minff committed Feb 29, 2024
1 parent f481883 commit 4632836
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
10 changes: 5 additions & 5 deletions XYZHubConnector/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,10 +822,10 @@ def _get_lst_reloading_con(self):
for qnode in self.iter_visible_xyz_node():
if qnode.nodeType() == qnode.NodeLayer:
layer = qnode.layer()
xlayer_id = get_customProperty_str(layer, QProps.UNIQUE_ID)
xlayer_id = QProps.get_iid(layer)
is_editable = layer.isEditable()
else:
xlayer_id = get_customProperty_str(qnode, QProps.UNIQUE_ID)
xlayer_id = QProps.get_iid(qnode)
is_editable = None
if xlayer_id in editing_xid:
continue
Expand Down Expand Up @@ -987,7 +987,7 @@ def init_layer_loader(self, qnode):
def init_all_layer_loader(self):
cnt = 0
for qnode in self.iter_update_all_xyz_node():
xlayer_id = get_customProperty_str(qnode, QProps.UNIQUE_ID)
xlayer_id = QProps.get_iid(qnode)
con = self.con_man.get_loader(xlayer_id)
if con:
continue
Expand All @@ -1010,7 +1010,7 @@ def cb_qnode_visibility_changed(self, qnode):
if is_xyz_supported_layer(vlayer):
vlayer.reload()
return
xlayer_id = get_customProperty_str(qnode, QProps.UNIQUE_ID)
xlayer_id = QProps.get_iid(qnode)
con = self.con_man.get_interactive_loader(xlayer_id)
if con:
con.stop_loading()
Expand All @@ -1022,7 +1022,7 @@ def cb_qnodes_deleting(self, parent, i0, i1):
for i in range(i0, i1 + 1):
qnode = lst[i]
if is_parent_root and is_xyz_supported_node(qnode):
xlayer_id = get_customProperty_str(qnode, QProps.UNIQUE_ID)
xlayer_id = QProps.get_iid(qnode)
self.pending_delete_qnodes.setdefault(key, list()).append(xlayer_id)
self.con_man.remove_persistent_loader(xlayer_id)
# is possible to handle vlayer delete here
Expand Down
18 changes: 9 additions & 9 deletions XYZHubConnector/xyz_qgis/layer/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
conn_info,
meta,
tags="",
unique: str = None,
iid: str = None,
loader_params: dict = None,
group_name="XYZ Layer",
ext="gpkg",
Expand All @@ -74,7 +74,7 @@ def __init__(
self.conn_info = conn_info
self.meta = meta
self.tags = tags
self.unique = str(unique or int(time.time() * 10))
self.iid = str(iid or int(time.time() * 1000))
self.loader_params = loader_params or dict()

self._base_group_name = group_name
Expand All @@ -93,7 +93,7 @@ def load_from_qnode(cls, qnode):
meta = get_customProperty_str(qnode, QProps.LAYER_META)
conn_info = get_customProperty_str(qnode, QProps.CONN_INFO)
tags = get_customProperty_str(qnode, QProps.TAGS)
unique = get_customProperty_str(qnode, QProps.UNIQUE_ID)
iid = get_customProperty_str(qnode, QProps.UNIQUE_ID)
loader_params = get_customProperty_str(qnode, QProps.LOADER_PARAMS)
meta = load_json_default(meta, default=dict())
conn_info = load_json_default(conn_info, default=dict())
Expand All @@ -102,7 +102,7 @@ def load_from_qnode(cls, qnode):

name = qnode.name()
obj = cls(
conn_info, meta, tags=tags, unique=unique, loader_params=loader_params, group_name=name
conn_info, meta, tags=tags, iid=iid, loader_params=loader_params, group_name=name
)
obj.qgroups["main"] = qnode
obj._update_group_name(qnode)
Expand Down Expand Up @@ -173,7 +173,7 @@ def _save_meta_node(self, qnode):
qnode.setCustomProperty(
QProps.CONN_INFO, json.dumps(self.conn_info.to_project_dict(), ensure_ascii=False)
)
qnode.setCustomProperty(QProps.UNIQUE_ID, self.get_id())
qnode.setCustomProperty(QProps.UNIQUE_ID, self.get_iid())
self._save_params_to_node(qnode)

def _save_meta_vlayer(self, vlayer):
Expand Down Expand Up @@ -400,14 +400,14 @@ def _layer_fname(self):
returns file name of the sqlite db corresponds to xyz layer
"""
tags = self.tags.replace(",", "_") if len(self.tags) else ""
return "{id}_{tags}_{unique}".format(
return "{id}_{tags}_{iid}".format(
id=self.meta.get("id", ""),
tags=tags,
unique=self.unique,
iid=self.iid,
)

def get_id(self):
return self.unique
def get_iid(self):
return self.iid

def get_map_fields(self):
"""returns reference to existing mutable map_fields"""
Expand Down
5 changes: 5 additions & 0 deletions XYZHubConnector/xyz_qgis/layer/layer_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def getProperty(qnode, key):
val = qnode.customProperty(key)
return val

@classmethod
def get_iid(cls, qnode):
val = cls.get_customProperty_str(qnode, QProps.UNIQUE_ID)
return val

@classmethod
def updatePropsVersion(cls, qnode):
cls._removeProperty(qnode, cls.EDIT_FLAG) # deprecated props
Expand Down
2 changes: 1 addition & 1 deletion XYZHubConnector/xyz_qgis/loader/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def reset(self):
def make_register_xyz_layer_cb(self, con, ptr):
def _register_xyz_layer():
# assert con.layer is not None
self._layer_ptr[con.layer.get_id()] = ptr
self._layer_ptr[con.layer.get_iid()] = ptr

return _register_xyz_layer

Expand Down

0 comments on commit 4632836

Please sign in to comment.