Graphics/UMLClassDiagram.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
17 from .UMLDialog import UMLDialog 17 from .UMLDialog import UMLDialog
18 from .ClassItem import ClassItem, ClassModel 18 from .ClassItem import ClassItem, ClassModel
19 from .AssociationItem import AssociationItem, Generalisation 19 from .AssociationItem import AssociationItem, Generalisation
20 from . import GraphicsUtilities 20 from . import GraphicsUtilities
21 21
22
22 class UMLClassDiagram(UMLDialog): 23 class UMLClassDiagram(UMLDialog):
23 """ 24 """
24 Class implementing a dialog showing a UML like class diagram. 25 Class implementing a dialog showing a UML like class diagram.
25 """ 26 """
26 def __init__(self, file, parent = None, name = None, noAttrs = False): 27 def __init__(self, file, parent=None, name=None, noAttrs=False):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param file filename of a python module to be shown (string) 31 @param file filename of a python module to be shown (string)
31 @param parent parent widget of the view (QWidget) 32 @param parent parent widget of the view (QWidget)
129 ct = QGraphicsTextItem(None, self.scene) 130 ct = QGraphicsTextItem(None, self.scene)
130 ct.setHtml( 131 ct.setHtml(
131 self.trUtf8("The module <b>'{0}'</b> does not contain any classes.")\ 132 self.trUtf8("The module <b>'{0}'</b> does not contain any classes.")\
132 .format(self.file)) 133 .format(self.file))
133 134
134 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor = 1.2): 135 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
135 """ 136 """
136 Private method to arrange the shapes on the canvas. 137 Private method to arrange the shapes on the canvas.
137 138
138 The algorithm is borrowed from Boa Constructor. 139 The algorithm is borrowed from Boa Constructor.
139 """ 140 """
195 cw.setPos(x, y) 196 cw.setPos(x, y)
196 rect = cw.sceneBoundingRect() 197 rect = cw.sceneBoundingRect()
197 x = x + rect.width() + whiteSpace 198 x = x + rect.width() + whiteSpace
198 y = y + currentHeight + verticalWhiteSpace 199 y = y + currentHeight + verticalWhiteSpace
199 200
200 def __addLocalClass(self, className, _class, x, y, isRbModule = False): 201 def __addLocalClass(self, className, _class, x, y, isRbModule=False):
201 """ 202 """
202 Private method to add a class defined in the module. 203 Private method to add a class defined in the module.
203 204
204 @param className name of the class to be as a dictionary key (string) 205 @param className name of the class to be as a dictionary key (string)
205 @param _class class to be shown (ModuleParser.Class) 206 @param _class class to be shown (ModuleParser.Class)
211 attrs = sorted(_class.attributes.keys()) 212 attrs = sorted(_class.attributes.keys())
212 name = _class.name 213 name = _class.name
213 if isRbModule: 214 if isRbModule:
214 name = "{0} (Module)".format(name) 215 name = "{0} (Module)".format(name)
215 cl = ClassModel(name, meths[:], attrs[:]) 216 cl = ClassModel(name, meths[:], attrs[:])
216 cw = ClassItem(cl, False, x, y, noAttrs = self.noAttrs, scene = self.scene) 217 cw = ClassItem(cl, False, x, y, noAttrs=self.noAttrs, scene=self.scene)
217 self.allClasses[className] = cw 218 self.allClasses[className] = cw
218 if _class.name not in self.allModules[self.file]: 219 if _class.name not in self.allModules[self.file]:
219 self.allModules[self.file].append(_class.name) 220 self.allModules[self.file].append(_class.name)
220 221
221 def __addExternalClass(self, _class, x, y): 222 def __addExternalClass(self, _class, x, y):
228 @param _class class to be shown (string) 229 @param _class class to be shown (string)
229 @param x x-coordinate (float) 230 @param x x-coordinate (float)
230 @param y y-coordinate (float) 231 @param y y-coordinate (float)
231 """ 232 """
232 cl = ClassModel(_class) 233 cl = ClassModel(_class)
233 cw = ClassItem(cl, True, x, y, noAttrs = self.noAttrs, scene = self.scene) 234 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene)
234 self.allClasses[_class] = cw 235 self.allClasses[_class] = cw
235 if _class not in self.allModules[self.file]: 236 if _class not in self.allModules[self.file]:
236 self.allModules[self.file].append(_class) 237 self.allModules[self.file].append(_class)
237 238
238 def __createAssociations(self, routes): 239 def __createAssociations(self, routes):

eric ide

mercurial