81 @type QGraphicsScene |
81 @type QGraphicsScene |
82 """ |
82 """ |
83 UMLItem.__init__(self, model, x, y, rounded, colors, parent) |
83 UMLItem.__init__(self, model, x, y, rounded, colors, parent) |
84 self.noModules = noModules |
84 self.noModules = noModules |
85 |
85 |
86 scene.addItem(self) |
86 if scene: |
|
87 scene.addItem(self) |
87 |
88 |
88 if self.model: |
89 if self.model: |
89 self.__createTexts() |
90 self.__createTexts() |
90 self.__calculateSize() |
91 self.__calculateSize() |
91 |
92 |
263 |
264 |
264 @return dictionary containing data to be persisted |
265 @return dictionary containing data to be persisted |
265 @rtype dict |
266 @rtype dict |
266 """ |
267 """ |
267 return { |
268 return { |
268 "name": self.model.getName(), |
269 "id": self.getId(), |
|
270 "x": self.x(), |
|
271 "y": self.y(), |
|
272 "type": self.getItemType(), |
|
273 "model_name": self.model.getName(), |
269 "no_nodules": self.noModules, |
274 "no_nodules": self.noModules, |
270 "modules": self.model.getModules(), |
275 "modules": self.model.getModules(), |
271 } |
276 } |
|
277 |
|
278 @classmethod |
|
279 def fromDict(cls, data, colors=None): |
|
280 """ |
|
281 Class method to create a class item from persisted data. |
|
282 |
|
283 @param data dictionary containing the persisted data as generated |
|
284 by toDict() |
|
285 @type dict |
|
286 @param colors tuple containing the foreground and background colors |
|
287 @type tuple of (QColor, QColor) |
|
288 @return created class item |
|
289 @rtype ClassItem |
|
290 """ |
|
291 try: |
|
292 model = PackageModel(data["model_name"], |
|
293 data["modules"]) |
|
294 itm = cls(model, |
|
295 x=0, |
|
296 y=0, |
|
297 noModules=data["no_nodules"], |
|
298 colors=colors) |
|
299 itm.setPos(data["x"], data["y"]) |
|
300 itm.setId(data["id"]) |
|
301 return itm |
|
302 except KeyError: |
|
303 return None |