7 Module implementing an UML like class item. |
7 Module implementing an UML like class item. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtGui import QFont, QGraphicsSimpleTextItem, QStyle |
10 from PyQt4.QtGui import QFont, QGraphicsSimpleTextItem, QStyle |
11 |
11 |
12 from .UMLItem import UMLItem |
12 from .UMLItem import UMLModel, UMLItem |
13 |
13 |
14 import Utilities |
14 import Utilities |
15 |
15 |
16 |
16 |
17 class ClassModel(object): |
17 class ClassModel(UMLModel): |
18 """ |
18 """ |
19 Class implementing the class model. |
19 Class implementing the class model. |
20 """ |
20 """ |
21 def __init__(self, name, methods=[], attributes=[]): |
21 def __init__(self, name, methods=[], attributes=[]): |
22 """ |
22 """ |
26 @param methods list of method names of the class |
26 @param methods list of method names of the class |
27 (list of strings) |
27 (list of strings) |
28 @param attributes list of attribute names of the class |
28 @param attributes list of attribute names of the class |
29 (list of strings) |
29 (list of strings) |
30 """ |
30 """ |
31 self.name = name |
31 super().__init__(name) |
|
32 |
32 self.methods = methods |
33 self.methods = methods |
33 self.attributes = attributes |
34 self.attributes = attributes |
34 |
35 |
35 def addMethod(self, method): |
36 def addMethod(self, method): |
36 """ |
37 """ |
37 Method to add a method to the class model. |
38 Method to add a method to the class model. |
38 |
39 |
39 @param method method name to be added (string) |
40 @param method method name to be added (string) |
40 """ |
41 """ |
41 self.methods.append(method) |
42 self.methods.append(method) |
42 |
43 |
43 def addAttribute(self, attribute): |
44 def addAttribute(self, attribute): |
44 """ |
45 """ |
45 Method to add an attribute to the class model. |
46 Method to add an attribute to the class model. |
46 |
47 |
47 @param attribute attribute name to be added (string) |
48 @param attribute attribute name to be added (string) |
48 """ |
49 """ |
49 self.attributes.append(attribute) |
50 self.attributes.append(attribute) |
50 |
51 |
51 def getMethods(self): |
52 def getMethods(self): |
52 """ |
53 """ |
53 Method to retrieve the methods of the class. |
54 Method to retrieve the methods of the class. |
54 |
55 |
55 @return list of class methods (list of strings) |
56 @return list of class methods (list of strings) |
56 """ |
57 """ |
57 return self.methods[:] |
58 return self.methods[:] |
58 |
59 |
59 def getAttributes(self): |
60 def getAttributes(self): |
60 """ |
61 """ |
61 Method to retrieve the attributes of the class. |
62 Method to retrieve the attributes of the class. |
62 |
63 |
63 @return list of class attributes (list of strings) |
64 @return list of class attributes (list of strings) |
64 """ |
65 """ |
65 return self.attributes[:] |
66 return self.attributes[:] |
66 |
|
67 def getName(self): |
|
68 """ |
|
69 Method to retrieve the class name. |
|
70 |
|
71 @return class name (string) |
|
72 """ |
|
73 return self.name |
|
74 |
67 |
75 |
68 |
76 class ClassItem(UMLItem): |
69 class ClassItem(UMLItem): |
77 """ |
70 """ |
78 Class implementing an UML like class item. |
71 Class implementing an UML like class item. |
91 @keyparam rounded flag indicating a rounded corner (boolean) |
84 @keyparam rounded flag indicating a rounded corner (boolean) |
92 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean) |
85 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean) |
93 @keyparam parent reference to the parent object (QGraphicsItem) |
86 @keyparam parent reference to the parent object (QGraphicsItem) |
94 @keyparam scene reference to the scene object (QGraphicsScene) |
87 @keyparam scene reference to the scene object (QGraphicsScene) |
95 """ |
88 """ |
96 UMLItem.__init__(self, x, y, rounded, parent) |
89 UMLItem.__init__(self, model, x, y, rounded, parent) |
97 self.model = model |
90 |
98 self.external = external |
91 self.external = external |
99 self.noAttrs = noAttrs |
92 self.noAttrs = noAttrs |
100 |
93 |
101 scene.addItem(self) |
94 scene.addItem(self) |
102 |
95 |