Does not rely on the pointervalue returned by getNameInDocument() to use as a DAG key.

In order to make getNameInDocument() always return a valid string,
we implement a getDagKey() method that shall be used instead of getNameInDocument()
when we want to use the pointer value as a "key" to identify the DocumentObject.
This commit is contained in:
André Caldas
2023-10-21 22:37:58 -03:00
committed by Chris Hennes
parent 500f3b6086
commit e6b5fd0a21
4 changed files with 14 additions and 3 deletions

View File

@@ -292,6 +292,15 @@ std::string DocumentObject::getFullLabel() const {
return name;
}
const char* DocumentObject::getDagKey() const
{
if(!pcNameInDocument)
{
return nullptr;
}
return pcNameInDocument->c_str();
}
const char *DocumentObject::getNameInDocument() const
{
// Note: It can happen that we query the internal name of an object even if it is not
@@ -808,7 +817,7 @@ DocumentObject *DocumentObject::getSubObject(const char *subname,
if(outList.size()!=_outListMap.size()) {
_outListMap.clear();
for(auto obj : outList)
_outListMap[obj->getNameInDocument()] = obj;
_outListMap[obj->getDagKey()] = obj;
}
auto it = _outListMap.find(name.c_str());
if(it != _outListMap.end())

View File

@@ -132,6 +132,8 @@ public:
DocumentObject();
~DocumentObject() override;
/// returns a value that uniquely identifies this DocumentObject.
const char* getDagKey() const;
/// returns the name which is set in the document for this object (not the name property!)
const char *getNameInDocument() const;
/// Return the object ID that is unique within its owner document

View File

@@ -468,7 +468,7 @@ void LinkBaseExtension::setOnChangeCopyObject(
}
}
const char *key = flags.testFlag(OnChangeCopyOptions::ApplyAll) ? "*" : parent->getNameInDocument();
const char *key = flags.testFlag(OnChangeCopyOptions::ApplyAll) ? "*" : parent->getDagKey();
if (external)
prop->setValue(key, exclude ? "" : "+");
else

View File

@@ -225,7 +225,7 @@ public:
}
const char *getLinkedName() const {
return pcLinked->getObject()->getNameInDocument();
return pcLinked->getObject()->getDagKey();
}
const char *getLinkedLabel() const {