* [TD]Allow non-shape views to have children (#20768) * Update src/Mod/TechDraw/App/DrawView.cpp Review comment Co-authored-by: Benjamin Nauck <benjamin@nauck.se> * Update src/Mod/TechDraw/App/DrawView.cpp review comment Co-authored-by: Benjamin Nauck <benjamin@nauck.se> * Update src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp review comment Co-authored-by: Benjamin Nauck <benjamin@nauck.se> * Update src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp review comment Co-authored-by: Benjamin Nauck <benjamin@nauck.se> --------- Co-authored-by: Benjamin Nauck <benjamin@nauck.se>
This commit is contained in:
@@ -439,6 +439,26 @@ DrawView *DrawView::claimParent() const
|
||||
return getCollection();
|
||||
}
|
||||
|
||||
//! return *unique* list of DrawView derived items which consider this DVP to be their 'owner'
|
||||
//! if a dimension has two references to this dvp, it will appear twice in the inlist, so we need to
|
||||
//! pick out duplicates.
|
||||
std::vector<DrawView*> DrawView::getUniqueChildren() const
|
||||
{
|
||||
std::vector<DrawView*> result;
|
||||
auto children = getInList();
|
||||
std::sort(children.begin(), children.end(), std::less<>());
|
||||
auto newEnd = std::unique(children.begin(), children.end());
|
||||
children.erase(newEnd, children.end());
|
||||
for (auto& child : children) {
|
||||
auto* childDV = freecad_cast<DrawView*>(child);
|
||||
if (childDV && childDV->claimParent() == this) {
|
||||
result.push_back(childDV);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
DrawViewClip* DrawView::getClipGroup()
|
||||
{
|
||||
for (auto* obj : getInList()) {
|
||||
|
||||
@@ -87,6 +87,7 @@ public:
|
||||
virtual DrawPage* findParentPage() const;
|
||||
virtual std::vector<DrawPage*> findAllParentPages() const;
|
||||
virtual DrawView *claimParent() const;
|
||||
std::vector<TechDraw::DrawView*> getUniqueChildren() const;
|
||||
|
||||
virtual int countParentPages() const;
|
||||
virtual QRectF getRect() const; //must be overridden by derived class
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawView.h>
|
||||
#include <Mod/TechDraw/App/DrawViewBalloon.h>
|
||||
#include <Mod/TechDraw/App/DrawViewDimension.h>
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
#include "ViewProviderDrawingView.h"
|
||||
@@ -477,3 +479,55 @@ TechDraw::DrawView* ViewProviderDrawingView::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawView*>(pcObject);
|
||||
}
|
||||
|
||||
|
||||
//! it can happen that child graphic items can lose their parent item if the
|
||||
//! the parent is deleted, then undo is invoked. The linkages on the App side are
|
||||
//! handled by the undo mechanism, but the QGraphicsScene parentage is not reset.
|
||||
void ViewProviderDrawingView::fixSceneDependencies()
|
||||
{
|
||||
Base::Console().Message("VPDV::fixSceneDependencies()\n");
|
||||
auto page = getViewProviderPage();
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto scene = page->getQGSPage();
|
||||
auto ourQView = getQView();
|
||||
|
||||
// this is the logic for items other than Dimensions and Balloons
|
||||
auto children = getViewObject()->getUniqueChildren();
|
||||
for (auto& child : children) {
|
||||
if (child->isDerivedFrom<DrawViewDimension>() ||
|
||||
child->isDerivedFrom<DrawViewBalloon>() ) {
|
||||
// these are handled by ViewProviderViewPart
|
||||
continue;
|
||||
}
|
||||
auto* childQView = scene->findQViewForDocObj(child);
|
||||
auto* childGraphicParent = scene->findParent(childQView);
|
||||
if (childGraphicParent != ourQView) {
|
||||
scene->addItemToParent(childQView, ourQView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderDrawingView::claimChildren() const
|
||||
{
|
||||
std::vector<App::DocumentObject*> temp;
|
||||
const std::vector<App::DocumentObject *> &potentialChildren = getViewObject()->getInList();
|
||||
try {
|
||||
for(auto& child : potentialChildren) {
|
||||
auto* view = freecad_cast<DrawView *>(child);
|
||||
if (view && view->claimParent() == getViewObject()) {
|
||||
temp.push_back(view);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
return {};
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,10 @@ public:
|
||||
|
||||
const char* whoAmI() const;
|
||||
|
||||
virtual void fixSceneDependencies();
|
||||
std::vector<App::DocumentObject*> claimChildren() const override;
|
||||
|
||||
|
||||
private:
|
||||
void multiParentPaint(std::vector<TechDraw::DrawPage*>& pages);
|
||||
void singleParentPaint(const TechDraw::DrawView* dv);
|
||||
|
||||
Reference in New Issue
Block a user