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
@@ -591,7 +591,7 @@ std::string Command::getObjectCmd(const char *Name, const App::Document *doc,
|
||||
std::string Command::getObjectCmd(const App::DocumentObject *obj,
|
||||
const char *prefix, const char *postfix, bool gui)
|
||||
{
|
||||
if(!obj || !obj->getNameInDocument())
|
||||
if(!obj || !obj->isAttachedToDocument())
|
||||
return {"None"};
|
||||
return getObjectCmd(obj->getNameInDocument(), obj->getDocument(), prefix, postfix,gui);
|
||||
}
|
||||
@@ -782,7 +782,7 @@ void Command::_copyVisual(const char *file, int line, const char* to, const char
|
||||
|
||||
void Command::_copyVisual(const char *file, int line, const App::DocumentObject *to, const char* attr_to, const App::DocumentObject *from, const char *attr_from)
|
||||
{
|
||||
if(!from || !from->getNameInDocument() || !to || !to->getNameInDocument())
|
||||
if(!from || !from->isAttachedToDocument() || !to || !to->isAttachedToDocument())
|
||||
return;
|
||||
static std::map<std::string,std::string> attrMap = {
|
||||
{"ShapeColor","ShapeMaterial.DiffuseColor"},
|
||||
|
||||
Reference in New Issue
Block a user