mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 22:24:13 +02:00
Add grouping of folio items: Group and Ungroup (#1070)
Symbols, free texts, shapes and pictures can be grouped from the Edit menu, the selection's context menu or the command search. Clicking one member selects the group, so moving, copying and deleting act on all of it; Ctrl+click on a member deselects the group; a rubber band touching part of a group selects all of it when released. No default shortcut: Ctrl+G is "jump to element". A group is not an object in the scene. Each member keeps its place and carries the group's uuid (QGraphicsItem::data()), saved as a "group" attribute written only when set: a project without groups saves exactly as before, and older versions open a grouped one and ignore the groups. Re-parenting under a QGraphicsItemGroup would have made every member's position group-relative; ElementTextItemGroup already needs nine special cases for that. - Selection is completed on clicks and at the end of a rubber band, not on every selectionChanged(): export, search and Tab select items themselves and must not have groups pulled back in. - Project database: group_uuid on element, shape, independent_text and image, kept in step by projectDataBase::itemGroupChanged(). - Paste and folio duplication give each source group one new uuid. - Undo of Ungroup restores each item's exact group. Builds on #1065 (uuids and database rows for texts, shapes and images). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "qetgraphicsitem/diagramimageitem.h"
|
||||
#include "qetgraphicsitem/independenttextitem.h"
|
||||
#include "qetgraphicsitem/qetshapeitem.h"
|
||||
#include "itemgroups.h"
|
||||
#include "qetinformation.h"
|
||||
|
||||
/*
|
||||
@@ -833,6 +834,20 @@ void ElementsPanelWidget::duplicateDiagram()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Groups too: a group of the copy is its own, so selecting it
|
||||
// is the same on both folios but the database tells them apart.
|
||||
QHash<QUuid, QUuid> renewed_groups;
|
||||
for (QGraphicsItem *item : new_diagram->items()) {
|
||||
const QUuid source_group = ItemGroups::groupOf(item);
|
||||
if (source_group.isNull()) {
|
||||
continue;
|
||||
}
|
||||
if (!renewed_groups.contains(source_group)) {
|
||||
renewed_groups.insert(source_group, QUuid::createUuid());
|
||||
}
|
||||
new_diagram->setItemGroup(item, renewed_groups.value(source_group));
|
||||
}
|
||||
}
|
||||
|
||||
elements_panel->reload();
|
||||
|
||||
Reference in New Issue
Block a user