[TechDraw] prevent crash where user duplicates page without also duplicating dependencies
This commit is contained in:
@@ -239,6 +239,26 @@ void DrawView::onDocumentRestored()
|
||||
handleXYLock();
|
||||
DrawView::execute();
|
||||
}
|
||||
/**
|
||||
* @brief DrawView::countParentPages
|
||||
* Fixes a crash in TechDraw when user creates duplicate page without dependencies
|
||||
* In fixOrphans() we check how many parent pages an object has before deleting
|
||||
* in case it is also a child of another duplicate page
|
||||
* @return
|
||||
*/
|
||||
int DrawView::countParentPages() const
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
std::vector<App::DocumentObject*> parent = getInList();
|
||||
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
|
||||
//page = static_cast<TechDraw::DrawPage *>(*it);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
DrawPage* DrawView::findParentPage() const
|
||||
{
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
virtual PyObject *getPyObject(void) override;
|
||||
|
||||
virtual DrawPage* findParentPage() const;
|
||||
virtual int countParentPages() const;
|
||||
virtual QRectF getRect() const; //must be overridden by derived class
|
||||
virtual double autoScale(void) const;
|
||||
virtual double autoScale(double w, double h) const;
|
||||
|
||||
@@ -481,7 +481,11 @@ void MDIViewPage::fixOrphans(bool force)
|
||||
m_view->removeQView(qv);
|
||||
} else {
|
||||
TechDraw::DrawPage* pp = qv->getViewObject()->findParentPage();
|
||||
if (thisPage != pp) {
|
||||
/** avoid crash where a view might have more than one parent page
|
||||
* if the user duplicated the page without duplicating dependencies
|
||||
*/
|
||||
int numParentPages = qv->getViewObject()->countParentPages();
|
||||
if (thisPage != pp && numParentPages == 1) {
|
||||
m_view->removeQView(qv);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user