@@ -125,15 +125,17 @@ def __init__(self, graph, node, pos=None):
125125 self .model = graph .model
126126 self .node = node
127127 self .pos = pos
128+ self .node_parent = node .parent ()
128129
129130 def undo (self ):
130131 self .pos = self .pos or self .node .pos ()
131132 self .model .nodes .pop (self .node .id )
132- self .node .view . delete ()
133+ self .node .delete ()
133134
134135 def redo (self ):
135136 self .model .nodes [self .node .id ] = self .node
136137 self .viewer .add_node (self .node .view , self .pos )
138+ self .node .set_parent (self .node_parent )
137139
138140
139141class NodeRemovedCmd (QtWidgets .QUndoCommand ):
@@ -153,6 +155,7 @@ def __init__(self, graph, node):
153155 self .node = node
154156 self .inputs = []
155157 self .outputs = []
158+ self .node_parent = node .parent ()
156159
157160 if hasattr (self .node , 'inputs' ):
158161 input_ports = self .node .inputs ().values ()
@@ -164,18 +167,15 @@ def __init__(self, graph, node):
164167 def undo (self ):
165168 self .model .nodes [self .node .id ] = self .node
166169 self .scene .addItem (self .node .view )
167- for port , connected_ports in self .inputs :
168- [port .connect_to (p ) for p in connected_ports ]
169- for port , connected_ports in self .outputs :
170- [port .connect_to (p ) for p in connected_ports ]
170+ [port .connect_to (p ) for port , connected_ports in self .inputs for p in connected_ports ]
171+ [port .connect_to (p ) for port , connected_ports in self .outputs for p in connected_ports ]
172+ self .node .set_parent (self .node_parent )
171173
172174 def redo (self ):
173- for port , connected_ports in self .inputs :
174- [port .disconnect_from (p ) for p in connected_ports ]
175- for port , connected_ports in self .outputs :
176- [port .disconnect_from (p ) for p in connected_ports ]
175+ [port .disconnect_from (p ) for port , connected_ports in self .inputs for p in connected_ports ]
176+ [port .disconnect_from (p ) for port , connected_ports in self .outputs for p in connected_ports ]
177177 self .model .nodes .pop (self .node .id )
178- self .node .view . delete ()
178+ self .node .delete ()
179179
180180
181181class NodeInputConnectedCmd (QtWidgets .QUndoCommand ):
0 commit comments