Optika GUI Toolik Version of the Day
Optika_ArrayWidget.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #ifndef OPTIKA_ARRAYWIDGET_HPP_
00029 #define OPTIKA_ARRAYWIDGET_HPP_
00030 
00031 #include <QDialog>
00032 #include <QModelIndex>
00033 #include <QPushButton>
00034 #include <QGridLayout>
00035 #include <QDoubleSpinBox>
00036 #include <QComboBox>
00037 #include <QLineEdit>
00038 #include <QGridLayout>
00039 #include <QScrollArea>
00040 #include <QLabel>
00041 #include <vector>
00042 #include "Optika_treemodel.hpp"
00043 #include "Optika_FileNameWidget.hpp"
00044 #include "Optika_ValidatorApplier.hpp"
00045 
00051 namespace Optika {
00052 
00060 template<class S>
00061 class GenericArrayWidget : public QDialog{
00062 
00063 public:
00064 
00068 
00077   GenericArrayWidget(
00078     QString name, 
00079     QString type, 
00080     const RCP<const ParameterEntryValidator> validator,
00081     QWidget *parent=0);
00083 
00089   const QString getType() const {
00090     return type;
00091   }
00092 
00096   const QString getName() const{
00097     return name;
00098   }
00099 
00103   const RCP<const ParameterEntryValidator> getEntryValidator() const{
00104     return entryValidator;
00105   }
00106 
00112   virtual void accept() =0;
00113 
00114 
00115 protected: 
00116 
00119   //@[
00120 
00125   virtual void setupArrayLayout(){
00126     if(arrayContainer->layout() == NULL){
00127       arrayContainer->setLayout(getArrayLayout());
00128     }
00129   }
00130 
00138   virtual QLayout* getArrayLayout() =0;  
00139 
00143   virtual void doAcceptWork() =0;
00144 
00145 
00147 
00150 
00155   QWidget *arrayContainer;
00156 
00158   
00159 
00160 private:
00161 
00164 
00168   QString type;
00169 
00173   QString name;
00174 
00178   RCP<const ParameterEntryValidator> entryValidator;  
00179 
00181 };
00182 
00183 template<class S>
00184 GenericArrayWidget<S>::GenericArrayWidget(
00185   QString name, 
00186   QString type, 
00187   const RCP<const ParameterEntryValidator> validator,
00188   QWidget *parent):
00189   QDialog(parent),
00190   type(type),
00191   name(name),
00192   entryValidator(validator)
00193 {
00194   setModal(true);
00195   setSizeGripEnabled(true);
00196   arrayContainer = new QWidget(this);
00197 
00198   QScrollArea *scrollArea = new QScrollArea(this);
00199   scrollArea->setWidget(arrayContainer);
00200   scrollArea->setWidgetResizable(true);
00201 
00202   QPushButton *doneButton = new QPushButton(tr("Done"));
00203   QPushButton *cancelButton = new QPushButton(tr("Cancel"));
00204   connect(doneButton, SIGNAL(clicked(bool)), this, SLOT(accept()));
00205   connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(reject()));
00206   QGridLayout *layout = new QGridLayout(this);
00207   layout->addWidget(scrollArea,0,0,1,3);
00208   layout->addWidget(doneButton,1,2);
00209   layout->addWidget(cancelButton,1,1);
00210 
00211   this->setLayout(layout);
00212 
00213   setWindowTitle(name);
00214 }
00215 
00221 template <class S>
00222 class Generic2DArrayWidget : public GenericArrayWidget<S>{
00223 
00224 public:
00225   
00228 
00237   Generic2DArrayWidget(
00238     QString name, 
00239     QString type, 
00240     const RCP<const ParameterEntryValidator> validator,
00241     QWidget *parent=0);
00242 
00244 
00247 
00257   void initData(TwoDArray<S> array){
00258     baseArray = array;
00259     this->setupArrayLayout();
00260   }
00261 
00269   TwoDArray<S> getArrayFromWidgets(){
00270     Teuchos::TwoDArray<QWidget*>::size_type numRows = 
00271       widgetArray.getNumRows()-1;
00272     Teuchos::TwoDArray<QWidget*>::size_type numCols = 
00273       widgetArray.getNumCols()-1;
00274     TwoDArray<S> toReturn(
00275       numRows, numCols);
00276     int numColsToIterate =0;
00277     for(int i=0; i<numRows; ++i){
00278       numColsToIterate = baseArray.isSymmetrical() ? 
00279         numCols-numRows+i : numCols;
00280       for(int j=0; j<numColsToIterate; ++j){
00281         toReturn(i,j) = getWidgetValue(i+1,j+1);
00282       }
00283     }
00284     toReturn.setSymmetrical(baseArray.isSymmetrical());
00285     return toReturn;
00286   }
00287 
00293   virtual S getWidgetValue(int row, int col) = 0;
00294 
00298   inline TwoDArray<S> getData() const{
00299     return baseArray;
00300   }
00301 
00303 
00304 protected:
00305   
00308 
00315   void doAcceptWork(){
00316     baseArray.clear();
00317     baseArray = getArrayFromWidgets();
00318     this->done(QDialog::Accepted);
00319   }
00320 
00330   virtual QWidget* getEditorWidget(int row, int col) =0;
00331 
00333 
00336 
00341   TwoDArray<QWidget*> widgetArray;
00342 
00348   TwoDArray<S> baseArray;
00349 
00351 
00352 private:
00353 
00356 
00360   QLayout* getArrayLayout();
00361 
00362 };
00363 
00364 template<class S>
00365 Generic2DArrayWidget<S>::Generic2DArrayWidget(
00366   QString name, 
00367   QString type, 
00368   const RCP<const ParameterEntryValidator> validator,
00369   QWidget *parent):
00370   GenericArrayWidget<S>(name, type, validator, parent)
00371 {}
00372 
00373 
00374 template<class S>
00375 QLayout* Generic2DArrayWidget<S>::getArrayLayout(){
00376  widgetArray = TwoDArray<QWidget*>(baseArray.getNumRows()+1, baseArray.getNumCols()+1);
00377  QGridLayout *widgetLayout = new QGridLayout;
00378   for(int i =0; i < baseArray.getNumCols(); ++i){
00379     widgetLayout->addWidget(new QLabel("Column: " +QString::number(i)),0,i+1,Qt::AlignLeft);
00380   }
00381   for(int i =0; i < baseArray.getNumRows(); ++i){
00382     widgetLayout->addWidget(new QLabel("Row: " +QString::number(i)),i+1,0,Qt::AlignLeft);
00383   }
00384   int numColsToIterate =0;
00385   for(int i =0; i < baseArray.getNumRows(); ++i){
00386     numColsToIterate = baseArray.isSymmetrical() ? 
00387       baseArray.getNumCols()-baseArray.getNumRows()+i : baseArray.getNumCols();
00388     for(int j =0; j < numColsToIterate; ++j){
00389       QWidget* editorWidget = getEditorWidget(i,j);
00390       widgetLayout->addWidget(editorWidget,i+1,j+1,Qt::AlignLeft);
00391       widgetArray(i+1,j+1) = editorWidget;
00392     }
00393   }
00394   return widgetLayout;
00395 }
00396 
00400 class Int2DArrayWidget : public Generic2DArrayWidget<int>{
00401 Q_OBJECT
00402 public:
00403 
00406 
00415   Int2DArrayWidget(
00416     QString name,
00417     QString type,
00418     const RCP<const ParameterEntryValidator> validator,
00419     QWidget *parent=0):
00420     Generic2DArrayWidget<int>(name, type, validator, parent)
00421   {}
00422 
00423 
00426 
00428   inline int getWidgetValue(int row, int col){
00429     return ((QSpinBox*)widgetArray(row,col))->value();
00430   }
00431 
00432 protected:
00433 
00435   QWidget* getEditorWidget(int row, int col){
00436     QSpinBox *newSpin = new QSpinBox(this);
00437     RCP<const EnhancedNumberValidator<int> > validator = null;
00438     if(!is_null(getEntryValidator())){
00439       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<int>, int> >(getEntryValidator(),true)->getPrototype();
00440     }
00441     ValidatorApplier<int>::applyToSpinBox(validator, newSpin);
00442     newSpin->setValue(baseArray(row, col));
00443     return newSpin;
00444   }
00445 
00447 
00448 public slots:
00451 
00453   void accept(){
00454     doAcceptWork();
00455   }
00456 
00458 
00459 };
00460 
00464 class Short2DArrayWidget : public Generic2DArrayWidget<short>{
00465 Q_OBJECT
00466 public:
00467 
00470 
00479   Short2DArrayWidget(
00480     QString name,
00481     QString type,
00482     const RCP<const ParameterEntryValidator> validator,
00483     QWidget *parent=0):
00484     Generic2DArrayWidget<short>(name, type, validator, parent)
00485   {}
00486 
00488 
00491 
00493   inline short getWidgetValue(int row, int col){
00494     return ((QSpinBox*)widgetArray(row,col))->value();
00495   }
00496 
00497 protected:
00498 
00500   QWidget* getEditorWidget(int row, int col){
00501     QSpinBox *newSpin = new QSpinBox(this);
00502     RCP<const EnhancedNumberValidator<short> > validator = null;
00503     if(!is_null(getEntryValidator())){
00504       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<short>, short> >(getEntryValidator(),true)->getPrototype();
00505     }
00506     ValidatorApplier<short>::applyToSpinBox(validator, newSpin);
00507     newSpin->setValue(baseArray(row, col));
00508     return newSpin;
00509   }
00510 
00512 
00513 public slots:
00514 
00517 
00519   void accept(){
00520     doAcceptWork();
00521   }
00522 
00524 
00525 };
00526 
00530 class Double2DArrayWidget : public Generic2DArrayWidget<double>{
00531 Q_OBJECT
00532 public:
00533 
00536 
00545   Double2DArrayWidget(
00546     QString name,
00547     QString type,
00548     const RCP<const ParameterEntryValidator> validator,
00549     QWidget *parent=0):
00550     Generic2DArrayWidget<double>(name, type, validator, parent)
00551   {}
00552 
00554 
00557 
00559   inline double getWidgetValue(int row, int col){
00560     return ((QLineEdit*)widgetArray(row,col))->text().toDouble();
00561   }
00562 
00563 protected:
00564 
00566   QWidget* getEditorWidget(int row, int col){
00567     QLineEdit *newEdit = new QLineEdit(this);
00568     RCP<const EnhancedNumberValidator<double> > validator = null;
00569     if(!is_null(getEntryValidator())){
00570       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<double>, double> >(getEntryValidator(),true)->getPrototype();
00571     }
00572     ValidatorApplier<double>::applyToLineEdit(validator, newEdit);
00573     newEdit->setText(QString::number(baseArray(row,col)));
00574     return newEdit;
00575   }
00576 
00578 
00579 public slots:
00580 
00583 
00584   void accept(){
00585     doAcceptWork();
00586   }
00587 
00589 
00590 };
00591 
00595 class Float2DArrayWidget : public Generic2DArrayWidget<float>{
00596 Q_OBJECT
00597 public:
00598 
00601 
00610   Float2DArrayWidget(
00611     QString name,
00612     QString type,
00613     const RCP<const ParameterEntryValidator> validator,
00614     QWidget *parent=0):
00615     Generic2DArrayWidget<float>(name, type, validator, parent)
00616   {}
00617 
00619 
00622 
00624   inline float getWidgetValue(int row, int col){
00625     return ((QLineEdit*)widgetArray(row,col))->text().toDouble();
00626   }
00627 
00628 protected:
00629 
00631   QWidget* getEditorWidget(int row, int col){
00632     QLineEdit *newEdit = new QLineEdit(this);
00633     RCP<const EnhancedNumberValidator<float> > validator = null;
00634     if(!is_null(getEntryValidator())){
00635       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<float>, float> >(getEntryValidator(),true)->getPrototype();
00636     }
00637     ValidatorApplier<float>::applyToLineEdit(validator, newEdit);
00638     newEdit->setText(QString::number(baseArray(row,col)));
00639     return newEdit;
00640   }
00641 
00643 
00644 public slots:
00645 
00648 
00649   void accept(){
00650     doAcceptWork();
00651   }
00652 
00654 
00655 };
00656 
00660 class String2DArrayWidget : public Generic2DArrayWidget<std::string>{
00661 Q_OBJECT
00662 public:
00663 
00666 
00675   String2DArrayWidget(
00676     QString name,
00677     QString type,
00678     const RCP<const ParameterEntryValidator> validator,
00679     QWidget *parent=0):
00680     Generic2DArrayWidget<std::string>(name, type, validator, parent)
00681   {}
00682 
00684 
00687 
00689   std::string getWidgetValue(int row, int col){
00690     if(is_null(getEntryValidator())){
00691        return ((QLineEdit*)widgetArray(row,col))->text().toStdString();
00692     }
00693     else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
00694        return ((FileNameWidget*)widgetArray(row,col))->getCurrentFileName().toStdString();
00695     }
00696     else if(getEntryValidator()->validStringValues()->size() !=0){
00697        return  ((QComboBox*)widgetArray(row,col))->currentText().toStdString();
00698     }
00699     else{
00700        return  ((QLineEdit*)widgetArray(row,col))->text().toStdString();
00701     }
00702   }
00703 
00704 protected:
00705 
00707   QWidget* getEditorWidget(int row, int col){
00708     QString currentData = QString::fromStdString(baseArray(row,col));
00709     if(is_null(getEntryValidator())){
00710       return new QLineEdit(currentData,this);
00711     }
00712     else if(!is_null(rcp_dynamic_cast<const TwoDArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
00713       return new FileNameWidget(
00714         currentData, 
00715         rcp_dynamic_cast<const TwoDArrayValidator<FileNameValidator, std::string> >(getEntryValidator())->getPrototype()->fileMustExist(), this);
00716     }
00717     else if(getEntryValidator()->validStringValues()->size() != 0){
00718       RCP<const Array<std::string> > options = getEntryValidator()->validStringValues();
00719       QComboBox *newCombo = new QComboBox(this);
00720       for(Array<std::string>::const_iterator itr = options->begin(); itr != options->end(); ++itr){
00721         newCombo->addItem(QString::fromStdString(*itr));
00722       }
00723       int selectedItem = newCombo->findText(currentData);
00724       newCombo->setCurrentIndex(selectedItem);
00725       return newCombo;
00726     }
00727     else{
00728       return new QLineEdit(currentData,this);
00729     }
00730   }
00731 
00733 
00734 public slots:
00737 
00739   void accept(){
00740     doAcceptWork();
00741   }
00742 
00744 
00745 };
00746 
00752 template <class S>
00753 class Generic1DArrayWidget : public GenericArrayWidget<S>{
00754 public:
00755 
00758 
00767   Generic1DArrayWidget(
00768     QString name, 
00769     QString type, 
00770     const RCP<const ParameterEntryValidator> validator,
00771     QWidget *parent=0);
00772 
00774   
00776 
00777 
00778 
00784   const Array<S> getData() const{
00785     return baseArray;
00786   }
00787 
00789 
00790 
00793 
00803   void initData(Array<S> array){
00804     baseArray = array;
00805     this->setupArrayLayout();
00806   }
00807 
00811   virtual QWidget* getEditorWidget(int index) = 0;
00812 
00818   virtual Array<S> getArrayFromWidgets() = 0;
00819 
00820 
00822 
00823 protected:
00824 
00827 
00831   typedef std::vector<QWidget*> WVector;
00832 
00834 
00837 
00841   WVector widgetVector;
00842 
00846   Array<S> baseArray;
00847   
00849 
00852 
00854   void doAcceptWork();
00855 
00857 
00858 private:
00859 
00862 
00863   QLayout* getArrayLayout();
00864 
00866 };
00867 
00868 template<class S>
00869 Generic1DArrayWidget<S>::Generic1DArrayWidget(
00870   QString name, 
00871   QString type, 
00872   const RCP<const ParameterEntryValidator> validator,
00873   QWidget *parent):
00874   GenericArrayWidget<S>(name, type, validator, parent)
00875 {}
00876 
00877 
00878 template<class S>
00879 QLayout* Generic1DArrayWidget<S>::getArrayLayout(){
00880   QGridLayout *widgetLayout = new QGridLayout;
00881   for(int i=0; i<baseArray.size(); ++i){
00882     widgetLayout->addWidget(new QLabel("Item: " +QString::number(i)),0,i,Qt::AlignLeft);
00883     QWidget* editorWidget = getEditorWidget(i);
00884     widgetLayout->addWidget(editorWidget,1,i,Qt::AlignLeft);
00885     widgetVector.push_back(editorWidget);
00886   }
00887   return widgetLayout;
00888 }
00889 
00890 template<class S>
00891 void Generic1DArrayWidget<S>::doAcceptWork(){
00892   baseArray.clear();
00893   baseArray = getArrayFromWidgets();
00894   this->done(QDialog::Accepted);
00895 }
00896 
00900 class IntArrayWidget: public Generic1DArrayWidget<int>{
00901   Q_OBJECT
00902 public:
00903 
00906 
00915   IntArrayWidget(
00916     QString name, 
00917     QString type, 
00918     const RCP<const ParameterEntryValidator> validator,
00919     QWidget *parent=0):
00920     Generic1DArrayWidget<int>(name, type, validator,parent){}
00921 
00923 
00926   
00930   Array<int> getArrayFromWidgets(){
00931     Array<int> toReturn(widgetVector.size(), 0);
00932     for(size_t i=0; i < widgetVector.size(); ++i){
00933       toReturn[i]= ((QSpinBox*)widgetVector[i])->value();
00934     }
00935     return toReturn;
00936   }
00937 
00938 private:
00939 
00943   QWidget* getEditorWidget(int index){
00944     QSpinBox *newSpin = new QSpinBox(this);
00945     RCP<const EnhancedNumberValidator<int> > validator = null;
00946     if(!is_null(getEntryValidator())){
00947       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<int>, int> >(getEntryValidator(),true)->getPrototype();
00948     }
00949     ValidatorApplier<int>::applyToSpinBox(validator, newSpin);
00950     newSpin->setValue(baseArray[index]);
00951     return newSpin;
00952   }
00953 
00955 
00956 
00957 public slots:
00958 
00961 
00963   void accept(){
00964     doAcceptWork();
00965   }
00966 
00968 
00969 };
00970 
00974 class ShortArrayWidget: public Generic1DArrayWidget<short>
00975 {
00976   Q_OBJECT
00977 public:
00978 
00981 
00990   ShortArrayWidget(
00991     QString name, 
00992     QString type, 
00993     const RCP<const ParameterEntryValidator> validator,
00994     QWidget *parent=0):
00995     Generic1DArrayWidget<short>(name, type, validator,parent){}
00996 
00998 
01001 
01003   Array<short> getArrayFromWidgets(){
01004     Array<short> toReturn(widgetVector.size(), 0);
01005     for(size_t i=0; i < widgetVector.size(); ++i){
01006       toReturn[i]= ((QSpinBox*)widgetVector[i])->value();
01007     }
01008     return toReturn;
01009   }
01010 
01011 
01012 private:
01013 
01015   QWidget* getEditorWidget(int index){
01016     QSpinBox *newSpin = new QSpinBox(this);
01017     RCP<const EnhancedNumberValidator<short> > validator = null;
01018     if(!is_null(getEntryValidator())){
01019       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<short>, short> >(getEntryValidator(),true)->getPrototype();
01020     }
01021     ValidatorApplier<short>::applyToSpinBox(validator, newSpin);
01022     newSpin->setValue(baseArray[index]);
01023     return newSpin;
01024   }
01025 
01027 
01028 public slots:
01031 
01033   void accept(){
01034     doAcceptWork();
01035   }
01036 
01038 };
01039 
01043 class DoubleArrayWidget: public Generic1DArrayWidget<double>
01044 {
01045   Q_OBJECT
01046 public:
01047 
01050 
01059   DoubleArrayWidget(
01060     QString name, 
01061     QString type, 
01062     const RCP<const ParameterEntryValidator> validator,
01063     QWidget *parent=0):
01064     Generic1DArrayWidget<double>(name, type, validator,parent){}
01065 
01067 
01070 
01072   Array<double> getArrayFromWidgets(){
01073     Array<double> toReturn(widgetVector.size(), 0.0);
01074     for(size_t i=0; i < widgetVector.size(); ++i){
01075       toReturn[i]= ((QLineEdit*)widgetVector[i])->text().toDouble();
01076     }
01077     return toReturn;
01078   }
01079 
01080 private:
01081 
01083   QWidget* getEditorWidget(int index){
01084     QLineEdit *newEdit = new QLineEdit(this);
01085     RCP<const EnhancedNumberValidator<double> > validator = null;
01086     if(!is_null(getEntryValidator())){
01087       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<double>, double> >(getEntryValidator(),true)->getPrototype();
01088     }
01089     ValidatorApplier<double>::applyToLineEdit(validator, newEdit);
01090     newEdit->setText(QString::number(baseArray[index], 'g', ((QDoubleValidator*)newEdit->validator())->decimals()));
01091     return newEdit;
01092   }
01093 
01095   
01096 public slots:
01099 
01101   void accept(){
01102     doAcceptWork();
01103   }
01104 
01106 
01107 };
01108 
01112 class FloatArrayWidget: public Generic1DArrayWidget<float>
01113 {
01114   Q_OBJECT
01115 public:
01118 
01127   FloatArrayWidget(
01128     QString name, 
01129     QString type, 
01130     const RCP<const ParameterEntryValidator> validator,
01131     QWidget *parent=0):
01132     Generic1DArrayWidget<float>(name, type, validator,parent){}
01133 
01135   
01138 
01140   Array<float> getArrayFromWidgets(){
01141     Array<float> toReturn(widgetVector.size(), 0.0);
01142     for(size_t i=0; i < widgetVector.size(); ++i){
01143       toReturn[i]= ((QLineEdit*)widgetVector[i])->text().toDouble();
01144     }
01145     return toReturn;
01146   }
01147 
01148 private:
01149 
01151   QWidget* getEditorWidget(int index){
01152     QLineEdit *newEdit = new QLineEdit(this);
01153     RCP<const EnhancedNumberValidator<float> > validator = null;
01154     if(!is_null(getEntryValidator())){
01155       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<float>, float> >(getEntryValidator(),true)->getPrototype();
01156     }
01157     ValidatorApplier<float>::applyToLineEdit(validator, newEdit);
01158     newEdit->setText(QString::number(baseArray[index], 'g', ((QDoubleValidator*)newEdit->validator())->decimals()));
01159     return newEdit;
01160   }
01161 
01162 
01164 
01165 public slots:
01166 
01169 
01171   void accept(){
01172     doAcceptWork();
01173   }
01174 
01176 
01177 };
01178 
01182 class StringArrayWidget : public Generic1DArrayWidget<std::string>{
01183   Q_OBJECT
01184 public:
01185 
01188 
01197   StringArrayWidget(
01198     QString name, 
01199     QString type, 
01200     const RCP<const ParameterEntryValidator> validator,
01201     QWidget *parent=0):
01202     Generic1DArrayWidget<std::string>(name, type, validator,parent)
01203   {}
01204 
01206 
01209 
01211   Array<std::string> getArrayFromWidgets(){
01212     Array<std::string> toReturn(widgetVector.size(), "");
01213     for(size_t i=0; i < widgetVector.size(); ++i){
01214       if(is_null(getEntryValidator())){
01215         toReturn[i] = ((QLineEdit*)widgetVector[i])->text().toStdString();
01216       }
01217       else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
01218         toReturn[i] = ((FileNameWidget*)widgetVector[i])->getCurrentFileName().toStdString();
01219       }
01220       else if(getEntryValidator()->validStringValues()->size() !=0){
01221         toReturn[i] = ((QComboBox*)widgetVector[i])->currentText().toStdString();
01222       }
01223       else{
01224         toReturn[i] = ((QLineEdit*)widgetVector[i])->text().toStdString();
01225       }
01226     }
01227     return toReturn;
01228   }
01229 
01230 private:
01231 
01233   QWidget* getEditorWidget(int index){
01234     QString currentData = QString::fromStdString(baseArray[index]);
01235     if(is_null(getEntryValidator())){
01236       return new QLineEdit(currentData,this);
01237     }
01238     else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
01239       return new FileNameWidget(
01240         currentData, 
01241         rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator())->getPrototype()->fileMustExist(), this);
01242     }
01243     else if(getEntryValidator()->validStringValues()->size() != 0){
01244       RCP<const Array<std::string> > options = getEntryValidator()->validStringValues();
01245       QComboBox *newCombo = new QComboBox(this);
01246       for(Array<std::string>::const_iterator itr = options->begin(); itr != options->end(); ++itr){
01247         newCombo->addItem(QString::fromStdString(*itr));
01248       }
01249       int selectedItem = newCombo->findText(currentData);
01250       newCombo->setCurrentIndex(selectedItem);
01251       return newCombo;
01252     }
01253     else{
01254       return new QLineEdit(currentData,this);
01255     }
01256   }
01257 
01259 
01260 public slots:
01261 
01264 
01266   void accept(){
01267     doAcceptWork();
01268   }
01269 
01271 
01272 
01273 };
01274 
01275 
01276 } //end namespace
01277 #endif //OPTIKA_ARRAYWIDGET_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines