1 // Copyright (C) 2006-2016 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 "FormContainerBase.hxx"
21 #include "FormAdvParamContainer.hxx"
22 #include "FormComponent.hxx"
23 #include "QtGuiContext.hxx"
24 #include "Container.hxx"
31 #include "YacsTrace.hxx"
38 using namespace YACS::HMI;
39 using namespace YACS::ENGINE;
41 FormContainerBase::FormContainerBase(QWidget *parent):QWidget(parent),_advancedParams(new FormAdvParamContainer(_properties,this))
45 gridLayout_2->addWidget(_advancedParams);
46 on_ch_advance_stateChanged(0);
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&)));
53 FormContainerBase::~FormContainerBase()
55 delete _advancedParams;
58 void FormContainerBase::FillPanel(YACS::ENGINE::Container *container)
60 DEBTRACE("FormContainer::FillPanel");
61 _container = container;
64 _properties = _container->getProperties();
65 le_name->setText(_container->getName().c_str());
70 le_name->setText("not defined");
75 cb_resource->addItem("automatic"); // --- when no resource is selected
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)
82 cb_resource->addItem(QString((*itm).c_str()));
86 if(_properties.count("name") && _properties["name"] != "")
88 //a resource has been specified
89 int index = cb_resource->findText(_properties["name"].c_str());
92 //the resource is found: use it
93 cb_resource->setCurrentIndex(index);
94 resource=_properties["name"];
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);
105 cb_resource->setCurrentIndex(0);
106 _advancedParams->FillPanel(resource,container);
108 if (!QtGuiContext::getQtCurrent()->isEdition())
110 //if the schema is in execution do not allow editing
111 le_name->setReadOnly(true);
112 cb_resource->setEnabled(false);
116 void FormContainerBase::onModified()
118 DEBTRACE("FormContainerBase::onModified");
119 Subject *sub(QtGuiContext::getQtCurrent()->getSelectedSubject());
122 YASSERT(QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(sub));
123 QWidget *widget(QtGuiContext::getQtCurrent()->_mapOfEditionItem[sub]);
124 ItemEdition *item(dynamic_cast<ItemEdition*>(widget));
126 item->setEdited(true);
129 void FormContainerBase::on_ch_advance_stateChanged(int state)
131 DEBTRACE("FormContainer::on_ch_advance_stateChanged " << state);
133 _advancedParams->show();
135 _advancedParams->hide();
138 void FormContainerBase::onModifyName(const QString &text)
140 DEBTRACE("onModifyName " << text.toStdString());
141 SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
143 string name = scont->getName();
144 if (name != text.toStdString())
148 bool FormContainerBase::onApply()
150 SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
152 bool ret(scont->setName(le_name->text().toStdString()));
155 ret = scont->setProperties(_properties);
159 void FormContainerBase::onCancel()
161 SubjectContainerBase *scont(QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
163 FillPanel(scont->getContainer());