Version: 8.3.0
EditionLoop.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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 "EditionLoop.hxx"
21 #include "FormLoop.hxx"
22 #include "Node.hxx"
23 #include "OutputPort.hxx"
24 #include "QtGuiContext.hxx"
25 
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28 
29 #include <cassert>
30 #include <sstream>
31 
32 using namespace std;
33 
34 using namespace YACS;
35 using namespace YACS::HMI;
36 
37 EditionLoop::EditionLoop(Subject* subject,
38  QWidget* parent,
39  const char* name)
40  : EditionNode(subject, parent, name)
41 {
42  _formLoop = new FormLoop(this);
43  _nbsteps = 0;
44  _wid->gridLayout1->addWidget(_formLoop);
45 
46  QHBoxLayout* _hbl_index = new QHBoxLayout();
47  QLabel* _la_index = new QLabel(this);
48  _hbl_index->addWidget(_la_index);
49  _la_index->setText("index:");
50  _le_index = new QLineEdit(this);
51  _le_index->setText(QString::number(0));
52  _le_index->setReadOnly(true);
53  _hbl_index->addWidget(_le_index);
54  _formLoop->gridLayout->addLayout(_hbl_index, 1, 0);
55 
56  _formLoop->sb_nsteps->setMinimum(0);
57  _formLoop->sb_nsteps->setMaximum(INT_MAX);
58  if (!QtGuiContext::getQtCurrent()->isEdition())
59  _formLoop->setEnabled (false);
60 
61  connect(_formLoop->sb_nsteps, SIGNAL(editingFinished()),
62  this, SLOT(onNbStepsEdited()));
63 }
64 
66 {
67 }
68 
70 {
71  int newval = _formLoop->sb_nsteps->value();
72  DEBTRACE("EditionLoop::onNbStepsEdited " << _nbsteps << " --> " << newval);
73  if (newval != _nbsteps)
74  {
75  SubjectForLoop *sfl = dynamic_cast<SubjectForLoop*>(_subject);
76  YASSERT(sfl);
77  QString text = _formLoop->sb_nsteps->cleanText();
78  sfl->setNbSteps(text.toStdString());
79  }
80 }
81 
83 {
85 }
86 
87 void EditionLoop::update(GuiEvent event, int type, Subject* son)
88 {
89  DEBTRACE("EditionLoop::update " <<eventName(event) << " " << type);
90  EditionNode::update(event, type, son);
91  switch (event)
92  {
93  case SETVALUE:
94  {
95  SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
96  string val = scn->getValue();
97  istringstream ss(val);
98  DEBTRACE(val);
99  int i = 0;
100  ss >> i;
101  DEBTRACE(i);
102  _formLoop->sb_nsteps->setValue(i);
103  _nbsteps = i;
104 
105  YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
107  _le_index->setText(QString::fromStdString(sodp->getExecValue()));
108  break;
109  }
110  case UPDATEPROGRESS:
111  {
112  SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
113  YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
115  _le_index->setText(QString::fromStdString(sodp->getExecValue()));
116  break;
117  }
118  }
119 }