App: fix restoring the attributes of a dynamic property
For more details see: https://forum.freecadweb.org/viewtopic.php?p=591465#p591465
This commit is contained in:
@@ -307,7 +307,10 @@ Property *DynamicProperty::restore(PropertyContainer &pc,
|
||||
doc = reader.getAttribute("doc");
|
||||
if (reader.hasAttribute("attr")) {
|
||||
attr = reader.getAttribute("attr");
|
||||
if (attr) attribute = attr[0]-48;
|
||||
if (attr) {
|
||||
std::istringstream str(attr);
|
||||
str >> attribute;
|
||||
}
|
||||
}
|
||||
if (reader.hasAttribute("ro")) {
|
||||
ro = reader.getAttribute("ro");
|
||||
@@ -317,6 +320,7 @@ Property *DynamicProperty::restore(PropertyContainer &pc,
|
||||
hide = reader.getAttribute("hide");
|
||||
if (hide) hidden = (hide[0]-48) != 0;
|
||||
}
|
||||
|
||||
return addDynamicProperty(pc,TypeName, PropName, group, doc, attribute, readonly, hidden);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,6 +377,30 @@ class DocumentBasicCases(unittest.TestCase):
|
||||
obj1.Link = obj2
|
||||
self.assertEqual(obj1.MustExecute, False)
|
||||
|
||||
def testAttributeOfDynamicProperty(self):
|
||||
obj = self.Doc.addObject("App::FeaturePython", "Obj")
|
||||
# Prop_NoPersist is the enum with the highest value
|
||||
max_value = FreeCAD.PropertyType.Prop_NoPersist
|
||||
list_of_types = []
|
||||
for i in range(0, max_value + 1):
|
||||
obj.addProperty("App::PropertyString", "String" + str(i), "", "", i)
|
||||
list_of_types.append(obj.getTypeOfProperty("String" + str(i)))
|
||||
|
||||
# saving and restoring
|
||||
SaveName = tempfile.gettempdir() + os.sep + "CreateTest.FCStd"
|
||||
self.Doc.saveAs(SaveName)
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
self.Doc = FreeCAD.open(SaveName)
|
||||
|
||||
obj = self.Doc.ActiveObject
|
||||
for i in range(0, max_value):
|
||||
types = obj.getTypeOfProperty("String" + str(i))
|
||||
self.assertEqual(list_of_types[i], types)
|
||||
|
||||
# A property with flag Prop_NoPersist won't be saved to the file
|
||||
with self.assertRaises(AttributeError):
|
||||
obj.getTypeOfProperty("String" + str(max_value))
|
||||
|
||||
def testNotification_Issue2902Part2(self):
|
||||
o = self.Doc.addObject("App::FeatureTest","test")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user