1 // Copyright (C) 2006-2014 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 "FormContainerDecorator.hxx"
21 #include "FormContainer.hxx"
22 #include "FormHPContainer.hxx"
24 #include "HomogeneousPoolContainer.hxx"
25 #include "Exception.hxx"
28 #include "YacsTrace.hxx"
30 using namespace YACS::ENGINE;
32 bool FormContainerDecorator::CHECKED = false;
34 FormContainerDecorator::FormContainerDecorator(YACS::ENGINE::Container *cont, QWidget *parent):QWidget(parent),_typ(0)
37 throw YACS::Exception("FormContainerDecorator constrctor : container is empty !");
39 _icon.addFile("icons:icon_down.png");
40 _icon.addFile("icons:icon_up.png",QSize(), QIcon::Normal, QIcon::On);
41 tb_container->setIcon(_icon);
42 connect(this,SIGNAL(typeOfContainerIsKnown(const QString&)),label,SLOT(setText(const QString &)));
43 HomogeneousPoolContainer *hpc(dynamic_cast<HomogeneousPoolContainer *>(cont));
45 _typ=new FormContainer(this);
47 _typ=new FormHPContainer(this);
48 emit typeOfContainerIsKnown(_typ->getTypeStr());
49 _typ->FillPanel(cont);
50 gridLayout_1->addWidget(_typ);
52 tb_container->setChecked(CHECKED);
53 on_tb_container_toggled(CHECKED);
56 FormContainerDecorator::~FormContainerDecorator()
61 void FormContainerDecorator::FillPanel(YACS::ENGINE::Container *container)
64 checkAndRepareTypeIfNecessary(container);
65 _typ->FillPanel(container);
68 QWidget *FormContainerDecorator::getWidget()
74 bool FormContainerDecorator::onApply()
77 return _typ->onApply();
80 void FormContainerDecorator::onCancel()
86 void FormContainerDecorator::show()
91 tb_container->setChecked(CHECKED);
92 on_tb_container_toggled(CHECKED);
95 void FormContainerDecorator::hide()
102 void FormContainerDecorator::on_tb_container_toggled(bool checked)
104 DEBTRACE("FormContainer::on_tb_container_toggled " << checked);
116 void FormContainerDecorator::synchronizeCheckContainer()
119 tb_container->setChecked(CHECKED);
122 std::string FormContainerDecorator::getHostName(int index) const
125 return _typ->cb_resource->itemText(index).toStdString();
128 void FormContainerDecorator::setName(const std::string& name)
131 _typ->le_name->setText(name.c_str());
134 void FormContainerDecorator::onResMousePressed()
136 emit(resourceMousePressed());
139 void FormContainerDecorator::onResActivated(int v)
141 emit(resourceActivated(v));
144 void FormContainerDecorator::onContToggled(bool v)
146 emit(containerToggled(v));
149 void FormContainerDecorator::checkOK() const
152 throw YACS::Exception("Null Widget Container !!!!");
155 void FormContainerDecorator::checkAndRepareTypeIfNecessary(YACS::ENGINE::Container *container)
159 throw YACS::Exception("Null Container !!!!");
160 YACS::ENGINE::HomogeneousPoolContainer *cont1(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container));
161 bool isTyp1(dynamic_cast<FormHPContainer *>(_typ)!=0);
162 if((!cont1 && !isTyp1) || (cont1 && isTyp1))
164 QWidget *parent(_typ->parentWidget());
167 _typ=new FormContainer(parent);
169 _typ=new FormHPContainer(parent);
170 gridLayout_1->addWidget(_typ);
171 emit typeOfContainerIsKnown(_typ->getTypeStr());
173 _typ->FillPanel(container);
176 void FormContainerDecorator::connectForTyp()
178 connect(_typ->cb_resource,SIGNAL(mousePressed()),this,SLOT(onResMousePressed()));
179 connect(_typ->cb_resource,SIGNAL(activated(int)),this,SLOT(onResActivated));
180 connect(tb_container,SIGNAL(toggled(bool)),this,SLOT(onContToggled()));