diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp index 2f97d31617c6..dc5d11d0746b 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -45,7 +45,17 @@ TaskFeatureParameters::TaskFeatureParameters(PartDesignGui::ViewProvider *vp, QW const std::string& pixmapname, const QString& parname) : TaskBox(Gui::BitmapFactory().pixmap(pixmapname.c_str()),parname,true, parent), vp(vp), blockUpdate(false) -{ } +{ + Gui::Document* doc = vp->getDocument(); + this->attachDocument(doc); + this->enableNotifications(DocumentObserver::Delete); +} + +void TaskFeatureParameters::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + if (this->vp == &Obj) + this->vp = nullptr; +} void TaskFeatureParameters::onUpdateView(bool on) { diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h index d1a4cf6095ca..dcc51f0f0fca 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h @@ -26,25 +26,27 @@ #include #include +#include #include "ViewProvider.h" namespace PartDesignGui { /// Convenience class to collect common methods for all SketchBased features -class TaskFeatureParameters : public Gui::TaskView::TaskBox +class TaskFeatureParameters : public Gui::TaskView::TaskBox, + public Gui::DocumentObserver { Q_OBJECT public: TaskFeatureParameters(PartDesignGui::ViewProvider* vp, QWidget *parent, const std::string& pixmapname, const QString& parname); - virtual ~TaskFeatureParameters() {}; + virtual ~TaskFeatureParameters() {} /// save field history - virtual void saveHistory(void) {}; + virtual void saveHistory(void) {} /// apply changes made in the parameters input to the model via commands - virtual void apply() {}; + virtual void apply() {} void recomputeFeature(); @@ -52,6 +54,10 @@ protected Q_SLOTS: // TODO Add update view to all dialogs (2015-12-05, Fat-Zer) void onUpdateView(bool on); +private: + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); + protected: PartDesignGui::ViewProvider *vp; /// Lock updateUI(), applying changes to the underlying feature and calling recomputeFeature() diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index f82d505911c9..ff0fe28a9b51 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -361,8 +361,8 @@ bool TaskRevolutionParameters::getReversed(void) const TaskRevolutionParameters::~TaskRevolutionParameters() { //hide the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf ( vp->getObject() ); - if ( body ) { + PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; + if (body) { try { App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; @@ -375,7 +375,7 @@ TaskRevolutionParameters::~TaskRevolutionParameters() delete ui; - for(size_t i = 0 ; i < axesInList.size() ; i++ ){ + for (size_t i = 0; i < axesInList.size(); i++) { delete axesInList[i]; } }