Don't pass ModelItem fields starting with _ to QML

This commit is contained in:
miruka 2021-03-02 07:41:16 -04:00
parent 045bce5f9c
commit 5476cf1e6d
2 changed files with 9 additions and 3 deletions

View File

@ -85,6 +85,9 @@ class Model(MutableMapping):
if not changed_fields: if not changed_fields:
for field in new.__dataclass_fields__: # type: ignore for field in new.__dataclass_fields__: # type: ignore
if field.startswith("_"):
continue
changed = True changed = True
if existing: if existing:

View File

@ -49,6 +49,7 @@ class ModelItem:
return { return {
name: self.serialized_field(name) name: self.serialized_field(name)
for name in self.__dataclass_fields__ # type: ignore for name in self.__dataclass_fields__ # type: ignore
if not name.startswith("_")
} }
@ -92,16 +93,18 @@ class ModelItem:
for name, value in changes.items(): for name, value in changes.items():
super().__setattr__(name, value) super().__setattr__(name, value)
is_field = name in self.__dataclass_fields__ # type: ignore
if name in self.__dataclass_fields__: # type: ignore if is_field and not name.startswith("_"):
qml_changes[name] = self.serialized_field(name) qml_changes[name] = self.serialized_field(name)
parent._sorted_data.add(self) parent._sorted_data.add(self)
index_now = parent._sorted_data.index(self) index_now = parent._sorted_data.index(self)
index_change = index_then != index_now
# Now, inform QML about changed dataclass fields if any. # Now, inform QML about changed dataclass fields if any.
if not parent.sync_id or not qml_changes: if not parent.sync_id or (not qml_changes and not index_change):
return return
ModelItemSet(parent.sync_id, index_then, index_now, qml_changes) ModelItemSet(parent.sync_id, index_then, index_now, qml_changes)