eric6/Graphics/ModuleItem.py

changeset 8295
3f5e8b0a338e
parent 8291
3d79b1e5bf3c
diff -r cb4e5bbf3a2c -r 3f5e8b0a338e eric6/Graphics/ModuleItem.py
--- a/eric6/Graphics/ModuleItem.py	Thu May 06 19:46:00 2021 +0200
+++ b/eric6/Graphics/ModuleItem.py	Sat May 08 18:34:08 2021 +0200
@@ -77,7 +77,8 @@
         """
         UMLItem.__init__(self, model, x, y, rounded, colors, parent)
         
-        scene.addItem(self)
+        if scene:
+            scene.addItem(self)
         
         if self.model:
             self.__createTexts()
@@ -236,6 +237,36 @@
         @rtype dict
         """
         return {
-            "name": self.model.getName(),
+            "id": self.getId(),
+            "x": self.x(),
+            "y": self.y(),
+            "type": self.getItemType(),
+            "model_name": self.model.getName(),
             "classes": self.model.getClasses(),
         }
+    
+    @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 = ModuleModel(data["model_name"],
+                                data["classes"])
+            itm = cls(model,
+                      x=0,
+                      y=0,
+                      colors=colors)
+            itm.setPos(data["x"], data["y"])
+            itm.setId(data["id"])
+            return itm
+        except KeyError:
+            return None

eric ide

mercurial