diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 3e132051b8..d1d7d249f1 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -39,12 +39,14 @@ # include # include +# include #endif #include #include #include #include +#include #include #include @@ -668,3 +670,42 @@ void ViewProviderFemPostObject::OnChange(Base::Subject< int >& /*rCaller*/, int bool ResetColorBarRange = false; WriteColorData(ResetColorBarRange); } + +bool ViewProviderFemPostObject::onDelete(const std::vector&) +{ + // warn the user if the object has childs + + auto objs = claimChildren(); + if (!objs.empty()) + { + // generate dialog + QString bodyMessage; + QTextStream bodyMessageStream(&bodyMessage); + bodyMessageStream << qApp->translate("Std_Delete", + "The page is not empty, therefore the\nfollowing referencing objects might be lost:"); + bodyMessageStream << '\n'; + for (auto ObjIterator : objs) + bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue()); + bodyMessageStream << "\n\n" << QObject::tr("Are you sure you want to continue?"); + // show and evaluate the dialog + int DialogResult = QMessageBox::warning(Gui::getMainWindow(), + qApp->translate("Std_Delete", "Object dependencies"), bodyMessage, + QMessageBox::Yes, QMessageBox::No); + if (DialogResult == QMessageBox::Yes) + return true; + else + return false; + } + else { + return true; + } +} + +bool ViewProviderFemPostObject::canDelete(App::DocumentObject* obj) const +{ + // deletions of objects from a FemPostObject don't necesarily destroy anything + // thus we can pass this action + // we can warn the user if necessary in the object's ViewProvider in the onDelete() function + Q_UNUSED(obj) + return true; +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index e4531c4842..d4b8d0eb62 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -98,6 +98,9 @@ public: //observer for the color bar virtual void OnChange(Base::Subject< int >& rCaller, int rcReason); + virtual bool onDelete(const std::vector&); + virtual bool canDelete(App::DocumentObject* obj) const; + /** @name Selection handling * This group of methods do the selection handling. * Here you can define how the selection for your ViewProvider