Draft: fix setting of self.Type

Fixes #17750.

`self.Type` should be set in `__init__` and `loads`, and not in `onDocumentRestored`.
This commit is contained in:
Roy-043
2025-06-26 12:01:08 +02:00
committed by Chris Hennes
parent dd5cb6aa61
commit 8add557e2f
4 changed files with 22 additions and 20 deletions

View File

@@ -42,8 +42,8 @@ class Text(DraftAnnotation):
def __init__(self, obj):
obj.Proxy = self
self.set_properties(obj)
self.Type = "Text"
self.set_properties(obj)
def set_properties(self, obj):
"""Add properties to the object and set them."""
@@ -77,11 +77,8 @@ class Text(DraftAnnotation):
"""Execute code when the document is restored."""
super().onDocumentRestored(obj)
gui_utils.restore_view_object(obj, vp_module="view_text", vp_class="ViewProviderText")
# See loads: old_type is None for new objects.
old_type = self.Type
self.Type = "Text"
if old_type is None:
# See loads:
if self.stored_type is None:
return
if not getattr(obj, "ViewObject", None):
return
@@ -96,10 +93,11 @@ class Text(DraftAnnotation):
_wrn("v0.21, " + obj.Label + ", "
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
def loads(self,state):
def loads(self, state):
# Before update_properties_0v21 the self.Type value was stored.
# We use this to identify older objects that need to be updated.
self.Type = state
self.stored_type = state
self.Type = "Text"
# Alias for compatibility with v0.18 and earlier