Skip to content

Commit

Permalink
App: Add temporaryDocument to DocumentObject
Browse files Browse the repository at this point in the history
This is used for detached DocumentObjects before they're attached to the document to support functionality that depends on a valid document
  • Loading branch information
hlorus committed Sep 29, 2024
1 parent 6e2cd4e commit 2a3978d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/App/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,7 +3388,7 @@ std::vector<DocumentObject *> Document::addObjects(const char* sType, const std:

void Document::addObject(DocumentObject* pcObject, const char* pObjectName)
{
if (pcObject->getDocument()) {
if (pcObject->isAttachedToDocument()) {
throw Base::RuntimeError("Document object is already added to a document");
}

Expand Down
8 changes: 8 additions & 0 deletions src/App/DocumentObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,23 @@ void DocumentObject::onLostLinkToObject(DocumentObject*)

App::Document *DocumentObject::getDocument() const
{
if (!_pDoc)
return _pTempDoc;
return _pDoc;
}

void DocumentObject::setDocument(App::Document* doc)
{
_pTempDoc = nullptr;
_pDoc=doc;
onSettingDocument();
}

void DocumentObject::setTemporaryDocument(App::Document* doc)
{
_pTempDoc = doc;
}

bool DocumentObject::removeDynamicProperty(const char* name)
{
if (!_pDoc || testStatus(ObjectStatus::Destroy))
Expand Down
5 changes: 5 additions & 0 deletions src/App/DocumentObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class AppExport DocumentObject: public App::TransactionalObject
const char* detachFromDocument() override;
/// gets the document in which this Object is handled
App::Document *getDocument() const;
/// sets the temporary document for detached objects which will be used as a fallback
void setTemporaryDocument(App::Document* doc);

/** Set the property touched -> changed, cause recomputation in Update()
*/
Expand Down Expand Up @@ -671,6 +673,9 @@ class AppExport DocumentObject: public App::TransactionalObject
/// pointer to the document this object belongs to
App::Document* _pDoc{nullptr};

/// pointer to the temporary document for detached objects
App::Document* _pTempDoc{nullptr};

/// Old label; used for renaming expressions
std::string oldLabel;

Expand Down

0 comments on commit 2a3978d

Please sign in to comment.