Document/PropertyExpressionEngine: Added onDocumentRestored function, to update internals of PropertyExpressionEngine after loading a document from disk.

This commit is contained in:
Eivind Kvedalen 2015-12-24 14:38:50 +01:00
parent 905cd3b1d2
commit 009d0c03b4
3 changed files with 24 additions and 9 deletions

View File

@ -1274,6 +1274,7 @@ Document::importObjects(Base::XMLReader& reader)
// reset all touched
for (std::vector<DocumentObject*>::iterator it= objs.begin();it!=objs.end();++it) {
(*it)->onDocumentRestored();
(*it)->ExpressionEngine.onDocumentRestored();
(*it)->purgeTouched();
}
return objs;
@ -1488,6 +1489,7 @@ void Document::restore (void)
for (std::map<std::string,DocumentObject*>::iterator It= d->objectMap.begin();It!=d->objectMap.end();++It) {
It->second->connectRelabelSignals();
It->second->onDocumentRestored();
It->second->ExpressionEngine.onDocumentRestored();
It->second->purgeTouched();
}

View File

@ -130,6 +130,7 @@ TYPESYSTEM_SOURCE(App::PropertyExpressionEngine , App::Property);
PropertyExpressionEngine::PropertyExpressionEngine()
: Property()
, AtomicPropertyChangeInterface()
, running(false)
, validator(0)
{
@ -172,7 +173,7 @@ void PropertyExpressionEngine::Paste(const Property &from)
{
const PropertyExpressionEngine * fromee = static_cast<const PropertyExpressionEngine*>(&from);
aboutToSetValue();
AtomicPropertyChange signaller(*this);
expressions.clear();
for (ExpressionMap::const_iterator it = fromee->expressions.begin(); it != fromee->expressions.end(); ++it) {
@ -181,8 +182,6 @@ void PropertyExpressionEngine::Paste(const Property &from)
}
validator = fromee->validator;
hasSetValue();
}
void PropertyExpressionEngine::Save(Base::Writer &writer) const
@ -206,6 +205,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader)
int count = reader.getAttributeAsFloat("count");
restoredExpressions.clear();
for (int i = 0; i < count; ++i) {
DocumentObject * docObj = freecad_dynamic_cast<DocumentObject>(getContainer());
@ -214,7 +214,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader)
boost::shared_ptr<Expression> expression(ExpressionParser::parse(docObj, reader.getAttribute("expression")));
const char * comment = reader.hasAttribute("comment") ? reader.getAttribute("comment") : 0;
setValue(path, expression, comment);
restoredExpressions[path] = ExpressionInfo(expression, comment);
}
reader.readEndElement("ExpressionEngine");
@ -363,6 +363,14 @@ void PropertyExpressionEngine::slotObjectDeleted(const DocumentObject &obj)
}
}
void PropertyExpressionEngine::onDocumentRestored()
{
AtomicPropertyChange signaller(*this);
for (ExpressionMap::iterator it = restoredExpressions.begin(); it != restoredExpressions.end(); ++it)
setValue(it->first, it->second.expression, it->second.comment.size() > 0 ? it->second.comment.c_str() : 0);
}
/**
* @brief Get expression for \a path.
* @param path ObjectIndentifier to query for.
@ -408,16 +416,14 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::sh
if (error.size() > 0)
throw Base::Exception(error.c_str());
aboutToSetValue();
AtomicPropertyChange signaller(*this);
expressions[usePath] = ExpressionInfo(expr, comment);
expressionChanged(usePath);
hasSetValue();
}
else {
aboutToSetValue();
AtomicPropertyChange signaller(*this);
expressions.erase(usePath);
expressionChanged(usePath);
hasSetValue();
}
}

View File

@ -44,7 +44,8 @@ class DocumentObjectExecReturn;
class ObjectIdentifier;
class Expression;
class AppExport PropertyExpressionEngine : public App::Property
class AppExport PropertyExpressionEngine : public App::Property, private App::AtomicPropertyChangeInterface<PropertyExpressionEngine>
{
TYPESYSTEM_HEADER();
public:
@ -124,6 +125,8 @@ public:
///signal called when a expression was changed
boost::signal<void (const App::ObjectIdentifier &)> expressionChanged;
void onDocumentRestored();
/* Python interface */
PyObject *getPyObject(void);
void setPyObject(PyObject *);
@ -149,6 +152,10 @@ private:
ValidatorFunc validator; /**< Valdiator functor */
ExpressionMap restoredExpressions; /**< Expressions are read from file to this map first before they are validated and inserted into the actual map */
friend class AtomicPropertyChange;
};
}