def dropEvent(self, dropEvent): """ Executed when a dragged element is dropped on the diagram. :type dropEvent: QGraphicsSceneDragDropEvent """ super().dropEvent(dropEvent) if dropEvent.mimeData().hasFormat('text/plain') and Item.valueOf(dropEvent.mimeData().text()): snapToGrid = self.session.action('toggle_grid').isChecked() node = self.factory.create(Item.valueOf(dropEvent.mimeData().text())) data = dropEvent.mimeData().data(dropEvent.mimeData().text()) iri = None if data is not None: data_str = '' for i in range(0, data.size()): data_str = data_str + data.at(i) if data_str is not '': data_comma_seperated = data_str.split(',') iri = data_comma_seperated[0] rc = data_comma_seperated[1] txt = data_comma_seperated[2] node.setText(txt) node.remaining_characters = rc node.setPos(snap(dropEvent.scenePos(), Diagram.GridSize, snapToGrid)) commands = [] if iri is not None: Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(self.project.IRI_prefixes_nodes_dict, dict()) Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(self.project.IRI_prefixes_nodes_dict, dict()) Duplicate_dict_1 = self.project.addIRINodeEntry(Duplicate_dict_1, iri, node) if Duplicate_dict_1 is not None: pass commands.append(CommandProjectDisconnectSpecificSignals(self.project)) commands.append(CommandProjetSetIRIPrefixesNodesDict(self.project, Duplicate_dict_2, Duplicate_dict_1, [iri], None)) commands.append(CommandNodeAdd(self, node)) if iri is not None: commands.append(CommandProjetSetIRIPrefixesNodesDict(self.project, Duplicate_dict_2, Duplicate_dict_1, [iri], None)) commands.append(CommandProjectConnectSpecificSignals(self.project)) if any(commands): self.session.undostack.beginMacro('node Add - {0}'.format(node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() self.sgnItemInsertionCompleted.emit(node, dropEvent.modifiers()) dropEvent.setDropAction(QtCore.Qt.CopyAction) dropEvent.accept() else: dropEvent.ignore()
def classForItem(cls, item): """ Returns the class implementing the given item. :type item: Item :rtype: class """ item = Item.valueOf(item) if item is Item.AttributeNode: return AttributeNode if item is Item.ComplementNode: return ComplementNode if item is Item.ConceptNode: return ConceptNode if item is Item.DatatypeRestrictionNode: return DatatypeRestrictionNode if item is Item.DisjointUnionNode: return DisjointUnionNode if item is Item.DomainRestrictionNode: return DomainRestrictionNode if item is Item.EnumerationNode: return EnumerationNode if item is Item.FacetNode: return FacetNode if item is Item.IndividualNode: return IndividualNode if item is Item.IntersectionNode: return IntersectionNode if item is Item.PropertyAssertionNode: return PropertyAssertionNode if item is Item.RangeRestrictionNode: return RangeRestrictionNode if item is Item.RoleNode: return RoleNode if item is Item.RoleChainNode: return RoleChainNode if item is Item.RoleInverseNode: return RoleInverseNode if item is Item.UnionNode: return UnionNode if item is Item.ValueDomainNode: return ValueDomainNode if item is Item.InclusionEdge: return InclusionEdge if item is Item.EquivalenceEdge: return EquivalenceEdge if item is Item.InputEdge: return InputEdge if item is Item.MembershipEdge: return MembershipEdge if item is Item.SameEdge: return SameEdge if item is Item.DifferentEdge: return DifferentEdge raise RuntimeError('unknown item type ({0})'.format(item))
def dropEvent(self, dropEvent): """ Executed when a dragged element is dropped on the diagram. :type dropEvent: QGraphicsSceneDragDropEvent """ super().dropEvent(dropEvent) if dropEvent.mimeData().hasFormat('text/plain'): snapToGrid = self.session.action('toggle_grid').isChecked() node = self.factory.create( Item.valueOf(dropEvent.mimeData().text())) node.setPos( snap(dropEvent.scenePos(), Diagram.GridSize, snapToGrid)) self.session.undostack.push(CommandNodeAdd(self, node)) self.sgnItemInsertionCompleted.emit(node, dropEvent.modifiers()) dropEvent.setDropAction(QtCore.Qt.CopyAction) dropEvent.accept() else: dropEvent.ignore()
def mousePressEvent(self, mouseEvent): """ Executed when a mouse button is clicked on the scene. :type mouseEvent: QGraphicsSceneMouseEvent """ self.project.colour_items_in_case_of_unsatisfiability_or_inconsistent_ontology( ) mouseModifiers = mouseEvent.modifiers() mouseButtons = mouseEvent.buttons() mousePos = mouseEvent.scenePos() if mouseButtons & QtCore.Qt.LeftButton: if self.mode is DiagramMode.NodeAdd: ############################################# # NODE INSERTION ################################# snapToGrid = self.session.action('toggle_grid').isChecked() node = self.factory.create(Item.valueOf(self.modeParam)) node.setPos(snap(mousePos, Diagram.GridSize, snapToGrid)) if isinstance(node, OntologyEntityNode) or isinstance( node, OntologyEntityResizableNode): self.session.doOpenIRIBuilder(node) elif isinstance(node, FacetNode): self.session.doOpenConstrainingFacetBuilder(node) elif isinstance(node, LiteralNode): self.session.doOpenLiteralBuilder(node) else: self.session.undostack.push(CommandNodeAdd(self, node)) self.sgnItemInsertionCompleted.emit(node, mouseEvent.modifiers()) elif self.mode is DiagramMode.EdgeAdd: ############################################# # EDGE INSERTION ################################# node = first(self.items(mousePos, edges=False)) if node: edge = self.factory.create(Item.valueOf(self.modeParam), source=node) edge.updateEdge(target=mousePos) self.mp_Edge = edge self.addItem(edge) else: # Execute super at first since this may change the diagram # mode: some actions are directly handle by graphics items # (i.e: edge breakpoint move, edge anchor move, node shape # resize) and we need to check whether any of them is being # performed before handling the even locally. super().mousePressEvent(mouseEvent) if self.mode is DiagramMode.Idle: if mouseModifiers & QtCore.Qt.ShiftModifier: ############################################# # LABEL MOVE ################################# item = first( self.items(mousePos, nodes=False, edges=False, labels=True)) if item and item.isMovable(): self.clearSelection() self.mp_Label = item self.mp_LabelPos = item.pos() self.mp_Pos = mousePos self.setMode(DiagramMode.LabelMove) else: ############################################# # ITEM SELECTION ################################# item = first(self.items(mousePos, labels=True)) if item: if item.isLabel(): # If we are hitting a label, check whether the label # is overlapping it's parent item and such item is # also intersecting the current mouse position: if so, # use the parent item as placeholder for the selection. parent = item.parentItem() items = self.items(mousePos) item = parent if parent in items else None if item: if mouseModifiers & QtCore.Qt.ControlModifier: # CTRL => support item multi selection. item.setSelected(not item.isSelected()) else: if self.selectedItems(): # Some elements have been already selected in the # diagram, during a previous mouse press event. if not item.isSelected(): # There are some items selected but we clicked # on a node which is not currently selected, so # make this node the only selected one. self.clearSelection() item.setSelected(True) else: # No item (nodes or edges) is selected and we just # clicked on one so make sure to select this item and # because selectedItems() filters out item Label's, # clear out the selection on the diagram. self.clearSelection() item.setSelected(True) # If we have some nodes selected we need to prepare data for a # possible item move operation: we need to make sure to retrieve # the node below the mouse cursor that will act as as mouse grabber # to compute delta movements for each component in the selection. selected = self.selectedNodes() if selected: self.mp_Node = first( self.items(mousePos, edges=False)) if self.mp_Node: self.mp_NodePos = self.mp_Node.pos() self.mp_Pos = mousePos self.mp_Data = self.setupMove(selected)
def dropEvent(self, dropEvent): """ Executed when a dragged element is dropped on the diagram. :type dropEvent: QGraphicsSceneDragDropEvent """ super().dropEvent(dropEvent) if dropEvent.mimeData().hasFormat('text/plain') and Item.valueOf( dropEvent.mimeData().text()): snapToGrid = self.session.action('toggle_grid').isChecked() #TODO nodeType = dropEvent.mimeData().text() if Item.ConceptIRINode <= int( dropEvent.mimeData().text()) <= Item.IndividualIRINode: #New node associated with IRI object #node = ConceptNode(diagram=self) node = self.factory.create( Item.valueOf(dropEvent.mimeData().text())) node.setPos( snap(dropEvent.scenePos(), Diagram.GridSize, snapToGrid)) data = dropEvent.mimeData().data(dropEvent.mimeData().text()) if not data: #new element if isinstance(node, FacetNode): self.session.doOpenConstrainingFacetBuilder(node) elif isinstance(node, OntologyEntityNode) or isinstance( node, OntologyEntityResizableNode): self.session.doOpenIRIBuilder(node) elif isinstance(node, LiteralNode): self.session.doOpenLiteralBuilder(node) else: #copy of existing element (e.g. drag and drop from ontology explorer) data_str = str(data, encoding='utf-8') iri = self.project.getIRI(data_str) node.iri = iri self.doAddOntologyEntityNode(node) node.doUpdateNodeLabel() else: #Old node type node = self.factory.create( Item.valueOf(dropEvent.mimeData().text())) data = dropEvent.mimeData().data(dropEvent.mimeData().text()) iri = None if data is not None: data_str = str(data, encoding='utf-8') if data_str is not '': data_comma_seperated = data_str.split(',') iri = data_comma_seperated[0] rc = data_comma_seperated[1] txt = data_comma_seperated[2] node.setText(txt) node.remaining_characters = rc node.setPos( snap(dropEvent.scenePos(), Diagram.GridSize, snapToGrid)) commands = [] #node.emptyMethod() if iri is not None: Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries( self.project.IRI_prefixes_nodes_dict, dict()) Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries( self.project.IRI_prefixes_nodes_dict, dict()) Duplicate_dict_1 = self.project.addIRINodeEntry( Duplicate_dict_1, iri, node) if Duplicate_dict_1 is not None: pass #commands.append(CommandProjetSetIRIPrefixesNodesDict(self.project, Duplicate_dict_2, Duplicate_dict_1, [iri], None)) commands.append(CommandNodeAdd(self, node)) if any(commands): self.session.undostack.beginMacro('node Add - {0}'.format( node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() self.sgnItemInsertionCompleted.emit(node, dropEvent.modifiers()) dropEvent.setDropAction(QtCore.Qt.CopyAction) dropEvent.accept() else: dropEvent.ignore()