Files
qelectrotech-source-mirror/sources/itemgroups.h
T
ispyisail 6ed41bbfd0 Click again on a member of a selected group to pick it on its own
Clicking an item of a group selects the whole group (#1070). Clicking
again on one of its items is meant to select just that item, to edit it
on its own -- what discussion #1070 proposed -- but the second click
selected the whole group again: Qt left only the clicked item selected on
release, and the group completion pulled the others back in.

A press on a member of a group that is selected whole now notes that
member (ItemGroups::memberToPick(), which also finds the member when the
click lands on a symbol's own text). If the click ends without a drag and
Qt has left only that member selected, the selection stays so. A drag
still moves the whole group; Ctrl+click keeps its meaning; a group of one
is not picked from.

In the GUI, on two grouped texts: one click then Delete removes both
(master and this); click, click again, Delete removes only the clicked
text here, both on master; dragging after one click moves both texts by
the same amount on both. tst_itemgroups: 5 new checks; removing the
whole-group or the group-of-one condition fails one each. ctest 24/24.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:33:28 +13:00

64 lines
2.1 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ITEMGROUPS_H
#define ITEMGROUPS_H
#include <QList>
#include <QUuid>
class QDomElement;
class QGraphicsItem;
class QGraphicsScene;
/**
Groups of items on a folio (discussion #1070): symbols, free texts,
shapes and pictures that select, move, copy and delete together.
A group is not an object in the scene. Each member keeps its place and
carries the group's uuid, and selecting one member selects them all;
moving, copying and deleting then need nothing new, because they act on
the selection. Re-parenting the members under a QGraphicsItemGroup would
make every position group-relative, which every piece of code reading a
symbol's position would have to learn about.
This part knows nothing of Diagram, so it can be tested on a plain scene.
*/
namespace ItemGroups
{
/// QGraphicsItem::data() key holding an item's group uuid.
inline constexpr int data_key = 0x475250; // "GRP"
/// XML attribute holding it, on <element>, <input>, <shape> and <image>.
inline constexpr char xml_attribute[] = "group";
QUuid groupOf(const QGraphicsItem *item);
void setGroup(QGraphicsItem *item, const QUuid &group);
void write(QDomElement &xml, const QGraphicsItem *item);
QUuid read(const QDomElement &xml);
QGraphicsItem *groupedItem(QGraphicsItem *item);
QGraphicsItem *memberToPick(QGraphicsItem *hit);
bool completeSelection(QGraphicsScene *scene,
const QList<QGraphicsItem *> &previous,
bool toggling);
}
#endif // ITEMGROUPS_H