--- a/eric6/Graphics/UMLGraphicsView.py Thu May 06 19:46:00 2021 +0200 +++ b/eric6/Graphics/UMLGraphicsView.py Sat May 08 18:34:08 2021 +0200 @@ -171,7 +171,17 @@ self.alignMapper.setMapping( self.alignBottomAct, Qt.AlignmentFlag.AlignBottom) self.alignBottomAct.triggered.connect(self.alignMapper.map) + + def setLayoutActionsEnabled(self, enable): + """ + Public method to enable or disable the layout related actions. + @param enable flag indicating the desired enable state + @type bool + """ + self.rescanAct.setEnabled(enable) + self.relayoutAct.setEnabled(enable) + def __checkSizeActions(self): """ Private slot to set the enabled state of the size actions. @@ -420,7 +430,7 @@ """ Public slot called to print the diagram. """ - printer = QPrinter(mode=QPrinter.PrinterMode.ScreenResolution) + printer = QPrinter(mode=QPrinter.PrinterMode.PrinterResolution) printer.setFullPage(True) if Preferences.getPrinter("ColorMode"): printer.setColorMode(QPrinter.ColorMode.Color) @@ -452,7 +462,7 @@ """ from PyQt5.QtPrintSupport import QPrintPreviewDialog - printer = QPrinter(mode=QPrinter.PrinterMode.ScreenResolution) + printer = QPrinter(mode=QPrinter.PrinterMode.PrinterResolution) printer.setFullPage(True) if Preferences.getPrinter("ColorMode"): printer.setColorMode(QPrinter.ColorMode.Color) @@ -782,14 +792,15 @@ y = float(y.split("=", 1)[1].strip()) itemType = itemType.split("=", 1)[1].strip() if itemType == ClassItem.ItemType: - itm = ClassItem(x=x, y=y, scene=self.scene(), + itm = ClassItem(x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()) elif itemType == ModuleItem.ItemType: - itm = ModuleItem(x=x, y=y, scene=self.scene(), + itm = ModuleItem(x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()) elif itemType == PackageItem.ItemType: - itm = PackageItem(x=x, y=y, scene=self.scene(), + itm = PackageItem(x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()) + itm.setPos(x, y) itm.setId(itemId) umlItems[itemId] = itm if not itm.parseItemDataString(version, itemData): @@ -814,15 +825,10 @@ @return dictionary containing data to be persisted @rtype dict """ - items = [] - for item in self.filteredItems(self.scene().items(), UMLItem): - items.append({ - "id": item.getId(), - "x": item.x(), - "y": item.y(), - "type": item.getItemType(), - "data": item.toDict() - }) + items = [ + item.toDict() + for item in self.filteredItems(self.scene().items(), UMLItem) + ] from .AssociationItem import AssociationItem associations = [ @@ -838,3 +844,50 @@ } return data + + def fromDict(self, version, data): + """ + Public method to populate the class with data persisted by 'toDict()'. + + @param version version of the data + @type str + @param data dictionary containing the persisted data + @type dict + @return flag indicating success + @rtype bool + """ + from .UMLItem import UMLItem + from .ClassItem import ClassItem + from .ModuleItem import ModuleItem + from .PackageItem import PackageItem + from .AssociationItem import AssociationItem + + umlItems = {} + + try: + self.diagramName = data["diagram_name"] + for itemData in data["items"]: + if itemData["type"] == UMLItem.ItemType: + itm = UMLItem.fromDict( + itemData, colors=self.getDrawingColors()) + elif itemData["type"] == ClassItem.ItemType: + itm = ClassItem.fromDict( + itemData, colors=self.getDrawingColors()) + elif itemData["type"] == ModuleItem.ItemType: + itm = ModuleItem.fromDict( + itemData, colors=self.getDrawingColors()) + elif itemData["type"] == PackageItem.ItemType: + itm = PackageItem.fromDict( + itemData, colors=self.getDrawingColors()) + if itm is not None: + umlItems[itm.getId()] = itm + self.scene().addItem(itm) + + for assocData in data["associations"]: + assoc = AssociationItem.fromDict( + assocData, umlItems, colors=self.getDrawingColors()) + self.scene().addItem(assoc) + + return True + except KeyError: + return False