diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 98000cab2e..c6e112b455 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -366,8 +366,13 @@ std::vector DrawPage::getViews() const std::vector views = Views.getValues(); std::vector allViews; for (auto& v : views) { + bool addChildren = false; + if (v->isDerivedFrom()) { + // In the case of links, child object of the view need to be added since + // they are not in the page Views property. v = static_cast(v)->getLinkedObject(); + addChildren = true; } if (!v->isDerivedFrom()) { @@ -375,6 +380,14 @@ std::vector DrawPage::getViews() const } allViews.push_back(v); + + if (addChildren) { + for (auto* dep : v->getInList()) { + if (dep && dep->isDerivedFrom()) { + allViews.push_back(dep); + } + } + } } return allViews; } diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 99c1b4c278..6a83d5296f 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -385,16 +385,16 @@ std::vector DrawView::findAllParentPages() const { std::vector pages; - for (auto parent : getInList()) { - if (parent->isDerivedFrom()) { - for (auto& linkParent : parent->getInList()) { - if (linkParent->isDerivedFrom() - || linkParent->isDerivedFrom()) { - parent = linkParent; - break; - } - } - } + for (auto parent : getInList()) { + if (parent->isDerivedFrom()) { + for (auto& linkParent : parent->getInList()) { + if (linkParent->isDerivedFrom() + || linkParent->isDerivedFrom()) { + parent = linkParent; + break; + } + } + } if (parent->isDerivedFrom()) { pages.emplace_back(static_cast(parent)); @@ -415,9 +415,8 @@ std::vector DrawView::findAllParentPages() const bool DrawView::isInClip() { - std::vector parent = getInList(); - for (std::vector::iterator it = parent.begin(); it != parent.end(); ++it) { - if ((*it)->isDerivedFrom()) { + for (auto* parent : getInList()) { + if (parent->isDerivedFrom()) { return true; } } @@ -440,14 +439,9 @@ DrawView *DrawView::claimParent() const DrawViewClip* DrawView::getClipGroup() { - std::vector parent = getInList(); - App::DocumentObject* obj = nullptr; - for (std::vector::iterator it = parent.begin(); it != parent.end(); ++it) { - if ((*it)->isDerivedFrom()) { - obj = (*it); - DrawViewClip* result = dynamic_cast(obj); - return result; - + for (auto* obj : getInList()) { + if (obj->isDerivedFrom()) { + return dynamic_cast(obj); } } return nullptr; @@ -455,14 +449,11 @@ DrawViewClip* DrawView::getClipGroup() DrawViewCollection *DrawView::getCollection() const { - std::vector parents = getInList(); - for (auto it = parents.begin(); it != parents.end(); ++it) { - auto parentCollection = dynamic_cast(*it); - if (parentCollection) { - return parentCollection; + for (auto* obj : getInList()) { + if (obj->isDerivedFrom()) { + return dynamic_cast(obj); } } - return nullptr; } diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp index e3b0a9b5aa..1dd2137116 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.cpp +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -112,7 +112,6 @@ void QGSPage::addChildrenToPage() // A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, // we'll have to make this recursive. -WF - std::vector childViews; for (auto* view : m_vpPage->getDrawPage()->getViews()) { attachView(view); auto* collect = dynamic_cast(view); @@ -833,7 +832,8 @@ void QGSPage::fixOrphans(bool force) } else { //DrawView exists in Document. Does it belong to this DrawPage? - int numParentPages = qv->getViewObject()->countParentPages(); + TechDraw::DrawView* viewObj = qv->getViewObject(); + int numParentPages = viewObj->countParentPages(); if (numParentPages == 0) { //DrawView does not belong to any DrawPage //remove QGItem from QGScene @@ -841,8 +841,16 @@ void QGSPage::fixOrphans(bool force) } else if (numParentPages == 1) { //Does DrawView belong to this DrawPage? - TechDraw::DrawPage* parentPage = qv->getViewObject()->findParentPage(); + TechDraw::DrawPage* parentPage = viewObj->findParentPage(); if (thisPage != parentPage) { + // The view could be a child of a link (ea Dimension). + TechDraw::DrawView* parentView = viewObj->claimParent(); + for (auto* v : thisPage->getViews()) { + if (v == parentView) { + continue; + } + } + //DrawView does not belong to this DrawPage //remove QGItem from QGScene removeQView(qv); diff --git a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp index 548017d8c4..1e6ba9b674 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp @@ -129,25 +129,35 @@ void ViewProviderPageExtension::dropObject(App::DocumentObject* obj) } if (obj->isDerivedFrom()) { auto* link = static_cast(obj); - if (!link->getLinkedObject()->isDerivedFrom()) { + obj = link->getLinkedObject(); + if (!obj->isDerivedFrom()) { return; } - TechDraw::DrawPage* page = nullptr; - for (auto& parent : obj->getInListRecursive()) { - if (parent->isDerivedFrom()) { - page = static_cast(parent); + std::vector deps; + for (auto& inObj : obj->getInList()) { + if (inObj && inObj->isDerivedFrom()) { + deps.push_back(inObj); } + } - if (page) { - break; + TechDraw::DrawPage* page = nullptr; + for (auto& inObj : link->getInList()) { + if (inObj->isDerivedFrom()) { + page = static_cast(inObj); } } if (page) { - page->removeView(obj); + for (auto* dep : deps) { + page->removeView(dep); + } + page->removeView(link); } - getViewProviderPage()->getDrawPage()->addView(obj); + getViewProviderPage()->getDrawPage()->addView(link, false); + for (auto* dep : deps) { + getViewProviderPage()->getDrawPage()->addView(dep, false); + } return; }