diff --git a/src/Mod/Spreadsheet/App/Expression.cpp b/src/Mod/Spreadsheet/App/Expression.cpp index 19960bb11..e00ea18ab 100644 --- a/src/Mod/Spreadsheet/App/Expression.cpp +++ b/src/Mod/Spreadsheet/App/Expression.cpp @@ -206,7 +206,7 @@ void Path::renameDocumentObject(const std::string &oldName, const std::string &n void Path::renameDocument(const std::string &oldName, const std::string &newName) { - if (documentNameSet && documentName == oldName) { + if (documentName == oldName) { documentName = newName; resolve(); } diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index 75e34d759..0826fb112 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -800,9 +800,10 @@ void PropertySheet::addDependencies(CellAddress key) while (i != expressionDeps.end()) { const Property * prop = (*i).getProperty(); DocumentObject * docObj = prop ? freecad_dynamic_cast(prop->getContainer()) : 0; + Document * doc = docObj ? docObj->getDocument() : 0; - std::string docName = (*i).getDocumentName().getString(); - std::string docObjName = docName + "#" + (prop ? docObj->getNameInDocument() : (*i).getDocumentObjectName().getString()); + std::string docName = doc ? doc->Label.getValue() : (*i).getDocumentName().getString(); + std::string docObjName = docName + "#" + (docObj ? docObj->getNameInDocument() : (*i).getDocumentObjectName().getString()); std::string propName = docObjName + "." + (*i).getPropertyName(); if (!prop) @@ -820,7 +821,8 @@ void PropertySheet::addDependencies(CellAddress key) } // Observe document to trach changes to the property - owner->observeDocument(docName); + if (doc) + owner->observeDocument(doc); // Insert into maps propertyNameToCellMap[propName].insert(key); @@ -879,9 +881,12 @@ void PropertySheet::removeDependencies(CellAddress key) assert(k != documentObjectToCellMap.end()); k->second.erase(key); + ++j; } + + cellToDocumentObjectMap.erase(i2); } @@ -900,7 +905,7 @@ void PropertySheet::recomputeDependants(const Property *prop) assert(name != 0); if (owner && name) { - const char * docName = owner->getDocument()->getName(); + const char * docName = owner->getDocument()->Label.getValue(); const char * nameInDoc = owner->getNameInDocument(); if (nameInDoc) { @@ -924,7 +929,7 @@ void PropertySheet::recomputeDependants(const Property *prop) void PropertySheet::invalidateDependants(const DocumentObject *docObj) { - const char * docName = docObj->getDocument()->getName(); + const char * docName = docObj->getDocument()->Label.getValue(); const char * docObjName = docObj->getNameInDocument(); // Touch to force recompute @@ -995,7 +1000,7 @@ void PropertySheet::renamedDocument(const Document * doc) void PropertySheet::recomputeDependants(const DocumentObject *docObj) { - const char * docName = docObj->getDocument()->getName(); + const char * docName = docObj->getDocument()->Label.getValue(); const char * docObjName = docObj->getNameInDocument(); // Touch to force recompute diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 30b76d2b6..0ffd3baed 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -659,7 +659,7 @@ const char *Sheet::getPropertyName(const Property *prop) const void Sheet::recomputeCell(CellAddress p) { Cell * cell = cells.getValue(p); - std::string docName = getDocument()->getName(); + std::string docName = getDocument()->Label.getValue(); std::string docObjName = std::string(getNameInDocument()); std::string name = docName + "#" + docObjName + "." + toAddress(p); @@ -1036,7 +1036,7 @@ std::set Sheet::dependsOn(CellAddress address) const void Sheet::providesTo(CellAddress address, std::set & result) const { - const char * docName = getDocument()->getName(); + const char * docName = getDocument()->Label.getValue(); const char * docObjName = getNameInDocument(); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address); std::set tmpResult = cells.getDeps(fullName); @@ -1047,7 +1047,7 @@ void Sheet::providesTo(CellAddress address, std::set & result) cons void Sheet::providesTo(CellAddress address, std::set & result) const { - const char * docName = getDocument()->getName(); + const char * docName = getDocument()->Label.getValue(); const char * docObjName = getNameInDocument(); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address); result = cells.getDeps(fullName); @@ -1062,23 +1062,25 @@ void Sheet::onDocumentRestored() void Sheet::onRelabledDocument(const Document &document) { cells.renamedDocument(&document); + cells.purgeTouched(); } void Sheet::onRenamedDocument(const Document &document) { } -void Sheet::observeDocument(const std::string & docName) +void Sheet::observeDocument(Document * document) { - ObserverMap::const_iterator it = observers.find(docName); + ObserverMap::const_iterator it = observers.find(document->getName()); + if (it != observers.end()) { // An observer already exists, increase reference counter for it it->second->ref(); } else { // Create a new observer - SheetObserver * observer = new SheetObserver(GetApplication().getDocument(docName.c_str()), &cells); + SheetObserver * observer = new SheetObserver(document, &cells); - observers[docName] = observer; + observers[document->getName()] = observer; } } diff --git a/src/Mod/Spreadsheet/App/Sheet.h b/src/Mod/Spreadsheet/App/Sheet.h index aacecf015..0bde46c55 100644 --- a/src/Mod/Spreadsheet/App/Sheet.h +++ b/src/Mod/Spreadsheet/App/Sheet.h @@ -202,7 +202,7 @@ public: } //@} - void observeDocument(const std::string &docName); + void observeDocument(App::Document *document); protected: