nodeeditor icon indicating copy to clipboard operation
nodeeditor copied to clipboard

nodeId parameter is always 0 when read from ```virtual bool deleteNode(NodeId const nodeId) override```

Open OpenJowel opened this issue 6 months ago • 1 comments

Description with steps to reproduce

Hi, first of all, thank you for this beautiful project. It is exactly what I have been looking for.

I am only facing a problem currently, I have been working on a class implementation based on QtNodes::AbstractGraphModel.

Everything was going perfect until I started to handle nodes deletion. Indeed, when I set a breakpoint in

    bool GraphViewController::deleteNode(QtNodes::NodeId nodeId)
    {
      Logger::debug("Deleting ", nodeId);
     // ...
    }

The nodeId value is always 0 when I delete the node from the UI (selecting node and hitting "delete" key)

However, i am able to refer to proper IDs everywhere else and it's perfect. (I am simply using an increment value at node creation.)

Am I missing anything ? I am using the version 3.0.12 of the project

Thank you very much,

Cheers

Supporting files, videos and screenshots

Image

Qt Version

6

Operating system

ArchLinux

Additional context

No response

Checklist

  • [x] I have verified that this issue has not been logged before, by searching the issue tracker for similar issues
  • [x] I have attached all requested files and information to this report
  • [x] I have attempted to identify the root problem as concisely as possible, and have used minimal reproducible examples where possible

OpenJowel avatar Aug 28 '25 16:08 OpenJowel

For some reasons, the problem was solved by overriding the non-pure "saveNode" method as follow:

QJsonObject GraphViewController::saveNode(NodeId const nodeId) const
{
    QJsonObject nodeJson;

    nodeJson["id"] = static_cast<qint64>(nodeId);

    return nodeJson;
}

It feels a bit like a positive side effect. Is it normal ? The documentation states:

inline virtual QJsonObject saveNode(NodeId const) const

    Reimplement the function if you want to store/restore the node’s inner state during undo/redo node deletion operations.

But doesn't warn clearly about this requirement regarding node id validity at deletion time as it mostly states about undo/redo.

Well. My problem is solved but the reason is still unclear. The SimpleGraph example helped me well getting over this.

If you want to reproduce my "bug" scenario, just comment-out the saveNode method from the abovementioned example and observe the ID passed to deleteNode will always be 0.

If this behavior is purposeful, I would advise to set virtual QJsonObject saveNode(NodeId const) const to pure in the AbstractGraphModel class (or to make it do the bare minimum (such as the implementation above)) as this sounds like a obscure requirement for well-behaving NodeID.

Else, there might be a bug to fix in order to ensure proper ID at deletion time.

Thank you for your attention

OpenJowel avatar Aug 29 '25 09:08 OpenJowel