[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 @@
#ifndef _PreComp_
# include <QAction>
# include <QMenu>
# include <QMessageBox>
# include <QTextStream>
# include <QTimer>
#include <QList>
#include <QPointer>
@@ -191,11 +193,37 @@ void ViewProviderPage::updateData(const App::Property* prop)
Gui::ViewProviderDocumentObject::updateData(prop);
}
bool ViewProviderPage::onDelete(const std::vector<std::string> &items)
bool ViewProviderPage::onDelete(const std::vector<std::string> &)
{
bool rc = ViewProviderDocumentObject::onDelete(items);
removeMDIView();
return rc;
// warn the user if the Page 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 page is not empty, therefore the\n 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 the dialog
int DialogResult = QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Yes, QMessageBox::No);
if (DialogResult == QMessageBox::Yes) {
removeMDIView();
return true;
} else
return false;
}
else {
removeMDIView();
return true;
}
}
void ViewProviderPage::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
@@ -421,6 +449,16 @@ void ViewProviderPage::setGraphicsView(QGVPage* gv)
m_graphicsView = gv;
}
bool ViewProviderPage::canDelete(App::DocumentObject *obj) const
{
// deletions from a page don't necesarily destroy anything
// thus we can pass this action
// if an object could break something, like e.g. the template object
// its ViewProvider handles this in the onDelete() function
Q_UNUSED(obj)
return true;
}
//! Redo the whole visual page
void ViewProviderPage::onGuiRepaint(const TechDraw::DrawPage* dp)
{