1 // Copyright (C) 2006-2013 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 "EditionSwitch.hxx"
21 #include "TableSwitch.hxx"
22 #include "SchemaModel.hxx"
23 #include "QtGuiContext.hxx"
24 #include "SchemaItem.hxx"
25 #include "ValueDelegate.hxx"
28 #include "YacsTrace.hxx"
36 using namespace YACS::HMI;
38 EditionSwitch::EditionSwitch(Subject* subject,
41 : EditionBloc(subject, parent, name)
43 _tvSwitch = new TableSwitch(this);
44 _wid->gridLayout1->addWidget(_tvSwitch);
45 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
46 _tvSwitch->tv_nodes->setModel(model);
47 _tvSwitch->sb_select->setMinimum(INT_MIN);
48 _tvSwitch->sb_select->setMaximum(INT_MAX);
49 connect(_tvSwitch->sb_select, SIGNAL(valueChanged(const QString &)),
50 this, SLOT(onModifySelect(const QString &)));
52 _valueDelegate = new ValueDelegate(parent);
53 _tvSwitch->tv_nodes->setItemDelegateForColumn(YValue, _valueDelegate);
54 _tvSwitch->setEditableCase(true);
56 connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
57 this, SLOT(onCommitData(QWidget*)));
60 EditionSwitch::~EditionSwitch()
64 void EditionSwitch::synchronize()
66 DEBTRACE("EditionSwitch::synchronize");
67 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
68 SchemaItem* schemaItem = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[_subject];
71 QModelIndex parentIndex = schemaItem->modelIndex();
72 _tvSwitch->tv_nodes->setRootIndex(parentIndex);
73 int numRows = model->rowCount(parentIndex);
74 for (int row = 0; row < numRows; ++row)
76 QModelIndex index = model->index(row, 0, parentIndex);
77 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
79 if (Subject *sub = childItem->getSubject())
80 if (dynamic_cast<SubjectNode*>(sub))
82 _tvSwitch->tv_nodes->setRowHidden(row, hidden);
85 _tvSwitch->adjustColumns();
86 _subject->update(SETSELECT, 0, _subject);
89 void EditionSwitch::onModifySelect(const QString &text)
91 DEBTRACE("EditionSwitch::onModifySelect " << text.toStdString());
92 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(_subject);
94 sswitch->setSelect(text.toStdString());
97 void EditionSwitch::update(GuiEvent event, int type, Subject* son)
99 DEBTRACE("EditionSwitch::update " <<eventName(event) << " " << type);
105 SubjectComposedNode *scn = dynamic_cast<SubjectComposedNode*>(_subject);
106 string val = scn->getValue();
107 istringstream ss(val);
112 _tvSwitch->sb_select->setValue(i);
116 EditionBloc::update(event, type, son);
120 void EditionSwitch::onCommitData(QWidget *editor)
122 DEBTRACE("EditionSwitch::onCommitData " << editor);
123 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
125 QString val = gedit->GetStrValue();
126 DEBTRACE(val.toStdString());
127 Subject *sub = gedit->getSubject();
129 SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
131 sub = snode->getParent();
132 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(sub);
134 bool isOk = sswitch->setCase(val.toStdString(), snode);
136 _valueDelegate->setResultEditing(editor, isOk);