[TD]fix multiselect handling of non-geometry objects

This commit is contained in:
wandererfan
2024-07-06 08:44:36 -04:00
committed by WandererFan
parent 94940f950b
commit 1b2707f00a
3 changed files with 42 additions and 19 deletions

View File

@@ -775,7 +775,7 @@ void MDIViewPage::sceneSelectionChanged()
else {
for (auto& sel : treeSel) {
// unselect the stored items
removeSelFromTreeSel(sceneSel, sel);
removeUnselectedTreeSelection(sceneSel, sel);
}
for (auto* item : sceneSel) {
@@ -820,7 +820,6 @@ void MDIViewPage::setTreeToSceneSelect()
}
else if (dynamic_cast<QGIDatumLabel*>(scene) || dynamic_cast<QGMText*>(scene)) {
if (!obj_name) {//can happen during undo/redo if Dim is selected???
//Base::Console().Log("INFO - MDIVP::sceneSelectionChanged - dimObj name is null!\n");
continue;
}
@@ -912,19 +911,43 @@ void MDIViewPage::addSceneItemToTreeSel(QGraphicsItem* sn, [[maybe_unused]]std::
}
}
// remove core selection if scene is not selected anymore
void MDIViewPage::removeSelFromTreeSel(QList<QGraphicsItem*> sceneSel, Gui::SelectionObject& sel)
// remove tree selection if it is no longer selected in the scene
void MDIViewPage::removeUnselectedTreeSelection(QList<QGraphicsItem*> sceneSelectedItems,
Gui::SelectionObject& treeSelection)
{
std::string selDocName = sel.getDocName();
App::DocumentObject* selObj = sel.getObject();
std::string selDocName = treeSelection.getDocName();
App::DocumentObject* selObj = treeSelection.getObject();
for (auto& sub : sel.getSubNames()) {
bool found = false;
for (auto& sn : sceneSel) {
auto* itemView = dynamic_cast<QGIView*>(sn);
// If the selected item is not a geometry item (vertex/edge/face) then the
// loop on subnames below will not handle the item and it will not be removed.
if (treeSelection.getSubNames().empty()) {
bool matchFound{false};
for (auto& sceneItem : sceneSelectedItems) {
auto* itemView = dynamic_cast<QGIView*>(sceneItem);
if (!itemView) {
auto* parent = dynamic_cast<QGIView*>(sn->parentItem());
continue;
}
auto itemFeature = itemView->getViewObject();
auto itemDocName = itemFeature->getDocument()->getName();
if (selDocName == itemDocName && selObj == itemFeature) {
matchFound = true;
break;
}
}
if (!matchFound) {
Gui::Selection().rmvSelection(treeSelection.getDocName(), treeSelection.getObject()->getNameInDocument());
}
return;
}
for (auto& sub : treeSelection.getSubNames()) {
bool found = false;
for (auto& sceneItem : sceneSelectedItems) {
auto* itemView = dynamic_cast<QGIView*>(sceneItem);
if (!itemView) {
auto* parent = dynamic_cast<QGIView*>(sceneItem->parentItem());
if (!parent) {
// neither sceneItem or its parent are Views
continue;
}
TechDraw::DrawView* viewObj = parent->getViewObject();
@@ -936,11 +959,11 @@ void MDIViewPage::removeSelFromTreeSel(QList<QGraphicsItem*> sceneSel, Gui::Sele
const char* obj_name = viewObj->getNameInDocument();
std::string sub_name;
if (dynamic_cast<QGIEdge*>(sn) || dynamic_cast<QGIVertex*>(sn) || dynamic_cast<QGIFace*>(sn)) {
sub_name = getSceneSubName(sn);
if (dynamic_cast<QGIEdge*>(sceneItem) || dynamic_cast<QGIVertex*>(sceneItem) || dynamic_cast<QGIFace*>(sceneItem)) {
sub_name = getSceneSubName(sceneItem);
}
else if (dynamic_cast<QGIDatumLabel*>(sn) || dynamic_cast<QGMText*>(sn)) {
else if (dynamic_cast<QGIDatumLabel*>(sceneItem) || dynamic_cast<QGMText*>(sceneItem)) {
if (!obj_name) {//can happen during undo/redo if Dim is selected???
continue;
}
@@ -967,7 +990,7 @@ void MDIViewPage::removeSelFromTreeSel(QList<QGraphicsItem*> sceneSel, Gui::Sele
}
}
if (!found) {
Gui::Selection().rmvSelection(sel.getDocName(), sel.getObject()->getNameInDocument(), sub.c_str());
Gui::Selection().rmvSelection(treeSelection.getDocName(), treeSelection.getObject()->getNameInDocument());
}
}
}

View File

@@ -131,7 +131,7 @@ protected:
bool compareSelections(std::vector<Gui::SelectionObject> treeSel, QList<QGraphicsItem*> sceneSel);
void addSceneItemToTreeSel(QGraphicsItem* sceneItem, std::vector<Gui::SelectionObject> treeSel);
void removeSelFromTreeSel(QList<QGraphicsItem*> sceneSel, Gui::SelectionObject& sel);
void removeUnselectedTreeSelection(QList<QGraphicsItem*> sceneSel, Gui::SelectionObject& treeSelection);
std::string getSceneSubName(QGraphicsItem* scene);
void setTreeToSceneSelect();
void sceneSelectionManager();

View File

@@ -126,9 +126,7 @@ void QGSPage::mousePressEvent(QGraphicsSceneMouseEvent * event)
itemUnderMouse->type() == QGISVGTemplateType ||
itemUnderMouse->type() == MysteryType) {
// click without item clears selection
for (auto& item : selectedItems()) {
item->setSelected(false);
}
Gui::Selection().clearSelection();
QGraphicsScene::mousePressEvent(event);
return;
}
@@ -149,6 +147,8 @@ void QGSPage::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
QGraphicsScene::mouseReleaseEvent(event);
// what does this do? the event has already been propagated so this will have
// no effect?
event->setModifiers(originalModifiers);
}