Back to index

salome-med  6.5.0
MEDGUISelectComponents.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  MED MEDGUI : MED component GUI implemetation
00021 //  File   : MEDGUISelectComponents.cxx
00022 //  Module : MED
00023 //
00024 #include "MEDGUISelectComponents.h"
00025 #include "ui_MEDGUISelectComponents.h"
00026 
00027 #include "MEDCalculatorBrowserLiteStruct.hxx"
00028 #include "MEDCalculatorBrowserField.hxx"
00029 
00030 #include <sstream>
00031 #include <string>
00032 #include <iostream>
00033 
00034 #include <QLabel>
00035 #include <QCheckBox>
00036 #include <QLineEdit>
00037 
00038 using namespace ParaMEDMEM;
00039 
00040 //  Constructor
00041 //  Initialize qt part and private var part
00042 //  l is the MEDGUILiteStruct that will be modified, fi is a field id, for the case where one field only is selected
00043 //  First, connect button ok and cancel
00044 //  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
00045 //  Then, fill the QDialog with the file name
00046 //    For each field concerned, add the field name
00047 //      For each component, add a QCheckBox and the component name as a modifiable QLineEdit
00048 MEDGUISelectComponents::MEDGUISelectComponents(ParaMEDMEM::MEDCalculatorBrowserLiteStruct& l,QWidget *parent, int fi/*=-1*/) :
00049   QDialog(parent),
00050   ui(new Ui::MEDGUISelectComponents),
00051   ls(&l),
00052   fieldInd(fi)
00053 {
00054   ui->setupUi(this);
00055 
00056   connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(close()));// close without applying
00057   connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(fillSelection()));//  apply
00058   connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(close()));//  close
00059 
00060   int min,max;
00061   fieldInd!=-1?min=fieldInd:min=0;
00062   fieldInd!=-1?max=fieldInd:max=(int)ls->getNumberOfFields()-1;
00063 
00064   QLabel *filename = new QLabel(ls->getName().c_str(),this);
00065   ui->verticalLayout_2->insertWidget(0,filename);
00066 
00067   for (int i = max; i >= min; i -= 1)
00068     {
00069 
00070       QGridLayout *fieldLayout = new QGridLayout(this);
00071 
00072       QLabel *fieldname = new QLabel(ls->getField(i).getName().c_str(),this);
00073       fieldLayout->addWidget(fieldname,0,0,1,0);
00074 
00075 
00076       for (int j = ls->getField(i).getComponentsSize()-1; j >= 0; j -= 1)
00077         {
00078           QCheckBox *cb = new QCheckBox(this);
00079           if(ls->getField(i).getSelectedComponents()[j]){
00080             cb->setCheckState(Qt::Checked);
00081           }
00082 
00083           std::string compname ="";
00084           if(ls->getField(i).getComponents()[j] != std::string("-noname-")) compname = ls->getField(i).getComponents()[j];
00085 
00086           QLineEdit *le = new QLineEdit(compname.c_str(),this);
00087 
00088           std::ostringstream chName, leName;
00089           chName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "chkbox";
00090           leName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "namebox";
00091 
00092           cb->setObjectName(QString(chName.str().c_str()));
00093           le->setObjectName(QString(leName.str().c_str()));
00094           cb->setAccessibleName(QString(chName.str().c_str()));
00095           le->setAccessibleName(QString(leName.str().c_str()));
00096 
00097           fieldLayout->addWidget(cb,j+1,0);
00098           fieldLayout->addWidget(le,j+1,1);
00099         }
00100 
00101       ui->verticalLayout_2->insertLayout(1,fieldLayout);
00102 
00103     }
00104 }
00105 
00106 //  Destructor
00107 MEDGUISelectComponents::~MEDGUISelectComponents()
00108 {
00109   delete ui;
00110 }
00111 
00112 //  Qt specific class
00113 void MEDGUISelectComponents::changeEvent(QEvent *e)
00114 {
00115   QDialog::changeEvent(e);
00116   switch (e->type()) {
00117   case QEvent::LanguageChange:
00118     ui->retranslateUi(this);
00119     break;
00120   default:
00121     break;
00122   }
00123 }
00124 
00125 // Fill the MEDGUILiteStruct according to the selection and modification made by user
00126 // First init the min,max for the loop : if equal, just one field will be modified, else all field
00127 // Then for each field, for each component, if there is modification, they are applied (selection, unselection or rename)
00128 void MEDGUISelectComponents::fillSelection()
00129 {
00130   int min,max;
00131   fieldInd!=-1?min=fieldInd:min=0;
00132   fieldInd!=-1?max=fieldInd:max=(int)ls->getNumberOfFields()-1;
00133 
00134   for (int i = max; i >= min; i -= 1) {
00135 
00136     for (unsigned int j = 0; j < ls->getField(i).getComponentsSize(); j += 1)
00137       {
00138         std::ostringstream chName, leName;
00139         chName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "chkbox";
00140         leName << ls->getName().c_str() << ls->getField(i).getName().c_str() << j << "namebox";
00141 
00142         QCheckBox *cb = this->findChild<QCheckBox*>(QString(chName.str().c_str()));
00143         QLineEdit *le = this->findChild<QLineEdit*>(QString(leName.str().c_str()));
00144 
00145         if (cb->isChecked())
00146           {
00147             ls->getField(i).selectComponent(j);
00148           }else{
00149           ls->getField(i).unselectComponent(j);
00150         }
00151         ls->getField(i).setComponentName(j,le->text().toStdString());
00152       }
00153   }
00154 }