27 """ |
27 """ |
28 def __init__(self, dialog, view, project, package, noAttrs=False): |
28 def __init__(self, dialog, view, project, package, noAttrs=False): |
29 """ |
29 """ |
30 Constructor |
30 Constructor |
31 |
31 |
32 @param dialog reference to the UML dialog (UMLDialog) |
32 @param dialog reference to the UML dialog |
33 @param view reference to the view object (UMLGraphicsView) |
33 @type UMLDialog |
34 @param project reference to the project object (Project) |
34 @param view reference to the view object |
35 @param package name of a python package to be shown (string) |
35 @type UMLGraphicsView |
|
36 @param project reference to the project object |
|
37 @type Project |
|
38 @param package name of a python package to be shown |
|
39 @type str |
36 @param noAttrs flag indicating, that no attributes should be shown |
40 @param noAttrs flag indicating, that no attributes should be shown |
37 (boolean) |
41 @type bool |
38 """ |
42 """ |
39 super().__init__(dialog, view, project) |
43 super().__init__(dialog, view, project) |
40 self.setObjectName("PackageDiagram") |
44 self.setObjectName("PackageDiagram") |
41 |
45 |
42 self.package = os.path.abspath(package) |
46 self.package = os.path.abspath(package) |
57 |
61 |
58 def __getCurrentShape(self, name): |
62 def __getCurrentShape(self, name): |
59 """ |
63 """ |
60 Private method to get the named shape. |
64 Private method to get the named shape. |
61 |
65 |
62 @param name name of the shape (string) |
66 @param name name of the shape |
63 @return shape (QCanvasItem) |
67 @type str |
|
68 @return shape |
|
69 @rtype QCanvasItem |
64 """ |
70 """ |
65 return self.allClasses.get(name) |
71 return self.allClasses.get(name) |
66 |
72 |
67 def __buildModulesDict(self): |
73 def __buildModulesDict(self): |
68 """ |
74 """ |
69 Private method to build a dictionary of modules contained in the |
75 Private method to build a dictionary of modules contained in the |
70 package. |
76 package. |
71 |
77 |
72 @return dictionary of modules contained in the package. |
78 @return dictionary of modules contained in the package |
|
79 @rtype dict |
73 """ |
80 """ |
74 import Utilities.ModuleParser |
81 import Utilities.ModuleParser |
75 |
82 |
76 supportedExt = ( |
83 supportedExt = ( |
77 ['*{0}'.format(ext) for ext in |
84 ['*{0}'.format(ext) for ext in |
296 Private method to arrange the shapes on the canvas. |
304 Private method to arrange the shapes on the canvas. |
297 |
305 |
298 The algorithm is borrowed from Boa Constructor. |
306 The algorithm is borrowed from Boa Constructor. |
299 |
307 |
300 @param nodes list of nodes to arrange |
308 @param nodes list of nodes to arrange |
|
309 @type list of str |
301 @param routes list of routes |
310 @param routes list of routes |
|
311 @type list of tuple of (str, str) |
302 @param whiteSpaceFactor factor to increase whitespace between |
312 @param whiteSpaceFactor factor to increase whitespace between |
303 items (float) |
313 items |
|
314 @type float |
304 """ |
315 """ |
305 from . import GraphicsUtilities |
316 from . import GraphicsUtilities |
306 generations = GraphicsUtilities.sort(nodes, routes) |
317 generations = GraphicsUtilities.sort(nodes, routes) |
307 |
318 |
308 # calculate width and height of all elements |
319 # calculate width and height of all elements |
369 |
380 |
370 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
381 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
371 """ |
382 """ |
372 Private method to add a class defined in the module. |
383 Private method to add a class defined in the module. |
373 |
384 |
374 @param className name of the class to be as a dictionary key (string) |
385 @param className name of the class to be as a dictionary key |
375 @param _class class to be shown (ModuleParser.Class) |
386 @type str |
376 @param x x-coordinate (float) |
387 @param _class class to be shown |
377 @param y y-coordinate (float) |
388 @type ModuleParser.Class |
378 @param isRbModule flag indicating a Ruby module (boolean) |
389 @param x x-coordinate |
|
390 @type float |
|
391 @param y y-coordinate |
|
392 @type float |
|
393 @param isRbModule flag indicating a Ruby module |
|
394 @type bool |
379 """ |
395 """ |
380 from .ClassItem import ClassItem, ClassModel |
396 from .ClassItem import ClassItem, ClassModel |
381 name = _class.name |
397 name = _class.name |
382 if isRbModule: |
398 if isRbModule: |
383 name = "{0} (Module)".format(name) |
399 name = "{0} (Module)".format(name) |
397 Private method to add a class defined outside the module. |
413 Private method to add a class defined outside the module. |
398 |
414 |
399 If the canvas is too small to take the shape, it |
415 If the canvas is too small to take the shape, it |
400 is enlarged. |
416 is enlarged. |
401 |
417 |
402 @param _class class to be shown (string) |
418 @param _class class to be shown |
403 @param x x-coordinate (float) |
419 @type ModuleParser.Class |
404 @param y y-coordinate (float) |
420 @param x x-coordinate |
|
421 @type float |
|
422 @param y y-coordinate |
|
423 @type float |
405 """ |
424 """ |
406 from .ClassItem import ClassItem, ClassModel |
425 from .ClassItem import ClassItem, ClassModel |
407 cl = ClassModel(_class) |
426 cl = ClassModel(_class) |
408 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene, |
427 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene, |
409 colors=self.umlView.getDrawingColors()) |
428 colors=self.umlView.getDrawingColors()) |
412 |
431 |
413 def __addPackage(self, name, modules, x, y): |
432 def __addPackage(self, name, modules, x, y): |
414 """ |
433 """ |
415 Private method to add a package to the diagram. |
434 Private method to add a package to the diagram. |
416 |
435 |
417 @param name package name to be shown (string) |
436 @param name package name to be shown |
|
437 @type str |
418 @param modules list of module names contained in the package |
438 @param modules list of module names contained in the package |
419 (list of strings) |
439 @type list of str |
420 @param x x-coordinate (float) |
440 @param x x-coordinate |
421 @param y y-coordinate (float) |
441 @type float |
|
442 @param y y-coordinate |
|
443 @type float |
422 """ |
444 """ |
423 from .PackageItem import PackageItem, PackageModel |
445 from .PackageItem import PackageItem, PackageModel |
424 pm = PackageModel(name, modules) |
446 pm = PackageModel(name, modules) |
425 pw = PackageItem(pm, x, y, scene=self.scene, |
447 pw = PackageItem(pm, x, y, scene=self.scene, |
426 colors=self.umlView.getDrawingColors()) |
448 colors=self.umlView.getDrawingColors()) |
430 def __createAssociations(self, routes): |
452 def __createAssociations(self, routes): |
431 """ |
453 """ |
432 Private method to generate the associations between the class shapes. |
454 Private method to generate the associations between the class shapes. |
433 |
455 |
434 @param routes list of relationsships |
456 @param routes list of relationsships |
|
457 @type list of tuple of (str, str) |
435 """ |
458 """ |
436 from .AssociationItem import AssociationItem, AssociationType |
459 from .AssociationItem import AssociationItem, AssociationType |
437 for route in routes: |
460 for route in routes: |
438 if len(route) > 1: |
461 if len(route) > 1: |
439 assoc = AssociationItem( |
462 assoc = AssociationItem( |
446 |
469 |
447 def getPersistenceData(self): |
470 def getPersistenceData(self): |
448 """ |
471 """ |
449 Public method to get a string for data to be persisted. |
472 Public method to get a string for data to be persisted. |
450 |
473 |
451 @return persisted data string (string) |
474 @return persisted data string |
|
475 @rtype str |
452 """ |
476 """ |
453 return "package={0}, no_attributes={1}".format( |
477 return "package={0}, no_attributes={1}".format( |
454 self.package, self.noAttrs) |
478 self.package, self.noAttrs) |
455 |
479 |
456 def parsePersistenceData(self, version, data): |
480 def parsePersistenceData(self, version, data): |
457 """ |
481 """ |
458 Public method to parse persisted data. |
482 Public method to parse persisted data. |
459 |
483 |
460 @param version version of the data (string) |
484 @param version version of the data |
461 @param data persisted data to be parsed (string) |
485 @type str |
462 @return flag indicating success (boolean) |
486 @param data persisted data to be parsed |
|
487 @type str |
|
488 @return flag indicating success |
|
489 @rtype bool |
463 """ |
490 """ |
464 parts = data.split(", ") |
491 parts = data.split(", ") |
465 if ( |
492 if ( |
466 len(parts) != 2 or |
493 len(parts) != 2 or |
467 not parts[0].startswith("package=") or |
494 not parts[0].startswith("package=") or |