Skip to content

Decide the drag into a group from the current node position - #579

Merged
paceholder merged 3 commits into
masterfrom
fix-group-drag-state
Dec 2, 2026
Merged

paceholder merged 3 commits into
masterfrom
fix-group-drag-state

Conversation

@paceholder

Copy link
Copy Markdown
Owner

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

Two bugs in the drag of a node over a node group (#537, item 2):

  1. A fast drag away from a group still joined it. A node that is dragged over a group, moved far away in one step and released joined the group anyway. The reset of the drag state ran only inside the loop over collidingItems(), so a move that left the group never reached it, and the release used the stale state.
  2. A crash when the group is deleted during the drag. _possibleGroup was a raw pointer that the release used after the group was deleted. The test for this crashed with SIGSEGV on the old code.

The node now checks on each move whether it still touches the group (as the box was before it grew to show the node), and the release always clears the state. _possibleGroup is a QPointer. _draggingIntoGroup is removed, because it duplicated the pointer. There is no new public function.

Three commits:

  1. The fix with three tests, and the migration page: it now lists as fixed in 3.x the group drag state, the group repaint loop (Fix the gaps in the change notifications of the scene and the model #575), two drags of the same node as two undo steps (Make each drag of a node one undo step #573), and the paste position of plain nodes (Fix the gaps in the change notifications of the scene and the model #575). These were still listed as open problems.
  2. A test for the resize handle: the box of a group follows a node that is resized with its handle. The group update in that branch of mouseMoveEvent (added in Fix the gaps in the change notifications of the scene and the model #575) had no test. The test fails when the call is removed.
  3. Documentation of MoveNodeCommand::beginMove() in the undo guide, which Make each drag of a node one undo step #573 added without a mention. The moves of one drag merge, a mouse press starts a new move, and code that pushes the command itself must call beginMove().

Testing

  • Qt version tested: 6.12 (offscreen). CI covers Qt 5 and MSVC.
  • Existing tests still pass: 118 test cases, 1069 assertions. The first commit also passes on its own (117 test cases).
  • Added tests for new functionality: "A node dragged over a group and released away from it stays out of the group" (3 checks failed on the old code), "... released on it joins the group" (guards the normal case), "A group deleted while a node is dragged over it is not used at the release" (crashed on the old code), and the resize handle test.
  • Docs built with Sphinx. No new warning.

Not tested: Qt 5, Linux, Windows, a real GPU window, an ASAN build.

Breaking changes?

No API change. Two private members of NodeGraphicsObject change type (a bool and a raw pointer become a QPointer). I measured that sizeof stays the same (16 bytes for both), so the layout of the class does not change. A class that derives from NodeGraphicsObject needs a rebuild.

Not in this PR

Issue #537 stays open. Item 3 (the offset of a pasted group, because the group item is always at (0,0)) needs a decision on what a paste position means for a group. GroupGraphicsObject::_possibleChild is still a raw pointer, and it dangles if a node is deleted while it is dragged over a group. I did not reproduce that case.

Related issue

See #537.

A node dragged over a group left the group only when a later move still
collided with the group. A move that took the node far away in one step
kept the old state, and the node joined the group at the release.

The node now checks on each move whether it still touches the group, and
the release always clears the drag state. The group is held in a QPointer,
so a group deleted during the drag is not used at the release.

See #537
The test drags the resize handle of a resizable node with an embedded
widget. The node belongs to a group. After the drag the box of the group
must still contain the larger node. This covers the updateGroupGeometry()
call in the resize branch of NodeGraphicsObject::mouseMoveEvent().
MoveNodeCommand::beginMove() was added without a mention in the undo guide. The guide now says that the moves of one drag merge, that a mouse press starts a new move, and that code which pushes the command itself must call beginMove(). The migration page narrows the warning about loadItems() with a paste position to pasted groups.
@paceholder
paceholder merged commit f7e6698 into master Dec 2, 2026
5 checks passed
@paceholder
paceholder deleted the fix-group-drag-state branch December 2, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant