137 UMLItem.__init__(self, model, x, y, rounded, colors, parent) |
137 UMLItem.__init__(self, model, x, y, rounded, colors, parent) |
138 |
138 |
139 self.external = external |
139 self.external = external |
140 self.noAttrs = noAttrs |
140 self.noAttrs = noAttrs |
141 |
141 |
142 scene.addItem(self) |
142 if scene: |
|
143 scene.addItem(self) |
143 |
144 |
144 if self.model: |
145 if self.model: |
145 self.__createTexts() |
146 self.__createTexts() |
146 self.__calculateSize() |
147 self.__calculateSize() |
147 |
148 |
396 |
397 |
397 @return dictionary containing data to be persisted |
398 @return dictionary containing data to be persisted |
398 @rtype dict |
399 @rtype dict |
399 """ |
400 """ |
400 return { |
401 return { |
|
402 "id": self.getId(), |
|
403 "x": self.x(), |
|
404 "y": self.y(), |
|
405 "type": self.getItemType(), |
401 "is_external": self.external, |
406 "is_external": self.external, |
402 "no_attributes": self.noAttrs, |
407 "no_attributes": self.noAttrs, |
403 "name": self.model.getName(), |
408 "model_name": self.model.getName(), |
404 "attributes": self.model.getInstanceAttributes(), |
409 "attributes": self.model.getInstanceAttributes(), |
405 "methods": self.model.getMethods(), |
410 "methods": self.model.getMethods(), |
406 "class_attributes": self.model.getClassAttributes(), |
411 "class_attributes": self.model.getClassAttributes(), |
407 } |
412 } |
|
413 |
|
414 @classmethod |
|
415 def fromDict(cls, data, colors=None): |
|
416 """ |
|
417 Class method to create a class item from persisted data. |
|
418 |
|
419 @param data dictionary containing the persisted data as generated |
|
420 by toDict() |
|
421 @type dict |
|
422 @param colors tuple containing the foreground and background colors |
|
423 @type tuple of (QColor, QColor) |
|
424 @return created class item |
|
425 @rtype ClassItem |
|
426 """ |
|
427 try: |
|
428 model = ClassModel(data["model_name"], |
|
429 data["methods"], |
|
430 data["attributes"], |
|
431 data["class_attributes"]) |
|
432 itm = cls(model=model, |
|
433 external=data["is_external"], |
|
434 x=0, |
|
435 y=0, |
|
436 noAttrs=data["no_attributes"], |
|
437 colors=colors) |
|
438 itm.setPos(data["x"], data["y"]) |
|
439 itm.setId(data["id"]) |
|
440 return itm |
|
441 except KeyError: |
|
442 return None |