18 |
18 |
19 class UMLDialog(QMainWindow): |
19 class UMLDialog(QMainWindow): |
20 """ |
20 """ |
21 Class implementing a dialog showing UML like diagrams. |
21 Class implementing a dialog showing UML like diagrams. |
22 """ |
22 """ |
23 def __init__(self, diagramType, diagramName="Unnamed", buildFunction=None, |
23 ClassDiagram = 0 |
24 parent=None, name=""): |
24 PackageDiagram = 1 |
|
25 ImportsDiagram = 2 |
|
26 ApplicationDiagram = 3 |
|
27 |
|
28 def __init__(self, diagramType, project, path, parent=None, **kwargs): |
25 """ |
29 """ |
26 Constructor |
30 Constructor |
27 |
31 |
28 @param diagramType type of the diagram (string) |
32 @param diagramType type of the diagram |
29 @param diagramName name of the diagram (string) |
33 (one of ApplicationDiagram, ClassDiagram, ImportsDiagram, PackageDiagram) |
30 @param buildFunction function to build the diagram contents (function) |
34 @param project reference to the project object (Project) |
|
35 @param path file or directory path to build the diagram from (string) |
31 @param parent parent widget of the view (QWidget) |
36 @param parent parent widget of the view (QWidget) |
32 @param name name of the view widget (string) |
37 @param kwargs diagram specific data |
33 """ |
38 """ |
34 super().__init__(parent) |
39 super().__init__(parent) |
|
40 self.setObjectName("UMLDialog") |
35 |
41 |
36 if not name: |
|
37 self.setObjectName("UMLDialog") |
|
38 else: |
|
39 self.setObjectName(name) |
|
40 |
|
41 self.buildFunction = buildFunction |
|
42 self.scene = QGraphicsScene(0.0, 0.0, 800.0, 600.0) |
42 self.scene = QGraphicsScene(0.0, 0.0, 800.0, 600.0) |
43 self.umlView = UMLGraphicsView(self.scene, diagramType, diagramName, |
43 self.umlView = UMLGraphicsView(self.scene, diagramType, parent=self) |
44 self, "umlView") |
44 self.builder = self.__diagramBuilder(diagramType, project, path, **kwargs) |
45 |
45 |
46 self.closeAct = \ |
46 self.closeAct = \ |
47 QAction(UI.PixmapCache.getIcon("close.png"), |
47 QAction(UI.PixmapCache.getIcon("close.png"), |
48 self.trUtf8("Close"), self) |
48 self.trUtf8("Close"), self) |
49 self.closeAct.triggered[()].connect(self.close) |
49 self.closeAct.triggered[()].connect(self.close) |
56 |
56 |
57 self.addToolBar(Qt.TopToolBarArea, self.windowToolBar) |
57 self.addToolBar(Qt.TopToolBarArea, self.windowToolBar) |
58 self.addToolBar(Qt.TopToolBarArea, self.umlToolBar) |
58 self.addToolBar(Qt.TopToolBarArea, self.umlToolBar) |
59 |
59 |
60 self.setCentralWidget(self.umlView) |
60 self.setCentralWidget(self.umlView) |
61 |
|
62 def setDiagramName(self, name): |
|
63 """ |
|
64 Public slot to set the diagram name. |
|
65 |
61 |
66 @param name diagram name (string) |
62 self.umlView.relayout.connect(self.__relayout) |
67 """ |
|
68 self.umlView.setDiagramName(name) |
|
69 |
63 |
70 def show(self): |
64 def show(self): |
71 """ |
65 """ |
72 Overriden method to show the dialog. |
66 Overriden method to show the dialog. |
73 """ |
67 """ |
74 if self.buildFunction: |
68 self.builder.buildDiagram() |
75 self.buildFunction() |
|
76 super().show() |
69 super().show() |
|
70 |
|
71 def __relayout(self): |
|
72 """ |
|
73 Private method to relayout the diagram. |
|
74 """ |
|
75 self.builder.buildDiagram() |
|
76 |
|
77 def __diagramBuilder(self, diagramType, project, path, **kwargs): |
|
78 """ |
|
79 Private method to instantiate a diagram builder object. |
|
80 |
|
81 @param diagramType type of the diagram |
|
82 (one of ApplicationDiagram, ClassDiagram, ImportsDiagram, PackageDiagram) |
|
83 @param project reference to the project object (Project) |
|
84 @param path file or directory path to build the diagram from (string) |
|
85 @param kwargs diagram specific data |
|
86 """ |
|
87 if diagramType == UMLDialog.ClassDiagram: |
|
88 from .UMLClassDiagramBuilder import UMLClassDiagramBuilder |
|
89 return UMLClassDiagramBuilder(self, self.umlView, project, path, **kwargs) |
|
90 elif diagramType == UMLDialog.PackageDiagram: |
|
91 from .PackageDiagramBuilder import PackageDiagramBuilder |
|
92 return PackageDiagramBuilder(self, self.umlView, project, path, **kwargs) |
|
93 elif diagramType == UMLDialog.ImportsDiagram: |
|
94 from .ImportsDiagramBuilder import ImportsDiagramBuilder |
|
95 return ImportsDiagramBuilder(self, self.umlView, project, path, **kwargs) |
|
96 elif diagramType == UMLDialog.ApplicationDiagram: |
|
97 from .ApplicationDiagramBuilder import ApplicationDiagramBuilder |
|
98 return ApplicationDiagramBuilder(self, self.umlView, project, **kwargs) |
|
99 else: |
|
100 raise ValueError( |
|
101 self.trUtf8("Illegal diagram type '{0}' given.").format(diagramType)) |
|
102 |
|
103 def diagramTypeToString(self, diagramType): |
|
104 """ |
|
105 Public method to convert the diagram type to a readable string. |
|
106 |
|
107 @param diagramType type of the diagram |
|
108 (one of ApplicationDiagram, ClassDiagram, ImportsDiagram, PackageDiagram) |
|
109 @return readable type string (string) |
|
110 """ |
|
111 if diagramType == UMLDialog.ClassDiagram: |
|
112 return "Class Diagram" |
|
113 elif diagramType == UMLDialog.PackageDiagram: |
|
114 return "Package Diagram" |
|
115 elif diagramType == UMLDialog.ImportsDiagram: |
|
116 return "Imports Diagram" |
|
117 elif diagramType == UMLDialog.ApplicationDiagram: |
|
118 return "Application Diagram" |
|
119 else: |
|
120 return "Illegal Diagram Type" |