Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/yacs.git] / src / genericgui / SchemaContainerItem.cxx
index 5b6752f59444232897b335f6a149c9c50fb85f4a..baaf221835a64a6b62a7c9e8a7a4c2a4e784e8b3 100644 (file)
@@ -1,25 +1,27 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "SchemaContainerItem.hxx"
 #include "QtGuiContext.hxx"
 #include "SchemaModel.hxx"
 #include "SchemaComponentItem.hxx"
+#include "Menus.hxx"
 
 #include <QIcon>
 #include <cassert>
@@ -31,7 +33,7 @@ using namespace std;
 using namespace YACS::HMI;
 
 SchemaContainerItem::SchemaContainerItem(SchemaItem *parent, QString label, Subject* subject)
-  : SchemaItem::SchemaItem(parent, label, subject)
+  : SchemaItem(parent, label, subject)
 {
   DEBTRACE("SchemaContainerItem::SchemaContainerItem " << subject->getName());
   SubjectContainer *scont = dynamic_cast<SubjectContainer*>(subject);
@@ -50,7 +52,7 @@ void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
         DEBTRACE("ADDCHILDREF ");
         SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
         SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
-        assert(ref);
+        YASSERT(ref);
         DEBTRACE("ADDCHILDREF " << ref->getReference()->getName());
         addComponentInstance(ref->getReference());
       }
@@ -58,7 +60,17 @@ void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
 
     case YACS::HMI::REMOVECHILDREF:
       {
-        DEBTRACE("REMOVECHILDREF ");
+        DEBTRACE("REMOVECHILDREF on " << getSubject()->getName());
+        SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
+        SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
+        YASSERT(ref);
+        DEBTRACE("REMOVECHILDREF " << ref->getReference()->getName());
+        SchemaItem *toRemove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
+
+        int position = toRemove->row();
+        model->beginRemoveRows(modelIndex(), position, position);
+        removeChild(toRemove);
+        model->endRemoveRows();
       }
       break;
 
@@ -67,7 +79,7 @@ void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
         DEBTRACE("CUT on " << getSubject()->getName());
         SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
         SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
-        assert(ref);
+        YASSERT(ref);
         DEBTRACE("CUT " << ref->getReference()->getName());
         SchemaItem *toMove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
 
@@ -83,7 +95,7 @@ void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
         DEBTRACE("PASTE on " << getSubject()->getName());
         SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
         SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
-        assert(ref);
+        YASSERT(ref);
         DEBTRACE("PASTE " << ref->getReference()->getName());
         SchemaItem *toPaste = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
 
@@ -95,6 +107,7 @@ void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
       break;
 
     default:
+      SchemaItem::update(event, type, son);
       ;
     }
 }
@@ -110,3 +123,14 @@ void SchemaContainerItem::addComponentInstance(Subject* subject)
                                                       subject);
   model->endInsertRows();
 }
+
+void SchemaContainerItem::popupMenu(QWidget *caller, const QPoint &globalPos)
+{
+  ContainerMenu m;
+  m.popupMenu(caller, globalPos);
+}
+
+QVariant SchemaContainerItem::editionWhatsThis(int column) const
+{
+  return "<p>To edit the container properties, select the container and use the input panel. <a href=\"modification.html#property-page-for-container\">More...</a></p>";
+}