diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Graphics/ModuleItem.py --- a/src/eric7/Graphics/ModuleItem.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Graphics/ModuleItem.py Wed Jul 13 14:55:47 2022 +0200 @@ -17,32 +17,33 @@ """ Class implementing the module model. """ + def __init__(self, name, classlist=None): """ Constructor - + @param name the module name @type str @param classlist list of class names @type list of str """ super().__init__(name) - + self.classlist = [] if classlist is None else classlist[:] - + def addClass(self, classname): """ Public method to add a class to the module model. - + @param classname class name to be added @type str """ self.classlist.append(classname) - + def getClasses(self): """ Public method to retrieve the classes of the module. - + @return list of class names @rtype list of str """ @@ -53,13 +54,15 @@ """ Class implementing a module item. """ + ItemType = "module" - - def __init__(self, model=None, x=0, y=0, rounded=False, colors=None, - parent=None, scene=None): + + def __init__( + self, model=None, x=0, y=0, rounded=False, colors=None, parent=None, scene=None + ): """ Constructor - + @param model module model containing the module data @type ModuleModel @param x x-coordinate @@ -76,26 +79,26 @@ @type QGraphicsScene """ UMLItem.__init__(self, model, x, y, rounded, colors, parent) - + if scene: scene.addItem(self) - + if self.model: self.__createTexts() self.__calculateSize() - + def __createTexts(self): """ Private method to create the text items of the module item. """ if self.model is None: return - + boldFont = QFont(self.font) boldFont.setBold(True) - + classes = self.model.getClasses() - + x = self.margin + int(self.rect().x()) y = self.margin + int(self.rect().y()) self.header = QGraphicsSimpleTextItem(self) @@ -110,25 +113,25 @@ self.classes.setFont(self.font) self.classes.setText(txt) self.classes.setPos(x, y) - + def __calculateSize(self): """ Private method to calculate the size of the module item. """ if self.model is None: return - + width = int(self.header.boundingRect().width()) height = int(self.header.boundingRect().height()) if self.classes: width = max(width, int(self.classes.boundingRect().width())) height += int(self.classes.boundingRect().height()) self.setSize(width + 2 * self.margin, height + 2 * self.margin) - + def setModel(self, model): """ Public method to set the module model. - + @param model module model containing the module data @type ModuleModel """ @@ -140,11 +143,11 @@ self.model = model self.__createTexts() self.__calculateSize() - + 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 @@ -154,32 +157,31 @@ """ 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.setFont(self.font) - + offsetX = int(self.rect().x()) offsetY = int(self.rect().y()) w = int(self.rect().width()) h = int(self.rect().height()) - + painter.drawRect(offsetX, offsetY, w, h) y = self.margin + int(self.header.boundingRect().height()) painter.drawLine(offsetX, offsetY + y, offsetX + w - 1, offsetY + y) - + self.adjustAssociations() - + 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 @@ -190,10 +192,10 @@ parts = data.split(", ") if len(parts) < 1: return False - + name = "" classes = [] - + for part in parts: key, value = part.split("=", 1) if key == "name": @@ -202,17 +204,17 @@ classes = value.strip().split("||") else: return False - + self.model = ModuleModel(name, classes) self.__createTexts() self.__calculateSize() - + return True - + def toDict(self): """ Public method to collect data to be persisted. - + @return dictionary containing data to be persisted @rtype dict """ @@ -224,12 +226,12 @@ "model_name": self.model.getName(), "classes": self.model.getClasses(), } - + @classmethod def fromDict(cls, data, colors=None): """ Class method to create a class item from persisted data. - + @param data dictionary containing the persisted data as generated by toDict() @type dict @@ -239,12 +241,8 @@ @rtype ClassItem """ try: - model = ModuleModel(data["model_name"], - data["classes"]) - itm = cls(model, - x=0, - y=0, - colors=colors) + model = ModuleModel(data["model_name"], data["classes"]) + itm = cls(model, x=0, y=0, colors=colors) itm.setPos(data["x"], data["y"]) itm.setId(data["id"]) return itm