1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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 // MED MEDGUI : MED component GUI implemetation
21 // File : MEDGUISelectComponents.cxx
24 #include "MEDGUISelectComponents.h"
25 #include "ui_MEDGUISelectComponents.h"
27 #include "MEDCalculatorBrowserLiteStruct.hxx"
28 #include "MEDCalculatorBrowserField.hxx"
38 using namespace ParaMEDMEM;
41 // Initialize qt part and private var part
42 // l is the MEDGUILiteStruct that will be modified, fi is a field id, for the case where one field only is selected
43 // First, connect button ok and cancel
44 // Then, set min and max for the loop according to fieldInd, this will made the QDialog show juste one field (with id fieldInd) or all fields
45 // Then, fill the QDialog with the file name
46 // For each field concerned, add the field name
47 // For each component, add a QCheckBox and the component name as a modifiable QLineEdit
48 MEDGUISelectComponents::MEDGUISelectComponents(ParaMEDMEM::MEDCalculatorBrowserLiteStruct& l,QWidget *parent, int fi/*=-1*/) :
50 ui(new Ui::MEDGUISelectComponents),
56 connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(close()));// close without applying
57 connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(fillSelection()));// apply
58 connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(close()));// close
61 fieldInd!=-1?min=fieldInd:min=0;
62 fieldInd!=-1?max=fieldInd:max=(int)ls->getNumberOfFields()-1;
64 QLabel *filename = new QLabel(ls->getName().c_str(),this);
65 ui->verticalLayout_2->insertWidget(0,filename);
67 for (int i = max; i >= min; i -= 1)
70 QGridLayout *fieldLayout = new QGridLayout(this);
72 QLabel *fieldname = new QLabel(ls->getField(i).getName().c_str(),this);
73 fieldLayout->addWidget(fieldname,0,0,1,0);
76 for (int j = ls->getField(i).getComponentsSize()-1; j >= 0; j -= 1)
78 QCheckBox *cb = new QCheckBox(this);
79 if(ls->getField(i).getSelectedComponents()[j]){
80 cb->setCheckState(Qt::Checked);
83 std::string compname ="";
84 if(ls->getField(i).getComponents()[j] != std::string("-noname-")) compname = ls->getField(i).getComponents()[j];
86 QLineEdit *le = new QLineEdit(compname.c_str(),this);
88 std::ostringstream chName, leName;
89 chName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "chkbox";
90 leName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "namebox";
92 cb->setObjectName(QString(chName.str().c_str()));
93 le->setObjectName(QString(leName.str().c_str()));
94 cb->setAccessibleName(QString(chName.str().c_str()));
95 le->setAccessibleName(QString(leName.str().c_str()));
97 fieldLayout->addWidget(cb,j+1,0);
98 fieldLayout->addWidget(le,j+1,1);
101 ui->verticalLayout_2->insertLayout(1,fieldLayout);
107 MEDGUISelectComponents::~MEDGUISelectComponents()
113 void MEDGUISelectComponents::changeEvent(QEvent *e)
115 QDialog::changeEvent(e);
117 case QEvent::LanguageChange:
118 ui->retranslateUi(this);
125 // Fill the MEDGUILiteStruct according to the selection and modification made by user
126 // First init the min,max for the loop : if equal, just one field will be modified, else all field
127 // Then for each field, for each component, if there is modification, they are applied (selection, unselection or rename)
128 void MEDGUISelectComponents::fillSelection()
131 fieldInd!=-1?min=fieldInd:min=0;
132 fieldInd!=-1?max=fieldInd:max=(int)ls->getNumberOfFields()-1;
134 for (int i = max; i >= min; i -= 1) {
136 for (unsigned int j = 0; j < ls->getField(i).getComponentsSize(); j += 1)
138 std::ostringstream chName, leName;
139 chName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "chkbox";
140 leName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "namebox";
142 QCheckBox *cb = this->findChild<QCheckBox*>(QString(chName.str().c_str()));
143 QLineEdit *le = this->findChild<QLineEdit*>(QString(leName.str().c_str()));
147 ls->getField(i).selectComponent(j);
149 ls->getField(i).unselectComponent(j);
151 ls->getField(i).setComponentName(j,le->text().toStdString());