Skip to content

refactor: Categorical NodeRegistry and updated QML Graph menu - #2582

Merged
RobBuchananCompPhys merged 5 commits into
dissolve2/gui2from
dissolve2/categorical-node-registry
Aug 21, 2026
Merged

RobBuchananCompPhys merged 5 commits into
dissolve2/gui2from
dissolve2/categorical-node-registry

Conversation

@RobBuchananCompPhys

@RobBuchananCompPhys RobBuchananCompPhys commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This PR puts the responsibility on the C++ NodeRegistry to store Node categories (which had previously been hardcoded into a QML menu) by an enum type. This categoricalProducers_ map is then flattened for more general use throughout the application, for retrieving any node. The categories are used to generate the context menu that appears when right-clicking in the Graph, and nodes can be created in that way.

Comment thread src/gui2/models/enumOptionsModel.cpp Outdated
Comment on lines +20 to +26
QHash<int, QByteArray> EnumOptionsModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "option";
return roles;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to rename the display role as "option" instead of just using "display" in the QML?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't know you could do that, but it sounds sensible and would make this cleaner (no need for a custom roleNames override)

Comment thread src/gui2/qml/nodeGraph/GraphView.qml Outdated
graphModel: graphRoot.rootGraphModel
posx: Math.round(ctxMenuCatcher.mouseX)
posy: Math.round(ctxMenuCatcher.mouseY)
Instantiator {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit more inclined to use a Repeater here. The Instantiator is useful when you're adding and removing nodes at runtime. Since the number of nodes and categories are fixed, we can just use a repeater. As an added bonus, we can drop the onObjectAdded and onObjectRemoved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point👍

Comment thread src/nodes/registry.cpp
}

// Static Singletons
const std::map<NodeRegistry::Category, ProducerMap> NodeRegistry::categoricalProducers_{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll admit that I had considered a slightly different architecture. Specifically, I had though that we would add a virtual category method to the Node class which returns a Node::Category (since this would require that the Category enum be moved out of NodeRegistry into Node). This map would then just be a vector and the NodeRegistryModel would filter the list by the category of each node type to ensure that everything was listed in the proper categories.

Honestly, though, I'm not sure that my architecture is any better, but rather just different. The main advantage would be that it would be impossible to forget to assign a category to a new Node class, since the unimplemented virtual method would be a compiler error. However, it would still be possible to forget to add the node to the registry vector, which gets us the very same problem. The only real advantage is that Nodes would directly know their own category, but I'm not sure that will every be useful.

@RobBuchananCompPhys
RobBuchananCompPhys merged commit 0bd1041 into dissolve2/gui2 Aug 21, 2026
@RobBuchananCompPhys
RobBuchananCompPhys deleted the dissolve2/categorical-node-registry branch August 21, 2026 11:08
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.

2 participants