From b74b3f3358730efc858bb7f7bfc6effbc32a9b9d Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Mon, 8 Feb 2016 21:04:39 +0100 Subject: [PATCH] Spreadsheet: Refactor code and reuse visitors from ExpressionVisitors.h --- src/Mod/Spreadsheet/App/PropertySheet.cpp | 59 ++++------------------- 1 file changed, 10 insertions(+), 49 deletions(-) diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index 57844a9f7..8ee07e62b 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -49,32 +49,12 @@ using namespace Spreadsheet; namespace Spreadsheet { -class RelabelDocumentObjectExpressionVisitor : public ExpressionVisitor { +class BuildDocDepsExpressionVisitor : public ExpressionModifier { public: - RelabelDocumentObjectExpressionVisitor(const std::string & _oldName, const std::string & _newName) - : oldName(_oldName) - , newName(_newName) - { - } - - void visit(Expression * node) { - VariableExpression *expr = freecad_dynamic_cast(node); - - if (expr) - expr->renameDocumentObject(oldName, newName); - } - -private: - std::string oldName; - std::string newName; -}; - -class BuildDocDepsExpressionVisitor : public ExpressionVisitor { -public: - - BuildDocDepsExpressionVisitor(std::set & _docDeps) - : docDeps(_docDeps) + BuildDocDepsExpressionVisitor(PropertySheet & prop, std::set & _docDeps) + : ExpressionModifier(prop) + , docDeps(_docDeps) { } @@ -87,8 +67,10 @@ public: const App::Property * prop = expr->getProperty(); App::DocumentObject * docObj = freecad_dynamic_cast(prop->getContainer()); - if (docObj) + if (docObj) { + setExpressionChanged(); docDeps.insert(docObj); + } } catch (const Base::Exception &) { // Ignore this type of exception; it means that the property was not found, which is ok here @@ -100,27 +82,6 @@ private: std::set & docDeps; }; -class RelabelDocumentExpressionVisitor : public ExpressionVisitor { -public: - - RelabelDocumentExpressionVisitor(const std::string & _oldName, const std::string & _newName) - : oldName(_oldName) - , newName(_newName) - { - } - - void visit(Expression * node) { - VariableExpression *expr = freecad_dynamic_cast(node); - - if (expr) - expr->renameDocument(oldName, newName); - } - -private: - std::string oldName; - std::string newName; -}; - } TYPESYSTEM_SOURCE(Spreadsheet::PropertySheet , App::Property); @@ -1130,7 +1091,7 @@ void PropertySheet::renamedDocumentObject(const App::DocumentObject * docObj) std::map::iterator i = data.begin(); AtomicPropertyChange signaller(*this); - RelabelDocumentObjectExpressionVisitor v(documentObjectName[docObj], docObj->Label.getValue()); + RelabelDocumentObjectExpressionVisitor v(*this, documentObjectName[docObj], docObj->Label.getValue()); while (i != data.end()) { i->second->visit(v); @@ -1151,7 +1112,7 @@ void PropertySheet::renamedDocument(const App::Document * doc) /* Resolve all cells */ AtomicPropertyChange signaller(*this); - RelabelDocumentExpressionVisitor v(documentName[doc], doc->Label.getValue()); + RelabelDocumentExpressionVisitor v(*this, documentName[doc], doc->Label.getValue()); while (i != data.end()) { i->second->visit(v); @@ -1240,7 +1201,7 @@ void PropertySheet::rebuildDocDepList() AtomicPropertyChange signaller(*this); docDeps.clear(); - BuildDocDepsExpressionVisitor v(docDeps); + BuildDocDepsExpressionVisitor v(*this, docDeps); std::map::iterator i = data.begin();