Back to index

salome-paravis  6.5.0
pqTableReaderPanel.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
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 #include "pqTableReaderPanel.h"
00021 
00022 #include "vtkSMProxy.h"
00023 #include "vtkSMStringVectorProperty.h"
00024 #include "vtkProcessModule.h"
00025 
00026 #include "pqPropertyLinks.h"
00027 
00028 #include <QLayout>
00029 #include <QSpinBox>
00030 
00031 
00032 class pqTableReaderPanel::pqUI: public QObject, public Ui::TableReaderPanel
00033 {
00034 public:
00035   pqUI(pqTableReaderPanel* p) : QObject(p)
00036   {
00037   }
00038 
00039   ~pqUI()
00040   {
00041   }
00042 
00043   pqPropertyLinks Links;
00044 };
00045 
00046 
00047 pqTableReaderPanel::pqTableReaderPanel(pqProxy* proxy, QWidget* p) :
00048   Superclass(proxy, p)
00049 {
00050   this->UI = new pqUI(this);
00051   this->UI->setupUi(this);
00052   
00053   this->linkServerManagerProperties();
00054   this->updateAvailableTables(false);
00055 
00056   this->connect(this->UI->ValueDelimiter, SIGNAL(textChanged(const QString&)),
00057               this, SLOT(onDelimiterChanged(const QString&)));
00058   this->connect(this->UI->TableNames, SIGNAL(currentIndexChanged(int)),
00059               this, SLOT(onCurrentTableChanged(int)));
00060 }
00061 
00062 pqTableReaderPanel::~pqTableReaderPanel()
00063 {
00064 }
00065 
00066 void pqTableReaderPanel::onCurrentTableChanged(int currentTableIndex)
00067 {
00068   this->setModified();
00069 }
00070 
00071 void pqTableReaderPanel::onDelimiterChanged(const QString& value)
00072 {
00073   this->updateAvailableTables(true);
00074 }
00075 
00076 void pqTableReaderPanel::linkServerManagerProperties()
00077 {
00078   this->UI->Links.addPropertyLink(this->UI->TableNames, "currentIndex",
00079          SIGNAL(currentIndexChanged(int)), this->proxy(), 
00080          this->proxy()->GetProperty("TableNumber"));
00081 
00082   // To hook up the rest widgets
00083   this->Superclass::linkServerManagerProperties();
00084 }
00085 
00086 void pqTableReaderPanel::updateAvailableTables(const bool keepCurrent)
00087 {
00088   vtkSMStringVectorProperty* prop = vtkSMStringVectorProperty::SafeDownCast(
00089                              this->proxy()->GetProperty("AvailableTables"));
00090   
00091   int currentIndex = this->UI->TableNames->currentIndex();
00092   QString currentText = this->UI->TableNames->currentText();
00093 
00094   this->UI->TableNames->clear();
00095   
00096   for(int id = 0; id < prop->GetNumberOfElements(); id++) 
00097     {
00098       QString text(prop->GetElement(id));
00099       if (text.isEmpty()) 
00100        {
00101          text = QString("Table:%1").arg(id);
00102        }
00103       this->UI->TableNames->addItem(text);
00104     }
00105 
00106   if (keepCurrent && 
00107       currentIndex < this->UI->TableNames->maxCount() &&
00108       currentText == this->UI->TableNames->itemText(currentIndex)) 
00109     {
00110       this->UI->TableNames->setCurrentIndex(currentIndex);
00111     }
00112 }