Version: 8.3.0
FormContainerBase.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 "FormContainerBase.hxx"
22 #include "FormComponent.hxx"
23 #include "QtGuiContext.hxx"
24 #include "Container.hxx"
25 
26 #include <cassert>
27 #include <cstdlib>
28 #include <climits>
29 
30 //#define _DEVDEBUG_
31 #include "YacsTrace.hxx"
32 
33 #include <QList>
34 #include <sstream>
35 
36 using namespace std;
37 using namespace YACS;
38 using namespace YACS::HMI;
39 using namespace YACS::ENGINE;
40 
41 FormContainerBase::FormContainerBase(QWidget *parent):QWidget(parent),_advancedParams(new FormAdvParamContainer(_properties,this))
42 {
43  setupUi(this);
44  _advanced = false;
45  gridLayout_2->addWidget(_advancedParams);
47 
48  FillPanel(0); // --- set widgets before signal connexion to avoid false modif detection
49  connect(le_name, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyName(const QString&)));
50  connect(cb_resource, SIGNAL(activated(const QString&)), _advancedParams, SLOT(onModifyResource(const QString&)));
51 }
52 
54 {
55  delete _advancedParams;
56 }
57 
59 {
60  DEBTRACE("FormContainer::FillPanel");
61  _container = container;
62  if (_container)
63  {
65  le_name->setText(_container->getName().c_str());
66  }
67  else
68  {
69  _properties.clear();
70  le_name->setText("not defined");
71  }
72 
73  //Resources
74  cb_resource->clear();
75  cb_resource->addItem("automatic"); // --- when no resource is selected
76 
77  //add available resources
78  list<string> machines = QtGuiContext::getQtCurrent()->getGMain()->getMachineList();
79  list<string>::iterator itm = machines.begin();
80  for( ; itm != machines.end(); ++itm)
81  {
82  cb_resource->addItem(QString((*itm).c_str()));
83  }
84 
85  std::string resource;
86  if(_properties.count("name") && _properties["name"] != "")
87  {
88  //a resource has been specified
89  int index = cb_resource->findText(_properties["name"].c_str());
90  if (index > 0)
91  {
92  //the resource is found: use it
93  cb_resource->setCurrentIndex(index);
94  resource=_properties["name"];
95  }
96  else
97  {
98  //the resource has not been found: add a false item
99  std::string item="Unknown resource ("+_properties["name"]+")";
100  cb_resource->addItem(item.c_str());
101  cb_resource->setCurrentIndex(cb_resource->count()-1);
102  }
103  }
104  else
105  cb_resource->setCurrentIndex(0);
106  _advancedParams->FillPanel(resource,container);
107 
108  if (!QtGuiContext::getQtCurrent()->isEdition())
109  {
110  //if the schema is in execution do not allow editing
111  le_name->setReadOnly(true);
112  cb_resource->setEnabled(false);
113  }
114 }
115 
117 {
118  DEBTRACE("FormContainerBase::onModified");
119  Subject *sub(QtGuiContext::getQtCurrent()->getSelectedSubject());
120  if (!sub)
121  return;
122  YASSERT(QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(sub));
123  QWidget *widget(QtGuiContext::getQtCurrent()->_mapOfEditionItem[sub]);
124  ItemEdition *item(dynamic_cast<ItemEdition*>(widget));
125  YASSERT(item);
126  item->setEdited(true);
127 }
128 
130 {
131  DEBTRACE("FormContainer::on_ch_advance_stateChanged " << state);
132  if (state)
133  _advancedParams->show();
134  else
135  _advancedParams->hide();
136 }
137 
138 void FormContainerBase::onModifyName(const QString &text)
139 {
140  DEBTRACE("onModifyName " << text.toStdString());
141  SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
142  YASSERT(scont);
143  string name = scont->getName();
144  if (name != text.toStdString())
145  onModified();
146 }
147 
149 {
150  SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
151  YASSERT(scont);
152  bool ret(scont->setName(le_name->text().toStdString()));
153  DEBTRACE(ret);
154  if (ret)
155  ret = scont->setProperties(_properties);
156  return ret;
157 }
158 
160 {
161  SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
162  YASSERT(scont);
163  FillPanel(scont->getContainer());
164 }