Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeStyle changes do not propagate to templates #226

Open
petrmanek opened this issue Feb 21, 2024 · 3 comments
Open

NodeStyle changes do not propagate to templates #226

petrmanek opened this issue Feb 21, 2024 · 3 comments

Comments

@petrmanek
Copy link

petrmanek commented Feb 21, 2024

Suppose that I have several node styles, and I would like to switch between them to indicate a state of a node (perhaps using a distinct backColor). On the level of my qan::Node subclass, I call getItem()->setStyle(x), after which I would expect that the QML code would adapt to my changes. Instead I see no difference.

In my particular case, I am using RectNodeTemplate, which internally relies on RectSolidBackground. By diving deep into the UI code, I found that because of lazy-loading, the node template only assigns the style property when the nodeItem property changes. Furthermore, there are protections against configuring nodeItem to null or undefined, which make it impossible to reset the nodeItem and explicitly set it again as a workaround.

By local experimentation, I figured out that the following patch to src/RectNodeTemplate.qml corrects the issue. It simply adds a change handler to nodeItem.style, which passes on the change to the loaded delegate. You may perhaps want to implement analogous fix to edges and groups.

diff --git a/src/RectNodeTemplate.qml b/src/RectNodeTemplate.qml
index 786380c..2fdf00d 100644
--- a/src/RectNodeTemplate.qml
+++ b/src/RectNodeTemplate.qml
@@ -55,7 +55,12 @@ Item {
             delegateLoader.item.nodeItem)
             delegateLoader.item.nodeItem = nodeItem
     }
+    onStyleChanged: {
+        if (template.nodeItem && delegateLoader.item)
+            delegateLoader.item.style = template.nodeItem ? template.nodeItem.style : undefined
+    }
     readonly property real   backRadius: nodeItem && nodeItem.style ? nodeItem.style.backRadius : 4.
+    readonly property var    style: nodeItem ? nodeItem.style : undefined
     Loader {
         id: delegateLoader
         anchors.fill: parent
@cneben
Copy link
Owner

cneben commented Feb 21, 2024

Hi @petrmanek I have the exact same problem with "group styles".

I will have a look at you proposition to see if it scale for groups, pushing in that branch.

@emmenlau
Copy link
Contributor

I can confirm that this patch solves the issue with node styles on the latest develop branch! Nice work @petrmanek , now it would be great if the changes can be cleanly integrated.

@petrmanek
Copy link
Author

Has there been any development on this? @cneben

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

No branches or pull requests

3 participants