From 2cda87f23a80339a0700841dcfbdcdb51ae1942f Mon Sep 17 00:00:00 2001 From: donovaly Date: Wed, 4 Mar 2020 02:14:25 +0100 Subject: [PATCH] ViewProviderProjGroup: handle the case that items have section or detail views that would be broken by the deletion --- .../TechDraw/Gui/ViewProviderProjGroup.cpp | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp index eb4273808c..0bdc5dfe59 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp @@ -49,6 +49,8 @@ #include #include +#include +#include #include "TaskProjGroup.h" #include "ViewProviderProjGroup.h" @@ -151,14 +153,50 @@ bool ViewProviderProjGroup::onDelete(const std::vector &) { // warn the user if the ProjGroup is not empty - // check if there are items in the group + QString bodyMessage; + QTextStream bodyMessageStream(&bodyMessage); + TechDraw::DrawProjGroupItem* Item = nullptr; + std::vector ViewList; + + // get the items in the group auto objs = claimChildren(); + + // iterate over all item to check which ones have a section or detail view + for (auto ObjectIterator : objs) { + // get item + Item = static_cast(ObjectIterator); + // get its section views + auto viewSection = Item->getSectionRefs(); + // add names to a list + if (!viewSection.empty()) { + for (auto SecIterator : viewSection) { + ViewList.push_back(SecIterator->Label.getValue()); + } + } + // get its detail views + auto viewDetail = Item->getDetailRefs(); + if (!viewDetail.empty()) { + for (auto DetIterator : viewDetail) { + ViewList.push_back(DetIterator->Label.getValue()); + } + } + } + + // if there are section or detail views we cannot delete because this would break them + if (!ViewList.empty()) { + bodyMessageStream << qApp->translate("Std_Delete", + "The group cannot be deleted because its items have the\n following section and detail views that would get broken:\n"); + for (auto ListIterator : ViewList) + bodyMessageStream << '\n' << QString::fromUtf8(ListIterator.c_str()); + QMessageBox::warning(Gui::getMainWindow(), + qApp->translate("Std_Delete", "Object dependencies"), bodyMessage, + QMessageBox::Ok); + return false; + } 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");