Skip to content

Commit 2d56c78

Browse files
committed
[ui] Graph: Updating the way how color gets set on the selected nodes
Coloring the nodes now uses setAttribute command instead of relying on refrences to Nodes within the graph.
1 parent 418bd63 commit 2d56c78

File tree

3 files changed

+6
-51
lines changed

3 files changed

+6
-51
lines changed

meshroom/ui/commands.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -205,54 +205,6 @@ def undoImpl(self):
205205
self.graph.removeNode(duplicate)
206206

207207

208-
class UpdateNodeColorCommand(GraphCommand):
209-
""" Command representing the work for Coloring nodes in the Graph.
210-
"""
211-
212-
def __init__(self, graph, nodes, color, parent=None):
213-
""" Command Constructor.
214-
215-
Args:
216-
graph (meshroom.core.Graph): Current Graph instance.
217-
nodes (list<Node>): Array of nodes.
218-
color (str): Hex code for the color.
219-
220-
Keyword Args:
221-
parent (QObject): Parent QObject instance.
222-
"""
223-
super(UpdateNodeColorCommand, self).__init__(graph, parent)
224-
self._nodes = nodes
225-
self._color = color
226-
227-
# Existing colors
228-
# Map <Node: str>
229-
# Holds the existing color of the node which can be applied on the node back in case of an undo
230-
self._colorMap = {}
231-
232-
self.setText("Update Selected Node Color")
233-
234-
def redoImpl(self) -> bool:
235-
""" Redo implementation.
236-
"""
237-
for node in self._nodes:
238-
# Update the existing color for the node in the map
239-
self._colorMap[node] = node.color
240-
241-
# Now update the color of the node with the provided one
242-
node.color = self._color
243-
244-
return True
245-
246-
def undoImpl(self):
247-
""" Undo Implementation.
248-
"""
249-
with GraphModification(self.graph):
250-
# Revert the color for the nodes
251-
for node in self._nodes:
252-
# Get the color which was saved for the node
253-
node.color = self._colorMap.get(node)
254-
255-
256208
class PasteNodesCommand(GraphCommand):
257209
"""
258210
Handle node pasting in a Graph.

meshroom/ui/graph.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,18 @@ def selectFollowing(self, node):
953953
self.selectNodes(self._graph.dfsOnDiscover(startNodes=[node], reverse=True, dependenciesOnly=True)[0])
954954

955955
@Slot(str)
956-
def updateNodeColor(self, color):
956+
def setSelectedNodesColor(self, color):
957957
""" Sets the Provided color on the selected Nodes.
958958
959959
Args:
960960
color (str): Hex code of the color to be set on the nodes.
961961
"""
962962
# Update the color attribute of the nodes which are currently selected
963963
with self.groupedGraphModification("Update Color for Select Nodes"):
964-
self.push(commands.UpdateNodeColorCommand(self._graph, list(self._selectedNodes), color))
964+
# For each of the selected nodes -> Check if the node has a color -> Apply the color if it has
965+
for node in self._selectedNodes:
966+
if node.hasInternalAttribute("color"):
967+
self.setAttribute(node.internalAttribute("color"), color)
965968

966969
@Slot(QObject, QObject)
967970
def boxSelect(self, selection, draggable):

meshroom/ui/qml/GraphEditor/GraphEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ Item {
10651065

10661066
// When a Color is selected
10671067
onColorSelected: (color)=> {
1068-
uigraph.updateNodeColor(color)
1068+
uigraph.setSelectedNodesColor(color)
10691069
}
10701070
}
10711071
}

0 commit comments

Comments
 (0)