23 """ |
23 """ |
24 def __init__(self, dialog, view, project, file, noAttrs=False): |
24 def __init__(self, dialog, view, project, file, noAttrs=False): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param dialog reference to the UML dialog (UMLDialog) |
28 @param dialog reference to the UML dialog |
29 @param view reference to the view object (UMLGraphicsView) |
29 @type UMLDialog |
30 @param project reference to the project object (Project) |
30 @param view reference to the view object |
31 @param file file name of a python module to be shown (string) |
31 @type UMLGraphicsView |
|
32 @param project reference to the project object |
|
33 @type Project |
|
34 @param file file name of a python module to be shown |
|
35 @type str |
32 @param noAttrs flag indicating, that no attributes should be shown |
36 @param noAttrs flag indicating, that no attributes should be shown |
33 (boolean) |
37 @type bool |
34 """ |
38 """ |
35 super().__init__(dialog, view, project) |
39 super().__init__(dialog, view, project) |
36 self.setObjectName("UMLClassDiagramBuilder") |
40 self.setObjectName("UMLClassDiagramBuilder") |
37 |
41 |
38 self.file = file |
42 self.file = file |
53 |
57 |
54 def __getCurrentShape(self, name): |
58 def __getCurrentShape(self, name): |
55 """ |
59 """ |
56 Private method to get the named shape. |
60 Private method to get the named shape. |
57 |
61 |
58 @param name name of the shape (string) |
62 @param name name of the shape |
59 @return shape (QGraphicsItem) |
63 @type str |
|
64 @return shape |
|
65 @rtype QGraphicsItem |
60 """ |
66 """ |
61 return self.allClasses.get(name) |
67 return self.allClasses.get(name) |
62 |
68 |
63 def buildDiagram(self): |
69 def buildDiagram(self): |
64 """ |
70 """ |
152 Private method to arrange the shapes on the canvas. |
158 Private method to arrange the shapes on the canvas. |
153 |
159 |
154 The algorithm is borrowed from Boa Constructor. |
160 The algorithm is borrowed from Boa Constructor. |
155 |
161 |
156 @param nodes list of nodes to arrange |
162 @param nodes list of nodes to arrange |
|
163 @type list of str |
157 @param routes list of routes |
164 @param routes list of routes |
|
165 @type list of tuple of (str, str) |
158 @param whiteSpaceFactor factor to increase whitespace between |
166 @param whiteSpaceFactor factor to increase whitespace between |
159 items (float) |
167 items |
|
168 @type float |
160 """ |
169 """ |
161 from . import GraphicsUtilities |
170 from . import GraphicsUtilities |
162 generations = GraphicsUtilities.sort(nodes, routes) |
171 generations = GraphicsUtilities.sort(nodes, routes) |
163 |
172 |
164 # calculate width and height of all elements |
173 # calculate width and height of all elements |
225 |
234 |
226 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
235 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
227 """ |
236 """ |
228 Private method to add a class defined in the module. |
237 Private method to add a class defined in the module. |
229 |
238 |
230 @param className name of the class to be as a dictionary key (string) |
239 @param className name of the class to be as a dictionary key |
231 @param _class class to be shown (ModuleParser.Class) |
240 @type str |
232 @param x x-coordinate (float) |
241 @param _class class to be shown |
233 @param y y-coordinate (float) |
242 @type ModuleParser.Class |
234 @param isRbModule flag indicating a Ruby module (boolean) |
243 @param x x-coordinate |
|
244 @type float |
|
245 @param y y-coordinate |
|
246 @type float |
|
247 @param isRbModule flag indicating a Ruby module |
|
248 @type bool |
235 """ |
249 """ |
236 from .ClassItem import ClassItem, ClassModel |
250 from .ClassItem import ClassItem, ClassModel |
237 name = _class.name |
251 name = _class.name |
238 if isRbModule: |
252 if isRbModule: |
239 name = "{0} (Module)".format(name) |
253 name = "{0} (Module)".format(name) |
255 Private method to add a class defined outside the module. |
269 Private method to add a class defined outside the module. |
256 |
270 |
257 If the canvas is too small to take the shape, it |
271 If the canvas is too small to take the shape, it |
258 is enlarged. |
272 is enlarged. |
259 |
273 |
260 @param _class class to be shown (string) |
274 @param _class class to be shown |
261 @param x x-coordinate (float) |
275 @type ModuleParser.Class |
262 @param y y-coordinate (float) |
276 @param x x-coordinate |
|
277 @type float |
|
278 @param y y-coordinate |
|
279 @type float |
263 """ |
280 """ |
264 from .ClassItem import ClassItem, ClassModel |
281 from .ClassItem import ClassItem, ClassModel |
265 cl = ClassModel(_class) |
282 cl = ClassModel(_class) |
266 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene, |
283 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene, |
267 colors=self.umlView.getDrawingColors()) |
284 colors=self.umlView.getDrawingColors()) |
273 def __createAssociations(self, routes): |
290 def __createAssociations(self, routes): |
274 """ |
291 """ |
275 Private method to generate the associations between the class shapes. |
292 Private method to generate the associations between the class shapes. |
276 |
293 |
277 @param routes list of relationsships |
294 @param routes list of relationsships |
|
295 @type list of tuple of (str, str) |
278 """ |
296 """ |
279 from .AssociationItem import AssociationItem, AssociationType |
297 from .AssociationItem import AssociationItem, AssociationType |
280 for route in routes: |
298 for route in routes: |
281 if len(route) > 1: |
299 if len(route) > 1: |
282 assoc = AssociationItem( |
300 assoc = AssociationItem( |
289 |
307 |
290 def getPersistenceData(self): |
308 def getPersistenceData(self): |
291 """ |
309 """ |
292 Public method to get a string for data to be persisted. |
310 Public method to get a string for data to be persisted. |
293 |
311 |
294 @return persisted data string (string) |
312 @return persisted data string |
|
313 @rtype str |
295 """ |
314 """ |
296 return "file={0}, no_attributes={1}".format(self.file, self.noAttrs) |
315 return "file={0}, no_attributes={1}".format(self.file, self.noAttrs) |
297 |
316 |
298 def parsePersistenceData(self, version, data): |
317 def parsePersistenceData(self, version, data): |
299 """ |
318 """ |
300 Public method to parse persisted data. |
319 Public method to parse persisted data. |
301 |
320 |
302 @param version version of the data (string) |
321 @param version version of the data |
303 @param data persisted data to be parsed (string) |
322 @type str |
304 @return flag indicating success (boolean) |
323 @param data persisted data to be parsed |
|
324 @type str |
|
325 @return flag indicating success |
|
326 @rtype bool |
305 """ |
327 """ |
306 parts = data.split(", ") |
328 parts = data.split(", ") |
307 if ( |
329 if ( |
308 len(parts) != 2 or |
330 len(parts) != 2 or |
309 not parts[0].startswith("file=") or |
331 not parts[0].startswith("file=") or |