eric6/Graphics/ModuleItem.py

changeset 8295
3f5e8b0a338e
parent 8291
3d79b1e5bf3c
equal deleted inserted replaced
8294:cb4e5bbf3a2c 8295:3f5e8b0a338e
75 @param scene reference to the scene object 75 @param scene reference to the scene object
76 @type QGraphicsScene 76 @type QGraphicsScene
77 """ 77 """
78 UMLItem.__init__(self, model, x, y, rounded, colors, parent) 78 UMLItem.__init__(self, model, x, y, rounded, colors, parent)
79 79
80 scene.addItem(self) 80 if scene:
81 scene.addItem(self)
81 82
82 if self.model: 83 if self.model:
83 self.__createTexts() 84 self.__createTexts()
84 self.__calculateSize() 85 self.__calculateSize()
85 86
234 235
235 @return dictionary containing data to be persisted 236 @return dictionary containing data to be persisted
236 @rtype dict 237 @rtype dict
237 """ 238 """
238 return { 239 return {
239 "name": self.model.getName(), 240 "id": self.getId(),
241 "x": self.x(),
242 "y": self.y(),
243 "type": self.getItemType(),
244 "model_name": self.model.getName(),
240 "classes": self.model.getClasses(), 245 "classes": self.model.getClasses(),
241 } 246 }
247
248 @classmethod
249 def fromDict(cls, data, colors=None):
250 """
251 Class method to create a class item from persisted data.
252
253 @param data dictionary containing the persisted data as generated
254 by toDict()
255 @type dict
256 @param colors tuple containing the foreground and background colors
257 @type tuple of (QColor, QColor)
258 @return created class item
259 @rtype ClassItem
260 """
261 try:
262 model = ModuleModel(data["model_name"],
263 data["classes"])
264 itm = cls(model,
265 x=0,
266 y=0,
267 colors=colors)
268 itm.setPos(data["x"], data["y"])
269 itm.setId(data["id"])
270 return itm
271 except KeyError:
272 return None

eric ide

mercurial