Spreadsheet: Consistently use App::Document::Label as reference for document names when tracking dependencies.

This commit is contained in:
Eivind Kvedalen 2015-02-16 00:11:10 +01:00 committed by wmayer
parent 1f94a15869
commit 1b43ca109b
4 changed files with 22 additions and 15 deletions

View File

@ -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) void Path::renameDocument(const std::string &oldName, const std::string &newName)
{ {
if (documentNameSet && documentName == oldName) { if (documentName == oldName) {
documentName = newName; documentName = newName;
resolve(); resolve();
} }

View File

@ -800,9 +800,10 @@ void PropertySheet::addDependencies(CellAddress key)
while (i != expressionDeps.end()) { while (i != expressionDeps.end()) {
const Property * prop = (*i).getProperty(); const Property * prop = (*i).getProperty();
DocumentObject * docObj = prop ? freecad_dynamic_cast<DocumentObject>(prop->getContainer()) : 0; DocumentObject * docObj = prop ? freecad_dynamic_cast<DocumentObject>(prop->getContainer()) : 0;
Document * doc = docObj ? docObj->getDocument() : 0;
std::string docName = (*i).getDocumentName().getString(); std::string docName = doc ? doc->Label.getValue() : (*i).getDocumentName().getString();
std::string docObjName = docName + "#" + (prop ? docObj->getNameInDocument() : (*i).getDocumentObjectName().getString()); std::string docObjName = docName + "#" + (docObj ? docObj->getNameInDocument() : (*i).getDocumentObjectName().getString());
std::string propName = docObjName + "." + (*i).getPropertyName(); std::string propName = docObjName + "." + (*i).getPropertyName();
if (!prop) if (!prop)
@ -820,7 +821,8 @@ void PropertySheet::addDependencies(CellAddress key)
} }
// Observe document to trach changes to the property // Observe document to trach changes to the property
owner->observeDocument(docName); if (doc)
owner->observeDocument(doc);
// Insert into maps // Insert into maps
propertyNameToCellMap[propName].insert(key); propertyNameToCellMap[propName].insert(key);
@ -879,9 +881,12 @@ void PropertySheet::removeDependencies(CellAddress key)
assert(k != documentObjectToCellMap.end()); assert(k != documentObjectToCellMap.end());
k->second.erase(key); k->second.erase(key);
++j; ++j;
} }
cellToDocumentObjectMap.erase(i2); cellToDocumentObjectMap.erase(i2);
} }
@ -900,7 +905,7 @@ void PropertySheet::recomputeDependants(const Property *prop)
assert(name != 0); assert(name != 0);
if (owner && name) { if (owner && name) {
const char * docName = owner->getDocument()->getName(); const char * docName = owner->getDocument()->Label.getValue();
const char * nameInDoc = owner->getNameInDocument(); const char * nameInDoc = owner->getNameInDocument();
if (nameInDoc) { if (nameInDoc) {
@ -924,7 +929,7 @@ void PropertySheet::recomputeDependants(const Property *prop)
void PropertySheet::invalidateDependants(const DocumentObject *docObj) void PropertySheet::invalidateDependants(const DocumentObject *docObj)
{ {
const char * docName = docObj->getDocument()->getName(); const char * docName = docObj->getDocument()->Label.getValue();
const char * docObjName = docObj->getNameInDocument(); const char * docObjName = docObj->getNameInDocument();
// Touch to force recompute // Touch to force recompute
@ -995,7 +1000,7 @@ void PropertySheet::renamedDocument(const Document * doc)
void PropertySheet::recomputeDependants(const DocumentObject *docObj) void PropertySheet::recomputeDependants(const DocumentObject *docObj)
{ {
const char * docName = docObj->getDocument()->getName(); const char * docName = docObj->getDocument()->Label.getValue();
const char * docObjName = docObj->getNameInDocument(); const char * docObjName = docObj->getNameInDocument();
// Touch to force recompute // Touch to force recompute

View File

@ -659,7 +659,7 @@ const char *Sheet::getPropertyName(const Property *prop) const
void Sheet::recomputeCell(CellAddress p) void Sheet::recomputeCell(CellAddress p)
{ {
Cell * cell = cells.getValue(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 docObjName = std::string(getNameInDocument());
std::string name = docName + "#" + docObjName + "." + toAddress(p); std::string name = docName + "#" + docObjName + "." + toAddress(p);
@ -1036,7 +1036,7 @@ std::set<std::string> Sheet::dependsOn(CellAddress address) const
void Sheet::providesTo(CellAddress address, std::set<std::string> & result) const void Sheet::providesTo(CellAddress address, std::set<std::string> & result) const
{ {
const char * docName = getDocument()->getName(); const char * docName = getDocument()->Label.getValue();
const char * docObjName = getNameInDocument(); const char * docObjName = getNameInDocument();
std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address);
std::set<CellAddress> tmpResult = cells.getDeps(fullName); std::set<CellAddress> tmpResult = cells.getDeps(fullName);
@ -1047,7 +1047,7 @@ void Sheet::providesTo(CellAddress address, std::set<std::string> & result) cons
void Sheet::providesTo(CellAddress address, std::set<CellAddress> & result) const void Sheet::providesTo(CellAddress address, std::set<CellAddress> & result) const
{ {
const char * docName = getDocument()->getName(); const char * docName = getDocument()->Label.getValue();
const char * docObjName = getNameInDocument(); const char * docObjName = getNameInDocument();
std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + toAddress(address);
result = cells.getDeps(fullName); result = cells.getDeps(fullName);
@ -1062,23 +1062,25 @@ void Sheet::onDocumentRestored()
void Sheet::onRelabledDocument(const Document &document) void Sheet::onRelabledDocument(const Document &document)
{ {
cells.renamedDocument(&document); cells.renamedDocument(&document);
cells.purgeTouched();
} }
void Sheet::onRenamedDocument(const Document &document) 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()) { if (it != observers.end()) {
// An observer already exists, increase reference counter for it // An observer already exists, increase reference counter for it
it->second->ref(); it->second->ref();
} }
else { else {
// Create a new observer // 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;
} }
} }

View File

@ -202,7 +202,7 @@ public:
} }
//@} //@}
void observeDocument(const std::string &docName); void observeDocument(App::Document *document);
protected: protected: