Avoids using getNameInDocument() to test if DocumentObject is attached to a Document.
This patch substitutes by isAttachedToDocument() (almost) everywhere where getNameInDocument() is used for this purpose. The very few places not touched by this patch demand a (just a little) less trivial change. When we change the returning type of getNameInDocument() to std::string, those places will be easily found, because they shall generate a compiler error (converting std::string to bool). Rationale: The fact that getNameInDocument() return nullptr to indicate that the object is not attached to a document is responsible for lots of bugs where the developer does not check for "nullptr". The idea is to eliminate all those uses of getNameInDocument() and, in the near future, make getNameInDocument() return always a valid std::string.
This commit is contained in:
committed by
Yorik van Havre
parent
7bee0fbde6
commit
89dbab9b0e
@@ -331,7 +331,7 @@ void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
|
||||
// save Object pointer
|
||||
pcObject = pcObj;
|
||||
|
||||
if(pcObj && pcObj->getNameInDocument() &&
|
||||
if(pcObj && pcObj->isAttachedToDocument() &&
|
||||
Visibility.getValue()!=pcObj->Visibility.getValue())
|
||||
pcObj->Visibility.setValue(Visibility.getValue());
|
||||
|
||||
@@ -519,14 +519,14 @@ bool ViewProviderDocumentObject::canDropObjectEx(App::DocumentObject* obj, App::
|
||||
int ViewProviderDocumentObject::replaceObject(
|
||||
App::DocumentObject *oldObj, App::DocumentObject *newObj)
|
||||
{
|
||||
if(!oldObj || !oldObj->getNameInDocument()
|
||||
|| !newObj || !newObj->getNameInDocument())
|
||||
if(!oldObj || !oldObj->isAttachedToDocument()
|
||||
|| !newObj || !newObj->isAttachedToDocument())
|
||||
{
|
||||
FC_THROWM(Base::RuntimeError,"Invalid object");
|
||||
}
|
||||
|
||||
auto obj = getObject();
|
||||
if(!obj || !obj->getNameInDocument())
|
||||
if(!obj || !obj->isAttachedToDocument())
|
||||
FC_THROWM(Base::RuntimeError,"View provider not attached");
|
||||
|
||||
int res = ViewProvider::replaceObject(oldObj,newObj);
|
||||
@@ -606,7 +606,7 @@ bool ViewProviderDocumentObject::getElementPicked(const SoPickedPoint *pp, std::
|
||||
if(!vp)
|
||||
return false;
|
||||
auto obj = vp->getObject();
|
||||
if(!obj || !obj->getNameInDocument())
|
||||
if(!obj || !obj->isAttachedToDocument())
|
||||
return false;
|
||||
std::ostringstream str;
|
||||
str << obj->getNameInDocument() << '.';
|
||||
@@ -635,7 +635,7 @@ bool ViewProviderDocumentObject::getDetailPath(const char *subname, SoFullPath *
|
||||
if(!dot)
|
||||
return false;
|
||||
auto obj = getObject();
|
||||
if(!obj || !obj->getNameInDocument())
|
||||
if(!obj || !obj->isAttachedToDocument())
|
||||
return false;
|
||||
auto sobj = obj->getSubObject(std::string(subname,dot-subname+1).c_str());
|
||||
if(!sobj)
|
||||
@@ -676,7 +676,7 @@ ViewProviderDocumentObject *ViewProviderDocumentObject::getLinkedViewProvider(
|
||||
{
|
||||
(void)subname;
|
||||
auto self = const_cast<ViewProviderDocumentObject*>(this);
|
||||
if(!pcObject || !pcObject->getNameInDocument())
|
||||
if(!pcObject || !pcObject->isAttachedToDocument())
|
||||
return self;
|
||||
auto linked = pcObject->getLinkedObject(recursive);
|
||||
if(!linked || linked == pcObject)
|
||||
|
||||
Reference in New Issue
Block a user