Skip to content

Fix the gaps in the change notifications of the scene and the model - #575

Merged
paceholder merged 6 commits into
masterfrom
fix-notification-gaps
Dec 2, 2026
Merged

paceholder merged 6 commits into
masterfrom
fix-notification-gaps

Conversation

@paceholder

Copy link
Copy Markdown
Owner

Type of change

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

Description

A trace of the update and notification paths found places where a change reached the model but not the scene, or where the model and the scene disagreed. This PR fixes them in six commits. Each commit builds, passes the whole test suite and can be reverted alone. Each fix has a regression test that failed before the fix.

  1. Update the node after port changes, a load and a widget resize. The node kept its old size after a delegate inserted or deleted ports, and after a node with a label was loaded. embeddedWidgetSizeUpdated had no listener since 2.x (see Embedded widget with wrong size when content has changed #408). DataFlowGraphModel now emits nodeUpdated in these cases. The delegate signals are connected in one private helper for addNode and loadNode.
  2. Clear the undo stack when the graph is replaced and keep one undo action. clearScene() and onModelReset() (and so load()) leave old commands that refer to ids of a graph that no longer exists. They now clear the stack. setScene() of the view added one more Undo and Redo action on each call. The undo guide listed a DuplicateCommand that does not exist.
  3. Keep connections on locked nodes and paste through the model. A model-locked node did not report position changes, so the connections stayed behind when code moved it. The flag was tied to the lock by accident: it never stops a move. loadItems with a paste position moved only the item, and the model kept the old position.
  4. Stop the endless repaint of a visible node group. GroupGraphicsObject::paint() changed its geometry, which scheduled the next paint. The area is now computed when a node moves, resizes, joins or leaves, and paint() only draws. The node calls the update where its geometry changes (position change, resize handle, onNodeUpdated); moveConnections() still moves connections only. Part of Node groups: repaint loop, stale drag state, paste position #537.
  5. Add the connection signals that nodes already have and document the delegate signals. connectionSelected and connectionDoubleClicked on the scene, like nodeSelected and nodeDoubleClicked. The guide and the header comments say who emits and who listens to the delegate signals, and what a custom model must emit after a port change. Fixes Add connectionSelected and connectionDoubleClicked scene signals #551.
  6. Send empty data downstream when a delegate emits dataInvalidated. The 2.x library cleared the connected inputs on dataInvalidated. The 3.x rewrite dropped the listener, so the calculator and node_validation examples kept the last valid value. The model sends empty data again, through the helper that deleteConnection already uses.

Behavior changes

  • More nodeUpdated signals: after port changes of a delegate, once for each loaded node, and on embeddedWidgetSizeUpdated.
  • The undo history is cleared by clearScene(), onModelReset() and load(). Old steps cannot be undone after the whole graph is replaced.
  • A locked node reports position changes, so its connections follow it.
  • A pasted node has the pasted position in the model.
  • setScene() of the view keeps one Undo and one Redo action. setScene(nullptr) also deletes the cut action.
  • The box of a group is computed when its nodes change. boundingRect() returns the stored area.
  • dataInvalidated clears the connected inputs, as in 2.x.

Public API added

  • BasicGraphicsScene::connectionSelected and connectionDoubleClicked, appended at the end of the signal list. ConnectionGraphicsObject overrides mouseDoubleClickEvent (an existing base class virtual).
  • GroupGraphicsObject::updateGeometry(), public because NodeGroup and NodeGraphicsObject call it, like the existing positionLockedIcon().
  • No virtual function and no data member is added to a public class, apart from the private members of the classes that change. I did not check the binary compatibility with a tool.

Not in this PR

A global style change still repaints nothing, the group paste offset (ggo.pos() is always (0,0)) needs a decision, and two scenes on one model still overwrite each other's node size. nodeUpdated still carries no reason.

Testing

  • Qt version tested: 6.12 (offscreen). CI covers Qt 5 and MSVC.
  • Existing tests still pass (111 test cases, 1020 assertions at the last commit). I built every commit on its own, with the examples, and ran the suite.
  • Added tests for new functionality: one or more for each fix, in TestNodeSizeUpdates, TestSceneSetup, TestLockAndPaste, TestGroupRepaint, TestNotifications and TestDataInvalidated. Each failed on the code before its fix. I also removed each group update call for a moment: without the one in itemChange the move test fails, and without the one in onNodeUpdated the size test fails.

Not tested: Qt 5, Linux, Windows, a real GPU window. The paint count was measured offscreen. No test drags the resize handle, so the group update in that branch of mouseMoveEvent is not covered.

Breaking changes?

No API or ABI is removed or changed. See the behavior changes above.

Related issue

Fixes #551. Part of #537 (item 1). See #408.

DataFlowGraphModel now emits nodeUpdated in three more cases, so that the
scene recomputes the node size:

- after a delegate inserts or deletes ports, once the shifted connections
  are restored;
- after loadNode() restored the label and the delegate state, because
  nodeCreated comes before them;
- when a delegate emits embeddedWidgetSizeUpdated, like requestNodeUpdate.

The delegate signals are connected in one helper for addNode() and
loadNode(). The header and the guide now say that a custom model must emit
nodeUpdated after portsInserted() and portsDeleted().
clearScene() deletes all nodes without an undo step, and onModelReset()
rebuilds the scene from a new graph. The old commands then refer to nodes
that no longer exist, and an undo could restore stale ids. Both now clear
the undo stack. DataFlowGraphicsScene::load() calls clearScene(), so a load
clears it too.

GraphicsView::setScene() added a new Undo and Redo action on each call.
It now deletes the actions of the previous scene. setScene(nullptr) also
deletes the cut action, like the other actions.

The undo guide listed a DuplicateCommand that does not exist. It now lists
the real commands and says when the stack is cleared.
A model-locked node turned off ItemSendsScenePositionChanges. The flag came
with the first lock in 388666a, next to ItemIsMovable, but it does not stop
a move: it only tells the item about one. A locked node moved from code or
by undo then left its connections behind. The flag is now always on. The
lock still clears ItemIsMovable and ItemIsSelectable, and the press handler
still ignores a locked node.

loadItems(..., usePastePos=true) moved a pasted node with moveBy(), so the
model kept the old position. It now writes the position through the model.
GroupGraphicsObject::paint() called prepareGeometryChange(), setRect() and
positionLockedIcon(). Each call marked the item dirty and scheduled the
next paint, so an idle view with one group repainted without end (3446
viewport paints in 300 ms in the new test).

The group now computes its area in updateGeometry() and stores it in
rect(). boundingRect() returns it, and paint() only draws. The area is
recomputed when the group is created, when a node joins or leaves, when a
possible child is set or cleared during a drag, and when a node of the
group moves or changes its size (both end in moveConnections()).

Part of #537 (item 1).
…elegate signals

BasicGraphicsScene gets connectionSelected and connectionDoubleClicked.
ConnectionGraphicsObject emits them like NodeGraphicsObject emits nodeSelected
and nodeDoubleClicked. The new signals are appended at the end of the signal
list. Nothing existing changes.

The headers and the guide now say who listens to the delegate signals:
embeddedWidgetSizeUpdated updates the node, while computingStarted and
computingFinished are for the application only. The guide also says that a
custom model must emit nodeUpdated after a port change.

See #551
The 2.x library cleared the connected inputs on dataInvalidated. The 3.x rewrite dropped the listener, so the calculator and node_validation examples kept showing the last valid value. DataFlowGraphModel now sends empty data to the inputs that are connected to the port.
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.

Add connectionSelected and connectionDoubleClicked scene signals

1 participant