diff --git a/src/Gui/Icons/Std_SelectGroupContents.svg b/src/Gui/Icons/Std_SelectGroupContents.svg new file mode 100644 index 0000000000..7086e8c271 --- /dev/null +++ b/src/Gui/Icons/Std_SelectGroupContents.svg @@ -0,0 +1,450 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Mon Oct 10 13:44:52 2011 +0000 + + + [wmayer] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + FreeCAD/src/Mod/Draft/Resources/icons/Draft_SelectGroup.svg + https://www.freecad.org/wiki/index.php?title=Artwork + + + [agryson] Alexander Gryson + + + + + hierarchy + group + selection + tree + + + A hierarchical tree structure with two blue child elements of a white parent element, both of which are surrounded by the same dotted box + + + + diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 86f5c4d0f9..17d760da4d 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -199,6 +199,7 @@ Std_DockOverlayToggleTop.svg Std_DuplicateSelection.svg Std_Export.svg + Std_SelectGroupContents.svg Std_HideObjects.svg Std_HideSelection.svg Std_Import.svg diff --git a/src/Gui/ViewProviderDocumentObjectGroup.cpp b/src/Gui/ViewProviderDocumentObjectGroup.cpp index 59ae34965c..fbbc08056e 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.cpp +++ b/src/Gui/ViewProviderDocumentObjectGroup.cpp @@ -23,6 +23,12 @@ #include "PreCompiled.h" #include +#include +#include +#include +#include +#include +#include #include "ViewProviderDocumentObjectGroup.h" #include "Application.h" @@ -82,6 +88,51 @@ void ViewProviderDocumentObjectGroup::getViewProviders(std::vectorgetObject(); + + // This action is only for plain "Std::Group" objects, not for derived types like "Draft::Layer". + // We check the TypeId to ensure we don't add this menu to other group-like objects. + if (obj->getTypeId() == App::DocumentObjectGroup::getClassTypeId()) { + auto* group = static_cast(obj); + + // Only add the action if the group actually contains objects. + if (group && !group->getObjects().empty()) { + // Add the custom action. + QIcon icon = BitmapFactory().iconFromTheme("Std_SelectGroupContents"); + QAction* selectAction = new QAction(icon, QObject::tr("Select group contents"), menu); + selectAction->setToolTip(QObject::tr("Selects all objects that are children of this group.")); + + // Connect the action's triggered signal to a lambda function that performs the selection. + QObject::connect(selectAction, &QAction::triggered, [group]() { + if (!group) return; + + // Use getAllChildren() to recursively select contents of subgroups. + const auto& children = group->getAllChildren(); + + if (!children.empty()) { + const char* docName = group->getDocument()->getName(); + + Gui::Selection().clearSelection(docName); + + // Add each child object to the selection individually. + for (App::DocumentObject* child : children) { + if (child && child->isAttachedToDocument()) { + Gui::Selection().addSelection(docName, child->getNameInDocument()); + } + } + } + }); + + // Insert the action at the top of the menu for better visibility. + menu->insertAction(menu->actions().isEmpty() ? nullptr : menu->actions().first(), selectAction); + } + } +} // Python feature ----------------------------------------------------------------------- diff --git a/src/Gui/ViewProviderDocumentObjectGroup.h b/src/Gui/ViewProviderDocumentObjectGroup.h index ef640546c9..42a91abdcd 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.h +++ b/src/Gui/ViewProviderDocumentObjectGroup.h @@ -48,6 +48,9 @@ public: /// deliver the icon shown in the tree view QIcon getIcon() const override; + // Set up the context menu with the supported edit modes + void setupContextMenu(QMenu* menu, QObject* receiver, const char* member) override; + /* Check whether the object accept reordering of its children during drop.*/ bool acceptReorderingObjects() const override { return true; };