Sketcher: Clear selection on selected geometry when hiding

When a geometry element is selected and then hidden using the visibility
checkbox in the Elements panel, it remains in the selection.
Subsequently, if another geometry element is selected and deleted, both
the visible element AND the hidden element are deleted.

Root cause of that is basically that `changeLayer()` functions change
the geometry's visual layer, but never clear the geometry from
`Gui::Selection()`.

So, this patch adds the handling to collect every sub-element name of
the hidden geometry and then formats it and calls remove selection on
the geometry during layer change transaction.
This commit is contained in:
tetektoza
2025-11-03 00:00:53 +01:00
committed by Chris Hennes
parent ffea3da872
commit 6bed2e663e

View File

@@ -34,6 +34,8 @@
#include <boost/core/ignore_unused.hpp>
#include <limits>
#include <fmt/format.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
@@ -646,6 +648,11 @@ void ElementView::changeLayer(ElementItem* item, int layer)
return;
}
const int geoid = item->ElementNbr;
const int startingVertex = item->StartingVertex;
const int midVertex = item->MidVertex;
const int endVertex = item->EndVertex;
doc->openTransaction("Geometry Layer Change");
auto sketchObject = item->getSketchObject();
@@ -653,8 +660,6 @@ void ElementView::changeLayer(ElementItem* item, int layer)
auto geometry = sketchObject->Geometry.getValues();
auto newGeometry(geometry);
auto geoid = item->ElementNbr;
// currently only internal geometry can be changed from one layer to another
if (geoid >= 0) {
auto currentLayer = getSafeGeomLayerId(geometry[geoid]);
@@ -677,6 +682,28 @@ void ElementView::changeLayer(ElementItem* item, int layer)
}
doc->commitTransaction();
if (layer == static_cast<int>(ElementItem::Layer::Hidden) && geoid >= 0) {
const std::string docName = sketchObject->getDocument()->getName();
const std::string objName = sketchObject->getNameInDocument();
auto deselect = [&](const std::string& name) {
const std::string convertedName = sketchObject->convertSubName(name);
Gui::Selection().rmvSelection(docName.c_str(), objName.c_str(), convertedName.c_str());
};
deselect(fmt::format("Edge{}", geoid + 1));
if (startingVertex >= 0) {
deselect(fmt::format("Vertex{}", startingVertex + 1));
}
if (midVertex >= 0) {
deselect(fmt::format("Vertex{}", midVertex + 1));
}
if (endVertex >= 0) {
deselect(fmt::format("Vertex{}", endVertex + 1));
}
}
}
void ElementView::contextMenuEvent(QContextMenuEvent* event)