Xcos MVC: detect deleted objects 70/18170/3
Paul Bignier [Thu, 19 May 2016 09:04:23 +0000 (11:04 +0200)]
Change-Id: I264fca75b3000ab590a2a0bc83234b6edd44099e

scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.cpp

index eecafee..00c8098 100644 (file)
@@ -82,9 +82,16 @@ struct model
 
                 for (const ScicosID id : children)
                 {
-                    auto o = controller.getObject(id);
-                    neededController.setObjectProperty(o->id(), o->kind(), PARENT_DIAGRAM, newDiag);
-                    neededController.referenceObject(o->id());
+                    if (id == ScicosID())
+                    {
+                        // Deleted object
+                    }
+                    else
+                    {
+                        auto o = controller.getObject(id);
+                        neededController.setObjectProperty(o->id(), o->kind(), PARENT_DIAGRAM, newDiag);
+                        neededController.referenceObject(o->id());
+                    }
                 }
                 subDiagram->setFrom(adaptor.getFrom());
                 subDiagram->setTo(adaptor.getTo());
@@ -103,26 +110,33 @@ struct model
                 std::vector<link_t> to;
                 for (const ScicosID id : children)
                 {
-                    auto o = controller.getObject(id);
-                    controller.referenceObject(o);
-
-                    switch (o->kind())
+                    if (id == ScicosID())
+                    {
+                        // Deleted object
+                    }
+                    else
                     {
-                        case ANNOTATION :
-                            listObjects->append(new TextAdapter(controller, static_cast<org_scilab_modules_scicos::model::Annotation*>(o)));
-                            break;
-                        case BLOCK :
+                        auto o = controller.getObject(id);
+                        controller.referenceObject(o);
+
+                        switch (o->kind())
                         {
-                            BlockAdapter* block = new BlockAdapter(controller, static_cast<org_scilab_modules_scicos::model::Block*>(o));
-                            listObjects->append(block);
-                            break;
+                            case ANNOTATION :
+                                listObjects->append(new TextAdapter(controller, static_cast<org_scilab_modules_scicos::model::Annotation*>(o)));
+                                break;
+                            case BLOCK :
+                            {
+                                BlockAdapter* block = new BlockAdapter(controller, static_cast<org_scilab_modules_scicos::model::Block*>(o));
+                                listObjects->append(block);
+                                break;
+                            }
+                            default : // LINK
+                                LinkAdapter* link = new LinkAdapter(controller, static_cast<org_scilab_modules_scicos::model::Link*>(o));
+                                from.push_back(link->getFrom());
+                                to.push_back(link->getTo());
+                                listObjects->append(link);
+                                break;
                         }
-                        default : // LINK
-                            LinkAdapter* link = new LinkAdapter(controller, static_cast<org_scilab_modules_scicos::model::Link*>(o));
-                            from.push_back(link->getFrom());
-                            to.push_back(link->getTo());
-                            listObjects->append(link);
-                            break;
                     }
                 }
                 const_cast<BlockAdapter&>(adaptor).setFrom(from);