From d0cca96919746465e7eb0acba0709186863e4cc6 Mon Sep 17 00:00:00 2001
From: Furgo <148809153+furgo16@users.noreply.github.com>
Date: Mon, 28 Jul 2025 00:44:12 +0200
Subject: [PATCH] Gui: add 'Select group contents' context menu item (#22082)
* Gui: add 'Select group contents' context menu item
* Gui: remove dependency from Draft icon
---
src/Gui/Icons/Std_SelectGroupContents.svg | 450 ++++++++++++++++++++
src/Gui/Icons/resource.qrc | 1 +
src/Gui/ViewProviderDocumentObjectGroup.cpp | 51 +++
src/Gui/ViewProviderDocumentObjectGroup.h | 3 +
4 files changed, 505 insertions(+)
create mode 100644 src/Gui/Icons/Std_SelectGroupContents.svg
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 @@
+
+
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; };