Version: 9.16.0
EditionSwitch.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "EditionSwitch.hxx"
21#include "TableSwitch.hxx"
22#include "SchemaModel.hxx"
23#include "QtGuiContext.hxx"
24#include "SchemaItem.hxx"
25#include "ValueDelegate.hxx"
26
27//#define _DEVDEBUG_
28#include "YacsTrace.hxx"
29
30#include <cassert>
31#include <sstream>
32
33using namespace std;
34
35using namespace YACS;
36using namespace YACS::HMI;
37
38EditionSwitch::EditionSwitch(Subject* subject,
39 QWidget* parent,
40 const char* name)
41 : EditionBloc(subject, parent, name)
42{
43 _tvSwitch = new TableSwitch(this);
44 _wid->gridLayout1->addWidget(_tvSwitch);
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 &)));
51
52 _valueDelegate = new ValueDelegate(parent);
53 _tvSwitch->tv_nodes->setItemDelegateForColumn(YValue, _valueDelegate);
55 if (!QtGuiContext::getQtCurrent()->isEdition())
56 _tvSwitch->setEnabled (false);
57
58 connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
59 this, SLOT(onCommitData(QWidget*)));
60}
61
63{
64}
65
67{
68 DEBTRACE("EditionSwitch::synchronize");
71 if (schemaItem)
72 {
73 QModelIndex parentIndex = schemaItem->modelIndex();
74 _tvSwitch->tv_nodes->setRootIndex(parentIndex);
75 int numRows = model->rowCount(parentIndex);
76 for (int row = 0; row < numRows; ++row)
77 {
78 QModelIndex index = model->index(row, 0, parentIndex);
79 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
80 bool hidden = true;
81 if (Subject *sub = childItem->getSubject())
82 if (dynamic_cast<SubjectNode*>(sub))
83 hidden = false;
84 _tvSwitch->tv_nodes->setRowHidden(row, hidden);
85 }
86 }
89}
90
91void EditionSwitch::onModifySelect(const QString &text)
92{
93 DEBTRACE("EditionSwitch::onModifySelect " << text.toStdString());
94 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(_subject);
95 YASSERT(sswitch);
96 sswitch->setSelect(text.toStdString());
97}
98
99void EditionSwitch::update(GuiEvent event, int type, Subject* son)
100{
101 DEBTRACE("EditionSwitch::update " <<eventName(event) << " " << type);
102 switch (event)
103 {
104
105 case SETSELECT:
106 {
107 SubjectComposedNode *scn = dynamic_cast<SubjectComposedNode*>(_subject);
108 string val = scn->getValue();
109 istringstream ss(val);
110 DEBTRACE(val);
111 int i = 0;
112 ss >> i;
113 DEBTRACE(i);
114 _tvSwitch->sb_select->setValue(i);
115 }
116 break;
117 default:
118 EditionBloc::update(event, type, son);
119 }
120}
121
123{
124 DEBTRACE("EditionSwitch::onCommitData " << editor);
125 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
126 YASSERT(gedit);
127 QString val = gedit->GetStrValue();
128 DEBTRACE(val.toStdString());
129 Subject *sub = gedit->getSubject();
130 YASSERT(sub);
131 SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
132 YASSERT(snode);
133 sub = snode->getParent();
134 SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(sub);
135 YASSERT(sswitch);
136 bool isOk = sswitch->setCase(val.toStdString(), snode);
137 if (_valueDelegate)
138 _valueDelegate->setResultEditing(editor, isOk);
139
140}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
WidEditItem * _wid
virtual void update(GuiEvent event, int type, Subject *son)
Definition: EditionBloc.cxx:44
ValueDelegate * _valueDelegate
virtual void onModifySelect(const QString &text)
virtual void synchronize()
virtual void onCommitData(QWidget *editor)
virtual void update(GuiEvent event, int type, Subject *son)
virtual Subject * getSubject()
virtual QString GetStrValue()
static std::string eventName(GuiEvent event)
YACS::HMI::SchemaModel * getSchemaModel()
std::map< YACS::HMI::Subject *, YACS::HMI::SchemaItem * > _mapOfSchemaItem
static QtGuiContext * getQtCurrent()
virtual Subject * getSubject()
Definition: SchemaItem.cxx:169
QModelIndex modelIndex(int column=0)
Definition: SchemaItem.cxx:253
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: SchemaModel.cxx:60
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: SchemaModel.cxx:92
virtual std::string getValue()
virtual bool setSelect(std::string select)
virtual bool setCase(std::string caseId, SubjectNode *snode)
virtual void update(GuiEvent event, int type, Subject *son)
virtual Subject * getParent()
virtual void adjustColumns()
Definition: TableSwitch.cxx:57
virtual void setEditableCase(bool isEditable)
Definition: TableSwitch.cxx:45
virtual void setResultEditing(QWidget *editor, bool isOk)