Draft: clean up the ViewProviderDraftAnnotation class

This class is the base of the viewproviders of annotation-type
objects like dimensions (linear, radial, angular), labels,
and texts.

The basic properties of `ViewProviderDraftAnnotation`
are set up by a method `set_properties`, which can be called
in the derived classes.

In the general proxy object `DraftAnnotation` we implement
the `onDocumentRestored` method in order to add the missing
view property `AnnotationStyle` to older objects.
This commit is contained in:
vocx-fc
2020-06-16 10:40:16 -05:00
committed by Yorik van Havre
parent 270e4b100a
commit 3f75dc7c61
2 changed files with 188 additions and 68 deletions

View File

@@ -63,15 +63,21 @@ class DraftAnnotation(object):
Check if new properties are present after the object is restored
in order to migrate older objects.
"""
self.add_missing_properties_0v19(obj)
def add_missing_properties_0v19(self, obj):
"""Provide missing annotation properties, if they don't exist."""
if (hasattr(obj, "ViewObject") and obj.ViewObject
and not hasattr(obj.ViewObject, 'ScaleMultiplier')):
if hasattr(obj, "ViewObject") and obj.ViewObject:
vobj = obj.ViewObject
self.add_missing_properties_0v19(obj, vobj)
def add_missing_properties_0v19(self, obj, vobj):
"""Provide missing annotation properties, if they don't exist."""
vproperties = vobj.PropertiesList
if 'ScaleMultiplier' not in vproperties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Dimension size overall multiplier")
"General scaling factor that affects "
"the annotation consistently\n"
"because it scales the text, "
"and the line decorations, if any,\n"
"in the same proportion.")
vobj.addProperty("App::PropertyFloat",
"ScaleMultiplier",
"Annotation",
@@ -81,6 +87,30 @@ class DraftAnnotation(object):
_info = "added view property 'ScaleMultiplier'"
_wrn("v0.19, " + obj.Label + ", " + _tr(_info))
if 'AnnotationStyle' not in vproperties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Annotation style to apply "
"to this object.\n"
"When using a saved style "
"some of the view properties "
"will become read-only;\n"
"they will only be editable by changing "
"the style through "
"the 'Annotation style editor' tool.")
vobj.addProperty("App::PropertyEnumeration",
"AnnotationStyle",
"Annotation",
_tip)
styles = []
for key in obj.Document.Meta.keys():
if key.startswith("Draft_Style_"):
styles.append(key[12:])
vobj.AnnotationStyle = [""] + styles
_info = "added view property 'AnnotationStyle'"
_wrn("v0.19, " + obj.Label + ", " + _tr(_info))
def __getstate__(self):
"""Return a tuple of objects to save or None.