def dropEvent(self, event): if event.mimeData().hasFormat("image/x-workflow-step"): pieceData = event.mimeData().data("image/x-workflow-step") stream = QtCore.QDataStream(pieceData, QtCore.QIODevice.ReadOnly) hotspot = QtCore.QPoint() nameLen = stream.readUInt32() name = stream.readRawData(nameLen).decode(sys.stdout.encoding) stream >> hotspot scene = self.scene() position = self.mapToScene(event.pos() - hotspot) metastep = MetaStep(workflowStepFactory(name, self._location)) node = Node(metastep) metastep._step.registerConfiguredObserver(scene.stepConfigured) metastep._step.registerDoneExecution(scene.doneExecution) metastep._step.registerOnExecuteEntry(scene.setCurrentWidget) metastep._step.registerIdentifierOccursCount(scene.identifierOccursCount) self._undoStack.beginMacro('Add node') self._undoStack.push(CommandAdd(scene, node)) # Set the position after it has been added to the scene self._undoStack.push(CommandMove(node, position, scene.ensureItemInScene(node, position))) scene.clearSelection() node.setSelected(True) self._undoStack.endMacro() self.setFocus() event.accept() else: event.ignore()
def updateModel(self): ''' Clears the QGraphicScene and re-populates it with what is currently in the WorkflowScene. ''' QtGui.QGraphicsScene.clear(self) meta_steps = {} connections = [] for workflowitem in self._workflow_scene.items(): if workflowitem.Type == MetaStep.Type: node = Node(workflowitem) workflowitem._step.registerConfiguredObserver(self.stepConfigured) workflowitem._step.registerDoneExecution(self.doneExecution) workflowitem._step.registerOnExecuteEntry(self.setCurrentWidget, self.setWidgetUndoRedoStack) workflowitem._step.registerIdentifierOccursCount(self.identifierOccursCount) # Put the node into the scene straight away so that the items scene will # be valid when we set the position. QtGui.QGraphicsScene.addItem(self, node) node.setPos(workflowitem.pos()) self.blockSignals(True) node.setSelected(workflowitem.selected()) self.blockSignals(False) meta_steps[workflowitem] = node elif workflowitem.Type == Connection.Type: connections.append(workflowitem) for connection in connections: src_port_item = meta_steps[connection.source()]._step_port_items[connection.sourceIndex()] destination_port_item = meta_steps[connection.destination()]._step_port_items[connection.destinationIndex()] arc = Arc(src_port_item, destination_port_item) # Overwrite the connection created in the Arc with the original one that is in the # WorkflowScene arc._connection = connection # Again put the arc into the scene straight away so the scene will be valid QtGui.QGraphicsScene.addItem(self, arc) self.blockSignals(True) arc.setSelected(connection.selected()) self.blockSignals(False) self._previousSelection = self.selectedItems()