1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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 "EditionElementaryNode.hxx"
21 #include "ValueDelegate.hxx"
22 #include "QtGuiContext.hxx"
26 #include "DataPort.hxx"
27 #include "TypeCode.hxx"
29 #include "TablePortsEdition.hxx"
32 #include "YacsTrace.hxx"
39 using namespace YACS::HMI;
41 EditionElementaryNode::EditionElementaryNode(Subject* subject,
44 : EditionNode(subject, parent, name)
52 _subElemNode = dynamic_cast<SubjectElementaryNode*>(_subject);
53 YASSERT(_subElemNode);
54 _valueDelegate = new ValueDelegate(parent);
56 connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
57 this, SLOT(onCommitData(QWidget*)));
61 EditionElementaryNode::~EditionElementaryNode()
65 void EditionElementaryNode::onApply()
67 ItemEdition::onApply();
70 void EditionElementaryNode::onCancel()
72 ItemEdition::onCancel();
75 void EditionElementaryNode::onPortIndexChanged(int index)
77 DEBTRACE("EditionElementaryNode::onPortIndexChanged " << index);
81 void EditionElementaryNode::synchronize()
83 //DEBTRACE("EditionElementaryNode::synchronize");
84 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
85 SchemaItem* schemaItem = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[_subject];
88 QModelIndex parentIndex = schemaItem->modelIndex();
89 int numRows = model->rowCount(parentIndex);
92 _tvInPorts->cb_insert->setCurrentIndex(0);
93 _tvInPorts->setNode(_subElemNode);
94 _tvInPorts->tv_ports->setRootIndex(parentIndex);
95 for (int row = 0; row < numRows; ++row)
97 QModelIndex index = model->index(row, 0, parentIndex);
98 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
100 if (Subject *sub = childItem->getSubject())
101 if (dynamic_cast<SubjectInputPort*>(sub)
102 || dynamic_cast<SubjectInputDataStreamPort*>(sub))
104 _tvInPorts->tv_ports->setRowHidden(row, hidden);
106 _tvInPorts->adjustColumns();
110 _tvOutPorts->cb_insert->setCurrentIndex(0);
111 _tvOutPorts->setNode(_subElemNode);
112 _tvOutPorts->tv_ports->setRootIndex(parentIndex);
113 for (int row = 0; row < numRows; ++row)
115 QModelIndex index = model->index(row, 0, parentIndex);
116 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
118 if (Subject *sub = childItem->getSubject())
119 if (dynamic_cast<SubjectOutputPort*>(sub)
120 || dynamic_cast<SubjectOutputDataStreamPort*>(sub))
122 _tvOutPorts->tv_ports->setRowHidden(row, hidden);
124 _tvOutPorts->adjustColumns();
129 void EditionElementaryNode::setEditablePorts(bool isEditable)
131 if (_tvInPorts) _tvInPorts->setEditablePorts(isEditable);
132 if (_tvOutPorts) _tvOutPorts->setEditablePorts(isEditable);
135 bool EditionElementaryNode::hasInputPorts()
140 bool EditionElementaryNode::hasOutputPorts()
145 void EditionElementaryNode::createTablePorts(QLayout* layout)
147 _twPorts = new QTabWidget(this);
148 layout->addWidget(_twPorts);
149 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
151 QModelIndex schemIndex = model->index(0, 0, QModelIndex());
152 QModelIndex TypesDirIndex = model->index(0, 0, schemIndex);
156 _tvInPorts =new TablePortsEdition(true, _twPorts);
157 _tvInPorts->tv_ports->setModel(model);
158 _tvInPorts->tv_ports->setItemDelegateForColumn(YLabel, _valueDelegate); // --- port label
159 _tvInPorts->tv_ports->setItemDelegateForColumn(YValue, _valueDelegate); // --- port value
160 _tvInPorts->cb_insert->setModel(model);
161 _tvInPorts->cb_insert->setRootModelIndex(TypesDirIndex);
162 _twPorts->addTab(_tvInPorts, "input Ports");
165 if (hasOutputPorts())
167 _tvOutPorts =new TablePortsEdition(false, _twPorts);
168 _tvOutPorts->tv_ports->setModel(model);
169 _tvOutPorts->tv_ports->setItemDelegateForColumn(YLabel, _valueDelegate); // --- port label
170 _tvOutPorts->tv_ports->setItemDelegateForColumn(YValue, _valueDelegate); // --- port value
171 _tvOutPorts->cb_insert->setModel(model);
172 _tvOutPorts->cb_insert->setRootModelIndex(TypesDirIndex);
173 _twPorts->addTab(_tvOutPorts, "output Ports");
176 connect(_twPorts, SIGNAL(currentChanged(int)),
177 this, SLOT(onPortIndexChanged(int)));
179 setEditablePorts(false);
183 * After edition with a specific editor created by ValueDelegate
184 * for a cell of TablePortsEdition, the resulting string is tested
185 * for setValue on the corresponding subject. Result of the setValue
186 * (succes or failure) is transmitted to ValueDelegate for further
187 * action in case of failure.
189 void EditionElementaryNode::onCommitData(QWidget *editor)
191 DEBTRACE("EditionElementaryNode::onCommitData " << editor);
192 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
194 QString val = gedit->GetStrValue();
195 DEBTRACE(val.toStdString());
196 Subject *sub = gedit->getSubject();
198 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(sub);
200 string strval = val.toStdString();
203 if (gedit->getColumnInSubject() == YValue)
206 isOk = sdp->setValue(strval);
208 GuiExecutor* executor = QtGuiContext::getQtCurrent()->getGuiExecutor();
209 if (executor) executor->setInPortValue(sdp->getPort(), strval);
214 isOk = sdp->setName(strval);
218 _valueDelegate->setResultEditing(editor, isOk);