Skip to content

Synchronize graphical node moves with model positions - #533

Open
Rajvira10 wants to merge 1 commit into
paceholder:masterfrom
Rajvira10:fix/synchronize-node-positions
Open

Rajvira10 wants to merge 1 commit into
paceholder:masterfrom
Rajvira10:fix/synchronize-node-positions

Conversation

@Rajvira10

Copy link
Copy Markdown

Type of change

  • Bug fix

Description

Moving nodes updates their graphics without storing the new model coordinates or emitting the completed-move signal. Synchronize graphical position changes with the model, avoiding duplicate updates when the model initiates the move.

Testing

Qt version tested: 6.11.2. Eleven regression assertions fail on unchanged upstream; 37 selected tests (448 assertions) pass after the fix. The library, all configured examples and changed-code formatting checks pass.

  • Added tests for dragging, grouped moves, save/load and notification counts.
  • Full existing suite: remaining UI/stress tests and Qt 5 were not run.

Breaking changes?

None.

Related issue

Fixes #525. Fixes #526.

@Rajvira10
Rajvira10 marked this pull request as ready for review October 16, 2026 20:26

@StDarton StDarton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look at the code, but tested locally - the bug is completely gone. Now nodes positions save as it should. This was such a frustrating issue, let's merge this quickly!

@paceholder

Copy link
Copy Markdown
Owner

Thank you for the PR, and for the tests. Thanks also to @StDarton for trying it.

I fixed the same bug a bit differently, so I will not merge this one. In QtNodes the model is the source of truth and the scene follows its signals. Before 3.1.4 the mouse move pushed a MoveNodeCommand, and the command changed the model. The node group commit broke that. I restored it, instead of syncing the graphics position back into the model. This also keeps undo and redo of moves working.

The fix is ready and has tests that check model positions, nodeMoved and undo. It will be in the next 3.x patch release. I will close this PR when the release is out. #525 and #526 will be closed then too.

Your tests for dragging and for save and load are useful. If you like, open a new PR with only the tests on top of the release. I would be happy to look at it.

paceholder added a commit that referenced this pull request Nov 22, 2026
Since the node group commit, dragging a node let Qt move the item and
never told the model, so NodeRole::Position stayed at the old value.
Saved positions, setNodeData overrides and nodeMoved saw stale data, and
a drag was not undoable.

Restore the original flow: mouseMoveEvent pushes a MoveNodeCommand and
the scene follows the model signals. MoveNodeCommand gets a constructor
taking explicit node ids, so group dragging can move the group's nodes
plus any selected nodes. GroupGraphicsObject::moveNodes writes to the
model without an undo command.

Remove the branch that moved the nodes of a locked group without an undo
command. A locked group is dragged through its own item.

Reset the drag flag of the scene on mouse press. A position set from code
or by undo no longer makes the next plain click emit nodeMoved.

Export GroupGraphicsObject. NodeGroup::groupGraphicsObject() returns it
in the public API, and the tests call its lock(). Without the export, the
tests do not link on a Windows shared build.

Add tests that drag a node and a group with simulated mouse events and
check model positions, the nodeMoved signal and undo/redo.

Fixes #525
Fixes #526
Refs #533
paceholder added a commit that referenced this pull request Nov 22, 2026
Since the node group commit, dragging a node let Qt move the item and
never told the model, so NodeRole::Position stayed at the old value.
Saved positions, setNodeData overrides and nodeMoved saw stale data, and
a drag was not undoable.

Restore the original flow: mouseMoveEvent pushes a MoveNodeCommand and
the scene follows the model signals. MoveNodeCommand gets a constructor
taking explicit node ids, so group dragging can move the group's nodes
plus any selected nodes. GroupGraphicsObject::moveNodes writes to the
model without an undo command.

Remove the branch that moved the nodes of a locked group without an undo
command. A locked group is dragged through its own item.

Reset the drag flag of the scene on mouse press. A position set from code
or by undo no longer makes the next plain click emit nodeMoved.

Add tests that drag a node and a group with simulated mouse events and
check model positions, the nodeMoved signal and undo/redo.

Fixes #525
Fixes #526
Refs #533
paceholder added a commit that referenced this pull request Nov 22, 2026
Since the node group commit, dragging a node let Qt move the item and
never told the model, so NodeRole::Position stayed at the old value.
Saved positions, setNodeData overrides and nodeMoved saw stale data, and
a drag was not undoable.

Restore the original flow: mouseMoveEvent pushes a MoveNodeCommand and
the scene follows the model signals. MoveNodeCommand gets a constructor
taking explicit node ids, so group dragging can move the group's nodes
plus any selected nodes. GroupGraphicsObject::moveNodes writes to the
model without an undo command.

Remove the branch that moved the nodes of a locked group without an undo
command. A locked group is dragged through its own item.

Reset the drag flag of the scene on mouse press. A position set from code
or by undo no longer makes the next plain click emit nodeMoved.

Add tests that drag a node and a group with simulated mouse events and
check model positions, the nodeMoved signal and undo/redo.

Fixes #525
Fixes #526
Refs #533
@paceholder

Copy link
Copy Markdown
Owner

3.1.8 is out with the fix from #542. Thanks again for the tests.

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.

setNodeData no longer called when a node is moved public API broken: BasicGraphicsScene::nodeMoved is not emitted anymore

3 participants