Delete DPGI's when parent DPG deleted
Ensure Gui/QGIVxx is removed when App/DVxxxx is deleted
This commit is contained in:
@@ -176,7 +176,9 @@ void DrawProjGroup::onChanged(const App::Property* prop)
|
||||
TechDraw::DrawPage *page = getPage();
|
||||
if (!isRestoring() && page) {
|
||||
if ( prop == &Views ) {
|
||||
recompute();
|
||||
if (!isDeleting()) {
|
||||
recompute();
|
||||
}
|
||||
} else if (prop == &Scale) {
|
||||
updateChildren(Scale.getValue());
|
||||
//resetPositions();
|
||||
@@ -808,7 +810,9 @@ TechDraw::DrawProjGroupItem* DrawProjGroup::getAnchor(void)
|
||||
App::DocumentObject* docObj = Anchor.getValue();
|
||||
if (docObj == nullptr) {
|
||||
//explode! DPG w/o anchor
|
||||
Base::Console().Error("Error - DPG::getAnchor - DPG has no Anchor!!!\n");
|
||||
if (!isDeleting()) {
|
||||
Base::Console().Error("Error - DPG::getAnchor - DPG has no Anchor!!!\n");
|
||||
}
|
||||
} else {
|
||||
result = static_cast<DrawProjGroupItem*>(docObj);
|
||||
}
|
||||
|
||||
@@ -164,13 +164,15 @@ void DrawProjGroupItem::unsetupObject()
|
||||
{
|
||||
if (getGroup() != nullptr) {
|
||||
if (getGroup()->hasProjection(Type.getValueAsString()) ) {
|
||||
if (getGroup()->getAnchor() == this) {
|
||||
if ((getGroup()->getAnchor() == this) &&
|
||||
!getGroup()->isDeleting() ) {
|
||||
Base::Console().Warning("Warning - DPG (%s/%s) may be corrupt - Anchor deleted\n",
|
||||
getGroup()->getNameInDocument(),getGroup()->Label.getValue());
|
||||
getGroup()->Anchor.setValue(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
DrawViewPart::unsetupObject();
|
||||
}
|
||||
|
||||
PyObject *DrawProjGroupItem::getPyObject(void)
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
@@ -42,6 +44,7 @@ PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView)
|
||||
|
||||
DrawViewCollection::DrawViewCollection()
|
||||
{
|
||||
nowDeleting = false;
|
||||
static const char *group = "Drawing view";
|
||||
ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view");
|
||||
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views");
|
||||
@@ -165,6 +168,26 @@ void DrawViewCollection::onChanged(const App::Property* prop)
|
||||
TechDraw::DrawView::onChanged(prop);
|
||||
}
|
||||
|
||||
void DrawViewCollection::unsetupObject()
|
||||
{
|
||||
nowDeleting = true;
|
||||
|
||||
// Remove the collection's views from document
|
||||
App::Document* doc = getDocument();
|
||||
std::string docName = doc->getName();
|
||||
|
||||
const std::vector<App::DocumentObject*> currViews = Views.getValues();
|
||||
std::vector<App::DocumentObject*> emptyViews;
|
||||
std::vector<App::DocumentObject*>::const_iterator it = currViews.begin();
|
||||
for (; it != currViews.end(); it++) {
|
||||
std::string viewName = (*it)->getNameInDocument();
|
||||
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
|
||||
docName.c_str(), viewName.c_str());
|
||||
}
|
||||
Views.setValues(emptyViews);
|
||||
}
|
||||
|
||||
|
||||
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
|
||||
{
|
||||
if (ScaleType.isValue("Page")) {
|
||||
|
||||
@@ -50,14 +50,13 @@ public:
|
||||
int addView(DrawView *view);
|
||||
int removeView(DrawView *view);
|
||||
void rebuildViewList(void);
|
||||
bool isDeleting(void) { return nowDeleting; }
|
||||
|
||||
int countChildren();
|
||||
/** @name methods overide Feature */
|
||||
//@{
|
||||
/// recalculate the Feature
|
||||
|
||||
virtual void onDocumentRestored();
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
//@}
|
||||
virtual void unsetupObject();
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
@@ -67,6 +66,7 @@ public:
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
bool nowDeleting;
|
||||
};
|
||||
|
||||
} //namespace TechDraw
|
||||
|
||||
Reference in New Issue
Block a user