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 "EditionSwitch.hxx"
20 #include "TableSwitch.hxx"
21 #include "SchemaModel.hxx"
22 #include "QtGuiContext.hxx"
23 #include "SchemaItem.hxx"
24 #include "ValueDelegate.hxx"
27 #include "YacsTrace.hxx"
35 using namespace YACS::HMI;
37 EditionSwitch::EditionSwitch(Subject* subject,
40 : EditionBloc(subject, parent, name)
42 _tvSwitch = new TableSwitch(this);
43 _wid->gridLayout1->addWidget(_tvSwitch);
44 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
45 _tvSwitch->tv_nodes->setModel(model);
46 _tvSwitch->sb_select->setMinimum(INT_MIN);
47 _tvSwitch->sb_select->setMaximum(INT_MAX);
48 connect(_tvSwitch->sb_select, SIGNAL(valueChanged(const QString &)),
49 this, SLOT(onModifySelect(const QString &)));
51 _valueDelegate = new ValueDelegate(parent);
52 _tvSwitch->tv_nodes->setItemDelegateForColumn(YValue, _valueDelegate);
53 _tvSwitch->setEditableCase(true);
55 connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
56 this, SLOT(onCommitData(QWidget*)));
59 EditionSwitch::~EditionSwitch()
63 void EditionSwitch::synchronize()
65 DEBTRACE("EditionSwitch::synchronize");
66 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
67 SchemaItem* schemaItem = QtGuiContext::getQtCurrent()->_mapOfSchemaItem[_subject];
70 QModelIndex parentIndex = schemaItem->modelIndex();
71 _tvSwitch->tv_nodes->setRootIndex(parentIndex);
72 int numRows = model->rowCount(parentIndex);
73 for (int row = 0; row < numRows; ++row)
75 QModelIndex index = model->index(row, 0, parentIndex);
76 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
78 if (Subject *sub = childItem->getSubject())
79 if (dynamic_cast<SubjectNode*>(sub))
81 _tvSwitch->tv_nodes->setRowHidden(row, hidden);
84 _tvSwitch->adjustColumns();
85 _subject->update(SETSELECT, 0, _subject);
88 void EditionSwitch::onModifySelect(const QString &text)
90 DEBTRACE("EditionSwitch::onModifySelect " << text.toStdString());
91 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(_subject);
93 sswitch->setSelect(text.toStdString());
96 void EditionSwitch::update(GuiEvent event, int type, Subject* son)
98 DEBTRACE("EditionSwitch::update " <<eventName(event) << " " << type);
104 SubjectComposedNode *scn = dynamic_cast<SubjectComposedNode*>(_subject);
105 string val = scn->getValue();
106 istringstream ss(val);
111 _tvSwitch->sb_select->setValue(i);
115 EditionBloc::update(event, type, son);
119 void EditionSwitch::onCommitData(QWidget *editor)
121 DEBTRACE("EditionSwitch::onCommitData " << editor);
122 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
124 QString val = gedit->GetStrValue();
125 DEBTRACE(val.toStdString());
126 Subject *sub = gedit->getSubject();
128 SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
130 sub = snode->getParent();
131 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(sub);
133 bool isOk = sswitch->setCase(val.toStdString(), snode);
135 _valueDelegate->setResultEditing(editor, isOk);