src/eric7/Graphics/UMLGraphicsView.py

branch
eric7
changeset 10922
36a90a94765c
parent 10917
4f40180b98dc
child 11006
a671918232f3
equal deleted inserted replaced
10921:495f084a737e 10922:36a90a94765c
52 @param scene reference to the scene object 52 @param scene reference to the scene object
53 @type QGraphicsScene 53 @type QGraphicsScene
54 @param parent parent widget of the view 54 @param parent parent widget of the view
55 @type QWidget 55 @type QWidget
56 """ 56 """
57 EricGraphicsView.__init__(self, scene, parent) 57 EricGraphicsView.__init__(
58 self,
59 scene,
60 drawingMode=Preferences.getGraphics("DrawingMode"),
61 parent=parent,
62 )
58 self.setObjectName("UMLGraphicsView") 63 self.setObjectName("UMLGraphicsView")
59 self.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.FullViewportUpdate) 64 self.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.FullViewportUpdate)
60 65
61 self.diagramName = "Unnamed" 66 self.diagramName = "Unnamed"
62 self.__itemId = -1 67 self.__itemId = -1
465 if printerName: 470 if printerName:
466 printer.setPrinterName(printerName) 471 printer.setPrinterName(printerName)
467 472
468 printDialog = QPrintDialog(printer, self) 473 printDialog = QPrintDialog(printer, self)
469 if printDialog.exec(): 474 if printDialog.exec():
470 super().printDiagram(printer, self.diagramName) 475 super().printDiagram(
476 printer,
477 margins=QMarginsF(
478 Preferences.getPrinter("LeftMargin"),
479 Preferences.getPrinter("TopMargin"),
480 Preferences.getPrinter("RightMargin"),
481 Preferences.getPrinter("BottomMargin"),
482 ),
483 diagramName=self.diagramName,
484 )
471 485
472 def printPreviewDiagram(self): 486 def printPreviewDiagram(self):
473 """ 487 """
474 Public slot called to show a print preview of the diagram. 488 Public slot called to show a print preview of the diagram.
475 """ 489 """
505 Private slot to generate a print preview. 519 Private slot to generate a print preview.
506 520
507 @param printer reference to the printer object 521 @param printer reference to the printer object
508 @type QPrinter 522 @type QPrinter
509 """ 523 """
510 super().printDiagram(printer, self.diagramName) 524 super().printDiagram(
525 printer,
526 margins=QMarginsF(
527 Preferences.getPrinter("LeftMargin"),
528 Preferences.getPrinter("TopMargin"),
529 Preferences.getPrinter("RightMargin"),
530 Preferences.getPrinter("BottomMargin"),
531 ),
532 diagramName=self.diagramName,
533 )
511 534
512 def setDiagramName(self, name): 535 def setDiagramName(self, name):
513 """ 536 """
514 Public slot to set the diagram name. 537 Public slot to set the diagram name.
515 538
760 783
761 if not data[0].startswith("diagram_name:"): 784 if not data[0].startswith("diagram_name:"):
762 return False, 0 785 return False, 0
763 self.diagramName = data[0].split(": ", 1)[1].strip() 786 self.diagramName = data[0].split(": ", 1)[1].strip()
764 787
788 colors = self.getDrawingColors(
789 drawingMode=Preferences.getGraphics("DrawingMode")
790 )
765 for linenum, line in enumerate(data[1:], start=1): 791 for linenum, line in enumerate(data[1:], start=1):
766 if not line.startswith(("item:", "association:")): 792 if not line.startswith(("item:", "association:")):
767 return False, linenum 793 return False, linenum
768 794
769 key, value = line.split(": ", 1) 795 key, value = line.split(": ", 1)
773 itemId = int(itemId.split("=", 1)[1].strip()) 799 itemId = int(itemId.split("=", 1)[1].strip())
774 x = float(x.split("=", 1)[1].strip()) 800 x = float(x.split("=", 1)[1].strip())
775 y = float(y.split("=", 1)[1].strip()) 801 y = float(y.split("=", 1)[1].strip())
776 itemType = itemType.split("=", 1)[1].strip() 802 itemType = itemType.split("=", 1)[1].strip()
777 if itemType == ClassItem.ItemType: 803 if itemType == ClassItem.ItemType:
778 itm = ClassItem( 804 itm = ClassItem(x=0, y=0, scene=self.scene(), colors=colors)
779 x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()
780 )
781 elif itemType == ModuleItem.ItemType: 805 elif itemType == ModuleItem.ItemType:
782 itm = ModuleItem( 806 itm = ModuleItem(x=0, y=0, scene=self.scene(), colors=colors)
783 x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()
784 )
785 elif itemType == PackageItem.ItemType: 807 elif itemType == PackageItem.ItemType:
786 itm = PackageItem( 808 itm = PackageItem(x=0, y=0, scene=self.scene(), colors=colors)
787 x=0, y=0, scene=self.scene(), colors=self.getDrawingColors()
788 )
789 itm.setPos(x, y) 809 itm.setPos(x, y)
790 itm.setId(itemId) 810 itm.setId(itemId)
791 umlItems[itemId] = itm 811 umlItems[itemId] = itm
792 if not itm.parseItemDataString(version, itemData): 812 if not itm.parseItemDataString(version, itemData):
793 return False, linenum 813 return False, linenum
847 from .ModuleItem import ModuleItem 867 from .ModuleItem import ModuleItem
848 from .PackageItem import PackageItem 868 from .PackageItem import PackageItem
849 from .UMLItem import UMLItem 869 from .UMLItem import UMLItem
850 870
851 umlItems = {} 871 umlItems = {}
872 colors = self.getDrawingColors(
873 drawingMode=Preferences.getGraphics("DrawingMode")
874 )
852 875
853 try: 876 try:
854 self.diagramName = data["diagram_name"] 877 self.diagramName = data["diagram_name"]
855 for itemData in data["items"]: 878 for itemData in data["items"]:
856 if itemData["type"] == UMLItem.ItemType: 879 if itemData["type"] == UMLItem.ItemType:
857 itm = UMLItem.fromDict(itemData, colors=self.getDrawingColors()) 880 itm = UMLItem.fromDict(itemData, colors=colors)
858 elif itemData["type"] == ClassItem.ItemType: 881 elif itemData["type"] == ClassItem.ItemType:
859 itm = ClassItem.fromDict(itemData, colors=self.getDrawingColors()) 882 itm = ClassItem.fromDict(itemData, colors=colors)
860 elif itemData["type"] == ModuleItem.ItemType: 883 elif itemData["type"] == ModuleItem.ItemType:
861 itm = ModuleItem.fromDict(itemData, colors=self.getDrawingColors()) 884 itm = ModuleItem.fromDict(itemData, colors=colors)
862 elif itemData["type"] == PackageItem.ItemType: 885 elif itemData["type"] == PackageItem.ItemType:
863 itm = PackageItem.fromDict(itemData, colors=self.getDrawingColors()) 886 itm = PackageItem.fromDict(itemData, colors=colors)
864 if itm is not None: 887 if itm is not None:
865 umlItems[itm.getId()] = itm 888 umlItems[itm.getId()] = itm
866 self.scene().addItem(itm) 889 self.scene().addItem(itm)
867 890
868 for assocData in data["associations"]: 891 for assocData in data["associations"]:
869 assoc = AssociationItem.fromDict( 892 assoc = AssociationItem.fromDict(assocData, umlItems, colors=colors)
870 assocData, umlItems, colors=self.getDrawingColors()
871 )
872 self.scene().addItem(assoc) 893 self.scene().addItem(assoc)
873 894
874 return True 895 return True
875 except KeyError: 896 except KeyError:
876 return False 897 return False

eric ide

mercurial