From 61ec1192f3d16fdcfd79dd457c29332dce42378c Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 5 Feb 2020 20:01:32 +0800 Subject: [PATCH] App: change PropertyContainer::Restore() Changes the way PropertyContainer handles existing property while restoring. Previously it will first ask DynamicProperty to restore if possible, then fallback to static property if else. This patch looks up existing property first, and only fallback to DynamicProperty if not found. This handles situation when an object changes an originally dynamic property into a static one. With the original code, it will add an auto renamed dynamic property that no one knows its existence. --- src/App/PropertyContainer.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index 5fda5ce279..a7438cea2f 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -332,21 +332,21 @@ void PropertyContainer::Restore(Base::XMLReader &reader) reader.readElement("Property"); std::string PropName = reader.getAttribute("name"); std::string TypeName = reader.getAttribute("type"); - auto prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); - if(!prop) - prop = getPropertyByName(PropName.c_str()); - - decltype(Property::StatusBits) status; - if(reader.hasAttribute("status")) { - status = decltype(status)(reader.getAttributeAsUnsigned("status")); - if(prop) - prop->setStatusValue(status.to_ulong()); - } // NOTE: We must also check the type of the current property because a // subclass of PropertyContainer might change the type of a property but // not its name. In this case we would force to read-in a wrong property // type and the behaviour would be undefined. try { + auto prop = getPropertyByName(PropName.c_str()); + if(!prop) + prop = dynamicProps.restore(*this,PropName.c_str(),TypeName.c_str(),reader); + + decltype(Property::StatusBits) status; + if(reader.hasAttribute("status")) { + status = decltype(status)(reader.getAttributeAsUnsigned("status")); + if(prop) + prop->setStatusValue(status.to_ulong()); + } // name and type match if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) { if (!prop->testStatus(Property::Transient)