Fix the right-click menu offering Group again after grouping (#1144)

Group and Ungroup are enabled in slot_updateComplexActions(), which ran
only when the selection changed. Grouping, ungrouping and undoing either
leave the selection as it is, and so does right-clicking an item that is
already selected, so the actions kept the state from before. The
right-click menu hides disabled actions, so it went on showing Group on a
selection that was now one group (and Ungroup after ungrouping), and the
one that would work was not in the menu at all.

Diagram::setItemGroup() is the one place an item's group changes (group,
ungroup, undo, redo, paste), so it now emits itemGroupChanged() and the
editor refreshes its actions on it, beside the selectionChanged
connection.

Checked in the GUI on two free texts, saving after each step: right-click
> Group, right-click again, Ctrl+Z, right-click again. Before, the second
and third right-clicks offered Group again and did nothing (both saves
still grouped). After, they offered Ungroup and ungrouped (0 grouped
texts in both saves); Group, Ungroup, Group also round-trips.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 23:09:57 +13:00
parent cbbb9fd0ac
commit 1d816f432c
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -2279,6 +2279,7 @@ void Diagram::setItemGroup(QGraphicsItem *item, const QUuid &group)
if (m_project) {
m_project->dataBase()->itemGroupChanged(item);
}
emit itemGroupChanged();
}
/**
+4
View File
@@ -325,6 +325,10 @@ class Diagram : public QGraphicsScene
void diagramActivated();
void diagramInformationChanged();
/// Emitted by setItemGroup(): an item joined or left a group
/// without the selection changing (#1144)
void itemGroupChanged();
};
Q_DECLARE_METATYPE(Diagram *)
+6
View File
@@ -3185,6 +3185,12 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv)
this,
&QETDiagramEditor::selectionChanged,
Qt::DirectConnection);
//Grouping leaves the selection as it is, so without this Group
//and Ungroup would keep the state from before (#1144)
connect(dv->diagram(),
&Diagram::itemGroupChanged,
this,
&QETDiagramEditor::slot_updateComplexActions);
connect(dv, &DiagramView::modeChanged, this, &QETDiagramEditor::slot_updateModeActions);
connect(dv, &DiagramView::elementPlacementStarted, this, &QETDiagramEditor::rememberPlacedElement);
}