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:
André Caldas
2023-10-21 21:42:35 -03:00
committed by Yorik van Havre
parent 7bee0fbde6
commit 89dbab9b0e
49 changed files with 229 additions and 233 deletions

View File

@@ -2120,7 +2120,7 @@ QMimeData * MainWindow::createMimeDataFromSelection () const
std::vector<App::DocumentObject*> sel;
std::set<App::DocumentObject*> objSet;
for(auto &s : Selection().getCompleteSelection()) {
if(s.pObject && s.pObject->getNameInDocument() && objSet.insert(s.pObject).second)
if(s.pObject && s.pObject->isAttachedToDocument() && objSet.insert(s.pObject).second)
sel.push_back(s.pObject);
}
if(sel.empty())