[TD] handle object deletions better

see https://forum.freecadweb.org/viewtopic.php?p=366902#p366902
This commit is contained in:
donovaly
2020-03-03 03:54:08 +01:00
committed by WandererFan
parent b25ca7194c
commit def5159c38
10 changed files with 175 additions and 7 deletions

View File

@@ -27,6 +27,8 @@
# endif
# include <QAction>
# include <QMenu>
# include <QMessageBox>
# include <QTextStream>
#endif
#include <Base/Console.h>
@@ -48,7 +50,6 @@
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include "TaskProjGroup.h"
#include "ViewProviderProjGroup.h"
@@ -146,6 +147,45 @@ bool ViewProviderProjGroup::doubleClicked(void)
return true;
}
bool ViewProviderProjGroup::onDelete(const std::vector<std::string> &)
{
// warn the user if the ProjGroup is not empty
// check if there are items in the group
auto objs = claimChildren();
if (!objs.empty())
{
// generate dialog
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete",
"The projection group is not empty, therefore\n the following referencing objects might be lost.\n\n"
"Are you sure you want to continue?\n");
for (auto ObjIterator : objs)
bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue());
// show and evaluate 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 ViewProviderProjGroup::canDelete(App::DocumentObject *obj) const
{
// deletions of views from a ProjGroup 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;
}
std::vector<App::DocumentObject*> ViewProviderProjGroup::claimChildren(void) const
{
// Collect any child fields