1 // Copyright (C) 2006-2008 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
19 #include "SchemaContainerItem.hxx"
20 #include "QtGuiContext.hxx"
21 #include "SchemaModel.hxx"
22 #include "SchemaComponentItem.hxx"
28 #include "YacsTrace.hxx"
31 using namespace YACS::HMI;
33 SchemaContainerItem::SchemaContainerItem(SchemaItem *parent, QString label, Subject* subject)
34 : SchemaItem::SchemaItem(parent, label, subject)
36 DEBTRACE("SchemaContainerItem::SchemaContainerItem " << subject->getName());
37 SubjectContainer *scont = dynamic_cast<SubjectContainer*>(subject);
39 _itemDeco.replace(YLabel, QIcon("icons:container.png"));
42 void SchemaContainerItem::update(GuiEvent event, int type, Subject* son)
44 DEBTRACE("SchemaContainerItem::update " << eventName(event) << " " << son->getName());
45 //SchemaItem::update(event, type, son);
48 case YACS::HMI::ADDCHILDREF:
50 DEBTRACE("ADDCHILDREF ");
51 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
52 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
54 DEBTRACE("ADDCHILDREF " << ref->getReference()->getName());
55 addComponentInstance(ref->getReference());
59 case YACS::HMI::REMOVECHILDREF:
61 DEBTRACE("REMOVECHILDREF ");
67 DEBTRACE("CUT on " << getSubject()->getName());
68 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
69 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
71 DEBTRACE("CUT " << ref->getReference()->getName());
72 SchemaItem *toMove = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
74 int position = toMove->row();
75 model->beginRemoveRows(modelIndex(), position, position);
77 model->endRemoveRows();
81 case YACS::HMI::PASTE:
83 DEBTRACE("PASTE on " << getSubject()->getName());
84 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
85 SubjectReference *ref = dynamic_cast<SubjectReference*>(son);
87 DEBTRACE("PASTE " << ref->getReference()->getName());
88 SchemaItem *toPaste = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[ref->getReference()];
90 int nbsons = childCount();
91 model->beginInsertRows(modelIndex(), nbsons, nbsons);
92 toPaste->reparent(this);
93 model->endInsertRows();
102 void SchemaContainerItem::addComponentInstance(Subject* subject)
104 DEBTRACE("SchemaContainersItem::addComponentInstance");
105 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
106 int nbsons = childCount();
107 model->beginInsertRows(modelIndex(), nbsons, nbsons);
108 SchemaComponentItem *item = new SchemaComponentItem(this,
109 subject->getName().c_str(),
111 model->endInsertRows();