1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SchemaContainerItem.hxx"
21 #include "QtGuiContext.hxx"
22 #include "SchemaModel.hxx"
23 #include "SchemaComponentItem.hxx"
30 #include "YacsTrace.hxx"
33 using namespace YACS::HMI;
35 SchemaContainerItem::SchemaContainerItem(SchemaItem *parent, QString label, Subject* subject)
36 : SchemaItem(parent, label, subject)
38 DEBTRACE("SchemaContainerItem::SchemaContainerItem " << subject->getName());
39 SubjectContainer *scont = dynamic_cast<SubjectContainer*>(subject);
41 _itemDeco.replace(YLabel, QIcon("icons:container.png"));
44 void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
46 DEBTRACE("SchemaContainerItem::update " << eventName(event) << " " << son->getName());
47 //SchemaItem::update(event, type, son);
50 case YACS::HMI::ADDCHILDREF:
52 DEBTRACE("ADDCHILDREF ");
53 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
54 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
56 DEBTRACE("ADDCHILDREF " << ref->getReference()->getName());
57 addComponentInstance(ref->getReference());
61 case YACS::HMI::REMOVECHILDREF:
63 DEBTRACE("REMOVECHILDREF on " << getSubject()->getName());
64 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
65 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
67 DEBTRACE("REMOVECHILDREF " << ref->getReference()->getName());
68 SchemaItem *toRemove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
70 int position = toRemove->row();
71 model->beginRemoveRows(modelIndex(), position, position);
72 removeChild(toRemove);
73 model->endRemoveRows();
79 DEBTRACE("CUT on " << getSubject()->getName());
80 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
81 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
83 DEBTRACE("CUT " << ref->getReference()->getName());
84 SchemaItem *toMove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
86 int position = toMove->row();
87 model->beginRemoveRows(modelIndex(), position, position);
89 model->endRemoveRows();
93 case YACS::HMI::PASTE:
95 DEBTRACE("PASTE on " << getSubject()->getName());
96 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
97 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
99 DEBTRACE("PASTE " << ref->getReference()->getName());
100 SchemaItem *toPaste = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
102 int nbsons = childCount();
103 model->beginInsertRows(modelIndex(), nbsons, nbsons);
104 toPaste->reparent(this);
105 model->endInsertRows();
110 SchemaItem::update(event, type, son);
115 void SchemaContainerItem::addComponentInstance(Subject* subject)
117 DEBTRACE("SchemaContainersItem::addComponentInstance");
118 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
119 int nbsons = childCount();
120 model->beginInsertRows(modelIndex(), nbsons, nbsons);
121 SchemaComponentItem *item = new SchemaComponentItem(this,
122 subject->getName().c_str(),
124 model->endInsertRows();
127 void SchemaContainerItem::popupMenu(QWidget *caller, const QPoint &globalPos)
130 m.popupMenu(caller, globalPos);
133 QVariant SchemaContainerItem::editionWhatsThis(int column) const
135 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>";