eric6/Graphics/PackageItem.py

changeset 8295
3f5e8b0a338e
parent 8291
3d79b1e5bf3c
--- a/eric6/Graphics/PackageItem.py	Thu May 06 19:46:00 2021 +0200
+++ b/eric6/Graphics/PackageItem.py	Sat May 08 18:34:08 2021 +0200
@@ -83,7 +83,8 @@
         UMLItem.__init__(self, model, x, y, rounded, colors, parent)
         self.noModules = noModules
         
-        scene.addItem(self)
+        if scene:
+            scene.addItem(self)
         
         if self.model:
             self.__createTexts()
@@ -265,7 +266,38 @@
         @rtype dict
         """
         return {
-            "name": self.model.getName(),
+            "id": self.getId(),
+            "x": self.x(),
+            "y": self.y(),
+            "type": self.getItemType(),
+            "model_name": self.model.getName(),
             "no_nodules": self.noModules,
             "modules": self.model.getModules(),
         }
+    
+    @classmethod
+    def fromDict(cls, data, colors=None):
+        """
+        Class method to create a class item from persisted data.
+        
+        @param data dictionary containing the persisted data as generated
+            by toDict()
+        @type dict
+        @param colors tuple containing the foreground and background colors
+        @type tuple of (QColor, QColor)
+        @return created class item
+        @rtype ClassItem
+        """
+        try:
+            model = PackageModel(data["model_name"],
+                                 data["modules"])
+            itm = cls(model,
+                      x=0,
+                      y=0,
+                      noModules=data["no_nodules"],
+                      colors=colors)
+            itm.setPos(data["x"], data["y"])
+            itm.setId(data["id"])
+            return itm
+        except KeyError:
+            return None

eric ide

mercurial