diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Graphics/UMLItem.py --- a/src/eric7/Graphics/UMLItem.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Graphics/UMLItem.py Wed Jul 13 14:55:47 2022 +0200 @@ -18,19 +18,20 @@ """ Class implementing the UMLModel base class. """ + def __init__(self, name): """ Constructor - + @param name package name @type str """ self.name = name - + def getName(self): """ Public method to retrieve the model name. - + @return model name @rtype str """ @@ -41,13 +42,13 @@ """ Class implementing the UMLItem base class. """ + ItemType = "UMLItem" - - def __init__(self, model=None, x=0, y=0, rounded=False, colors=None, - parent=None): + + def __init__(self, model=None, x=0, y=0, rounded=False, colors=None, parent=None): """ Constructor - + @param model UML model containing the item data @type UMLModel @param x x-coordinate @@ -63,36 +64,34 @@ """ super().__init__(parent) self.model = model - + if colors is None: - self._colors = (QColor(Qt.GlobalColor.black), - QColor(Qt.GlobalColor.white)) + self._colors = (QColor(Qt.GlobalColor.black), QColor(Qt.GlobalColor.white)) else: self._colors = colors self.setPen(QPen(self._colors[0])) - + self.font = Preferences.getGraphics("Font") self.margin = 5 self.associations = [] self.shouldAdjustAssociations = False self.__id = -1 - + self.setRect(x, y, 60, 30) - + if rounded: p = self.pen() p.setCapStyle(Qt.PenCapStyle.RoundCap) p.setJoinStyle(Qt.PenJoinStyle.RoundJoin) - + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, True) self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable, True) - self.setFlag( - QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges, True) - + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges, True) + def getName(self): """ Public method to retrieve the item name. - + @return item name @rtype str """ @@ -100,11 +99,11 @@ return self.model.name else: return "" - + def setSize(self, width, height): """ Public method to set the rectangles size. - + @param width width of the rectangle @type float @param height height of the rectangle @@ -113,27 +112,27 @@ rect = self.rect() rect.setSize(QSizeF(width, height)) self.setRect(rect) - + def addAssociation(self, assoc): """ Public method to add an association to this widget. - + @param assoc association to be added @type AssociationWidget """ if assoc and assoc not in self.associations: self.associations.append(assoc) - + def removeAssociation(self, assoc): """ Public method to remove an association to this widget. - + @param assoc association to be removed @type AssociationWidget """ if assoc and assoc in self.associations: self.associations.remove(assoc) - + def removeAssociations(self): """ Public method to remove all associations of this widget. @@ -142,7 +141,7 @@ assoc.unassociate() assoc.hide() del assoc - + def adjustAssociations(self): """ Public method to adjust the associations to widget movements. @@ -151,11 +150,11 @@ for assoc in self.associations: assoc.widgetMoved() self.shouldAdjustAssociations = False - + def moveBy(self, dx, dy): """ Public overriden method to move the widget relative. - + @param dx relative movement in x-direction @type float @param dy relative movement in y-direction @@ -163,11 +162,11 @@ """ super().moveBy(dx, dy) self.adjustAssociations() - + def setPos(self, x, y): """ Public overriden method to set the items position. - + @param x absolute x-position @type float @param y absolute y-position @@ -175,11 +174,11 @@ """ super().setPos(x, y) self.adjustAssociations() - + def itemChange(self, change, value): """ Public method called when an items state changes. - + @param change the item's change @type QGraphicsItem.GraphicsItemChange @param value the value of the change @@ -188,7 +187,7 @@ if change == QGraphicsItem.GraphicsItemChange.ItemPositionChange: # 1. remember to adjust associations self.shouldAdjustAssociations = True - + # 2. ensure the new position is inside the scene scene = self.scene() if scene: @@ -198,13 +197,13 @@ value.setX(min(rect.right(), max(value.x(), rect.left()))) value.setY(min(rect.bottom(), max(value.y(), rect.top()))) return value - + return QGraphicsItem.itemChange(self, change, value) - + def paint(self, painter, option, widget=None): """ Public method to paint the item in local coordinates. - + @param painter reference to the painter object @type QPainter @param option style options @@ -214,49 +213,48 @@ """ pen = self.pen() if ( - (option.state & QStyle.StateFlag.State_Selected) == - QStyle.StateFlag.State_Selected - ): + option.state & QStyle.StateFlag.State_Selected + ) == QStyle.StateFlag.State_Selected: pen.setWidth(2) else: pen.setWidth(1) - + painter.setPen(pen) painter.setBrush(self.brush()) painter.drawRect(self.rect()) self.adjustAssociations() - + def setId(self, itemId): """ Public method to assign an ID to the item. - + @param itemId assigned ID @type int """ self.__id = itemId - + def getId(self): """ Public method to get the item ID. - + @return ID of the item @rtype int """ return self.__id - + def getItemType(self): """ Public method to get the item's type. - + @return item type @rtype str """ return self.ItemType - + def parseItemDataString(self, version, data): """ Public method to parse the given persistence data. - + @param version version of the data @type str @param data persisted data to be parsed @@ -265,11 +263,11 @@ @rtype bool """ return True - + def toDict(self): """ Public method to collect data to be persisted. - + @return dictionary containing data to be persisted @rtype dict """ @@ -280,12 +278,12 @@ "type": self.getItemType(), "model_name": self.model.getName(), } - + @classmethod def fromDict(cls, data, colors=None): """ Class method to create a generic UML item from persisted data. - + @param data dictionary containing the persisted data as generated by toDict() @type dict @@ -296,10 +294,7 @@ """ try: model = UMLModel(data["model_name"]) - itm = cls(model=model, - x=0, - y=0, - colors=colors) + itm = cls(model=model, x=0, y=0, colors=colors) itm.setPos(data["x"], data["y"]) itm.setId(data["id"]) return itm