5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog showing UML like diagrams. |
7 Module implementing a dialog showing UML like diagrams. |
8 """ |
8 """ |
9 |
9 |
|
10 import enum |
|
11 |
10 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo |
12 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo |
11 from PyQt5.QtWidgets import QAction, QToolBar, QGraphicsScene |
13 from PyQt5.QtWidgets import QAction, QToolBar, QGraphicsScene |
12 |
14 |
13 from E5Gui import E5MessageBox, E5FileDialog |
15 from E5Gui import E5MessageBox, E5FileDialog |
14 from E5Gui.E5MainWindow import E5MainWindow |
16 from E5Gui.E5MainWindow import E5MainWindow |
15 |
17 |
16 import UI.Config |
18 import UI.Config |
17 import UI.PixmapCache |
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class UMLDialogType(enum.Enum): |
|
23 """ |
|
24 Class defining the UML dialog types. |
|
25 """ |
|
26 CLASS_DIAGRAM = 0 |
|
27 PACKAGE_DIAGRAM = 1 |
|
28 IMPORTS_DIAGRAM = 2 |
|
29 APPLICATION_DIAGRAM = 3 |
|
30 NO_DIAGRAM = 255 |
18 |
31 |
19 |
32 |
20 class UMLDialog(E5MainWindow): |
33 class UMLDialog(E5MainWindow): |
21 """ |
34 """ |
22 Class implementing a dialog showing UML like diagrams. |
35 Class implementing a dialog showing UML like diagrams. |
23 """ |
36 """ |
24 # convert to Enum |
37 FileVersions = ("1.0") |
25 NoDiagram = 255 |
|
26 ClassDiagram = 0 |
|
27 PackageDiagram = 1 |
|
28 ImportsDiagram = 2 |
|
29 ApplicationDiagram = 3 |
|
30 |
|
31 FileVersions = ["1.0"] |
|
32 |
38 |
33 def __init__(self, diagramType, project, path="", parent=None, |
39 def __init__(self, diagramType, project, path="", parent=None, |
34 initBuilder=True, **kwargs): |
40 initBuilder=True, **kwargs): |
35 """ |
41 """ |
36 Constructor |
42 Constructor |
37 |
43 |
38 @param diagramType type of the diagram (one of ApplicationDiagram, |
44 @param diagramType type of the diagram |
39 ClassDiagram, ImportsDiagram, NoDiagram, PackageDiagram) |
45 @type UMLDialogType |
40 @param project reference to the project object (Project) |
46 @param project reference to the project object |
41 @param path file or directory path to build the diagram from (string) |
47 @type Project |
42 @param parent parent widget of the dialog (QWidget) |
48 @param path file or directory path to build the diagram from |
|
49 @type str |
|
50 @param parent parent widget of the dialog |
|
51 @type QWidget |
43 @param initBuilder flag indicating to initialize the diagram |
52 @param initBuilder flag indicating to initialize the diagram |
44 builder (boolean) |
53 builder |
|
54 @type bool |
45 @keyparam kwargs diagram specific data |
55 @keyparam kwargs diagram specific data |
|
56 @type dict |
46 """ |
57 """ |
47 super().__init__(parent) |
58 super().__init__(parent) |
48 self.setObjectName("UMLDialog") |
59 self.setObjectName("UMLDialog") |
49 |
60 |
50 self.__project = project |
61 self.__project = project |
51 self.__diagramType = diagramType |
62 self.__diagramType = diagramType |
52 self.__diagramTypeString = { |
63 self.__diagramTypeString = { |
53 UMLDialog.ClassDiagram: "Class Diagram", |
64 UMLDialogType.CLASS_DIAGRAM: "Class Diagram", |
54 UMLDialog.PackageDiagram: "Package Diagram", |
65 UMLDialogType.PACKAGE_DIAGRAM: "Package Diagram", |
55 UMLDialog.ImportsDiagram: "Imports Diagram", |
66 UMLDialogType.IMPORTS_DIAGRAM: "Imports Diagram", |
56 UMLDialog.ApplicationDiagram: "Application Diagram", |
67 UMLDialogType.APPLICATION_DIAGRAM: "Application Diagram", |
57 }.get(diagramType, "Illegal Diagram Type") |
68 }.get(diagramType, "Illegal Diagram Type") |
58 |
69 |
59 from .UMLGraphicsView import UMLGraphicsView |
70 from .UMLGraphicsView import UMLGraphicsView |
60 self.scene = QGraphicsScene(0.0, 0.0, 800.0, 600.0) |
71 self.scene = QGraphicsScene(0.0, 0.0, 800.0, 600.0) |
61 self.umlView = UMLGraphicsView(self.scene, parent=self) |
72 self.umlView = UMLGraphicsView(self.scene, parent=self) |
161 def __diagramBuilder(self, diagramType, path, **kwargs): |
172 def __diagramBuilder(self, diagramType, path, **kwargs): |
162 """ |
173 """ |
163 Private method to instantiate a diagram builder object. |
174 Private method to instantiate a diagram builder object. |
164 |
175 |
165 @param diagramType type of the diagram |
176 @param diagramType type of the diagram |
166 (one of ApplicationDiagram, ClassDiagram, ImportsDiagram, |
177 @type UMLDialogType |
167 PackageDiagram) |
178 @param path file or directory path to build the diagram from |
168 @param path file or directory path to build the diagram from (string) |
179 @type str |
169 @keyparam kwargs diagram specific data |
180 @keyparam kwargs diagram specific data |
|
181 @type dict |
170 @return reference to the instantiated diagram builder |
182 @return reference to the instantiated diagram builder |
171 @exception ValueError raised to indicate an illegal diagram type |
183 @rtype UMLDiagramBuilder |
172 """ |
184 """ |
173 if diagramType not in ( |
185 if diagramType == UMLDialogType.CLASS_DIAGRAM: |
174 UMLDialog.ClassDiagram, UMLDialog.PackageDiagram, |
|
175 UMLDialog.ImportsDiagram, UMLDialog.ApplicationDiagram, |
|
176 UMLDialog.NoDiagram |
|
177 ): |
|
178 raise ValueError(self.tr( |
|
179 "Illegal diagram type '{0}' given.").format(diagramType)) |
|
180 |
|
181 if diagramType == UMLDialog.ClassDiagram: |
|
182 from .UMLClassDiagramBuilder import UMLClassDiagramBuilder |
186 from .UMLClassDiagramBuilder import UMLClassDiagramBuilder |
183 return UMLClassDiagramBuilder( |
187 return UMLClassDiagramBuilder( |
184 self, self.umlView, self.__project, path, **kwargs) |
188 self, self.umlView, self.__project, path, **kwargs) |
185 elif diagramType == UMLDialog.PackageDiagram: |
189 elif diagramType == UMLDialogType.PACKAGE_DIAGRAM: |
186 from .PackageDiagramBuilder import PackageDiagramBuilder |
190 from .PackageDiagramBuilder import PackageDiagramBuilder |
187 return PackageDiagramBuilder( |
191 return PackageDiagramBuilder( |
188 self, self.umlView, self.__project, path, **kwargs) |
192 self, self.umlView, self.__project, path, **kwargs) |
189 elif diagramType == UMLDialog.ImportsDiagram: |
193 elif diagramType == UMLDialogType.IMPORTS_DIAGRAM: |
190 from .ImportsDiagramBuilder import ImportsDiagramBuilder |
194 from .ImportsDiagramBuilder import ImportsDiagramBuilder |
191 return ImportsDiagramBuilder( |
195 return ImportsDiagramBuilder( |
192 self, self.umlView, self.__project, path, **kwargs) |
196 self, self.umlView, self.__project, path, **kwargs) |
193 elif diagramType == UMLDialog.ApplicationDiagram: |
197 elif diagramType == UMLDialogType.APPLICATION_DIAGRAM: |
194 from .ApplicationDiagramBuilder import ApplicationDiagramBuilder |
198 from .ApplicationDiagramBuilder import ApplicationDiagramBuilder |
195 return ApplicationDiagramBuilder( |
199 return ApplicationDiagramBuilder( |
196 self, self.umlView, self.__project, **kwargs) |
200 self, self.umlView, self.__project, **kwargs) |
197 else: |
201 else: |
198 return None |
202 return None |
316 if key.strip() != "diagram_type": |
320 if key.strip() != "diagram_type": |
317 self.__showInvalidDataMessage(filename, linenum) |
321 self.__showInvalidDataMessage(filename, linenum) |
318 return False |
322 return False |
319 try: |
323 try: |
320 diagramType, diagramTypeString = value.strip().split(None, 1) |
324 diagramType, diagramTypeString = value.strip().split(None, 1) |
321 self.__diagramType = int(self.__diagramType) |
325 self.__diagramType = UMLDialogType(int(self.__diagramType)) |
322 self.__diagramTypeString = diagramTypeString[1:-1] |
326 self.__diagramTypeString = diagramTypeString[1:-1] |
323 # remove opening an closing bracket |
327 # remove opening an closing bracket |
324 except ValueError: |
328 except ValueError: |
325 self.__showInvalidDataMessage(filename, linenum) |
329 self.__showInvalidDataMessage(filename, linenum) |
326 return False |
330 return False |