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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #ifndef OPTIKA_ARRAYWIDGET_HPP_
00042 #define OPTIKA_ARRAYWIDGET_HPP_
00043 
00044 #include <QDialog>
00045 #include <QModelIndex>
00046 #include <QPushButton>
00047 #include <QGridLayout>
00048 #include <QDoubleSpinBox>
00049 #include <QComboBox>
00050 #include <QLineEdit>
00051 #include <QGridLayout>
00052 #include <QScrollArea>
00053 #include <QLabel>
00054 #include <vector>
00055 #include "Optika_treemodel.hpp"
00056 #include "Optika_FileNameWidget.hpp"
00057 #include "Optika_ValidatorApplier.hpp"
00058 
00064 namespace Optika {
00065 
00073 template<class S>
00074 class GenericArrayWidget : public QDialog{
00075 
00076 public:
00077 
00081 
00090   GenericArrayWidget(
00091     QString name, 
00092     QString type, 
00093     const RCP<const ParameterEntryValidator> validator,
00094     QWidget *parent=0);
00096 
00102   const QString getType() const {
00103     return type;
00104   }
00105 
00109   const QString getName() const{
00110     return name;
00111   }
00112 
00116   const RCP<const ParameterEntryValidator> getEntryValidator() const{
00117     return entryValidator;
00118   }
00119 
00125   virtual void accept() =0;
00126 
00127 
00128 protected: 
00129 
00132   //@[
00133 
00138   virtual void setupArrayLayout(){
00139     if(arrayContainer->layout() == NULL){
00140       arrayContainer->setLayout(getArrayLayout());
00141     }
00142   }
00143 
00151   virtual QLayout* getArrayLayout() =0;  
00152 
00156   virtual void doAcceptWork() =0;
00157 
00158 
00160 
00163 
00168   QWidget *arrayContainer;
00169 
00171   
00172 
00173 private:
00174 
00177 
00181   QString type;
00182 
00186   QString name;
00187 
00191   RCP<const ParameterEntryValidator> entryValidator;  
00192 
00194 };
00195 
00196 template<class S>
00197 GenericArrayWidget<S>::GenericArrayWidget(
00198   QString name, 
00199   QString type, 
00200   const RCP<const ParameterEntryValidator> validator,
00201   QWidget *parent):
00202   QDialog(parent),
00203   type(type),
00204   name(name),
00205   entryValidator(validator)
00206 {
00207   setModal(true);
00208   setSizeGripEnabled(true);
00209   arrayContainer = new QWidget(this);
00210 
00211   QScrollArea *scrollArea = new QScrollArea(this);
00212   scrollArea->setWidget(arrayContainer);
00213   scrollArea->setWidgetResizable(true);
00214 
00215   QPushButton *doneButton = new QPushButton(tr("Done"));
00216   QPushButton *cancelButton = new QPushButton(tr("Cancel"));
00217   connect(doneButton, SIGNAL(clicked(bool)), this, SLOT(accept()));
00218   connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(reject()));
00219   QGridLayout *layout = new QGridLayout(this);
00220   layout->addWidget(scrollArea,0,0,1,3);
00221   layout->addWidget(doneButton,1,2);
00222   layout->addWidget(cancelButton,1,1);
00223 
00224   this->setLayout(layout);
00225 
00226   setWindowTitle(name);
00227 }
00228 
00234 template <class S>
00235 class Generic2DArrayWidget : public GenericArrayWidget<S>{
00236 
00237 public:
00238   
00241 
00250   Generic2DArrayWidget(
00251     QString name, 
00252     QString type, 
00253     const RCP<const ParameterEntryValidator> validator,
00254     QWidget *parent=0);
00255 
00257 
00260 
00270   void initData(TwoDArray<S> array){
00271     baseArray = array;
00272     this->setupArrayLayout();
00273   }
00274 
00282   TwoDArray<S> getArrayFromWidgets(){
00283     Teuchos::TwoDArray<QWidget*>::size_type numRows = 
00284       widgetArray.getNumRows()-1;
00285     Teuchos::TwoDArray<QWidget*>::size_type numCols = 
00286       widgetArray.getNumCols()-1;
00287     TwoDArray<S> toReturn(
00288       numRows, numCols);
00289     int numColsToIterate =0;
00290     for(int i=0; i<numRows; ++i){
00291       numColsToIterate = baseArray.isSymmetrical() ? 
00292         numCols-numRows+i : numCols;
00293       for(int j=0; j<numColsToIterate; ++j){
00294         toReturn(i,j) = getWidgetValue(i+1,j+1);
00295       }
00296     }
00297     toReturn.setSymmetrical(baseArray.isSymmetrical());
00298     return toReturn;
00299   }
00300 
00306   virtual S getWidgetValue(int row, int col) = 0;
00307 
00311   inline TwoDArray<S> getData() const{
00312     return baseArray;
00313   }
00314 
00316 
00317 protected:
00318   
00321 
00328   void doAcceptWork(){
00329     baseArray.clear();
00330     baseArray = getArrayFromWidgets();
00331     this->done(QDialog::Accepted);
00332   }
00333 
00343   virtual QWidget* getEditorWidget(int row, int col) =0;
00344 
00346 
00349 
00354   TwoDArray<QWidget*> widgetArray;
00355 
00361   TwoDArray<S> baseArray;
00362 
00364 
00365 private:
00366 
00369 
00373   QLayout* getArrayLayout();
00374 
00375 };
00376 
00377 template<class S>
00378 Generic2DArrayWidget<S>::Generic2DArrayWidget(
00379   QString name, 
00380   QString type, 
00381   const RCP<const ParameterEntryValidator> validator,
00382   QWidget *parent):
00383   GenericArrayWidget<S>(name, type, validator, parent)
00384 {}
00385 
00386 
00387 template<class S>
00388 QLayout* Generic2DArrayWidget<S>::getArrayLayout(){
00389  widgetArray = TwoDArray<QWidget*>(baseArray.getNumRows()+1, baseArray.getNumCols()+1);
00390  QGridLayout *widgetLayout = new QGridLayout;
00391   for(int i =0; i < baseArray.getNumCols(); ++i){
00392     widgetLayout->addWidget(new QLabel("Column: " +QString::number(i)),0,i+1,Qt::AlignLeft);
00393   }
00394   for(int i =0; i < baseArray.getNumRows(); ++i){
00395     widgetLayout->addWidget(new QLabel("Row: " +QString::number(i)),i+1,0,Qt::AlignLeft);
00396   }
00397   int numColsToIterate =0;
00398   for(int i =0; i < baseArray.getNumRows(); ++i){
00399     numColsToIterate = baseArray.isSymmetrical() ? 
00400       baseArray.getNumCols()-baseArray.getNumRows()+i : baseArray.getNumCols();
00401     for(int j =0; j < numColsToIterate; ++j){
00402       QWidget* editorWidget = getEditorWidget(i,j);
00403       widgetLayout->addWidget(editorWidget,i+1,j+1,Qt::AlignLeft);
00404       widgetArray(i+1,j+1) = editorWidget;
00405     }
00406   }
00407   return widgetLayout;
00408 }
00409 
00413 class Int2DArrayWidget : public Generic2DArrayWidget<int>{
00414 Q_OBJECT
00415 public:
00416 
00419 
00428   Int2DArrayWidget(
00429     QString name,
00430     QString type,
00431     const RCP<const ParameterEntryValidator> validator,
00432     QWidget *parent=0):
00433     Generic2DArrayWidget<int>(name, type, validator, parent)
00434   {}
00435 
00436 
00439 
00441   inline int getWidgetValue(int row, int col){
00442     return ((QSpinBox*)widgetArray(row,col))->value();
00443   }
00444 
00445 protected:
00446 
00448   QWidget* getEditorWidget(int row, int col){
00449     QSpinBox *newSpin = new QSpinBox(this);
00450     RCP<const EnhancedNumberValidator<int> > validator = null;
00451     if(!is_null(getEntryValidator())){
00452       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<int>, int> >(getEntryValidator(),true)->getPrototype();
00453     }
00454     ValidatorApplier<int>::applyToSpinBox(validator, newSpin);
00455     newSpin->setValue(baseArray(row, col));
00456     return newSpin;
00457   }
00458 
00460 
00461 public slots:
00464 
00466   void accept(){
00467     doAcceptWork();
00468   }
00469 
00471 
00472 };
00473 
00477 class Short2DArrayWidget : public Generic2DArrayWidget<short>{
00478 Q_OBJECT
00479 public:
00480 
00483 
00492   Short2DArrayWidget(
00493     QString name,
00494     QString type,
00495     const RCP<const ParameterEntryValidator> validator,
00496     QWidget *parent=0):
00497     Generic2DArrayWidget<short>(name, type, validator, parent)
00498   {}
00499 
00501 
00504 
00506   inline short getWidgetValue(int row, int col){
00507     return ((QSpinBox*)widgetArray(row,col))->value();
00508   }
00509 
00510 protected:
00511 
00513   QWidget* getEditorWidget(int row, int col){
00514     QSpinBox *newSpin = new QSpinBox(this);
00515     RCP<const EnhancedNumberValidator<short> > validator = null;
00516     if(!is_null(getEntryValidator())){
00517       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<short>, short> >(getEntryValidator(),true)->getPrototype();
00518     }
00519     ValidatorApplier<short>::applyToSpinBox(validator, newSpin);
00520     newSpin->setValue(baseArray(row, col));
00521     return newSpin;
00522   }
00523 
00525 
00526 public slots:
00527 
00530 
00532   void accept(){
00533     doAcceptWork();
00534   }
00535 
00537 
00538 };
00539 
00543 class Double2DArrayWidget : public Generic2DArrayWidget<double>{
00544 Q_OBJECT
00545 public:
00546 
00549 
00558   Double2DArrayWidget(
00559     QString name,
00560     QString type,
00561     const RCP<const ParameterEntryValidator> validator,
00562     QWidget *parent=0):
00563     Generic2DArrayWidget<double>(name, type, validator, parent)
00564   {}
00565 
00567 
00570 
00572   inline double getWidgetValue(int row, int col){
00573     return ((QLineEdit*)widgetArray(row,col))->text().toDouble();
00574   }
00575 
00576 protected:
00577 
00579   QWidget* getEditorWidget(int row, int col){
00580     QLineEdit *newEdit = new QLineEdit(this);
00581     RCP<const EnhancedNumberValidator<double> > validator = null;
00582     if(!is_null(getEntryValidator())){
00583       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<double>, double> >(getEntryValidator(),true)->getPrototype();
00584     }
00585     ValidatorApplier<double>::applyToLineEdit(validator, newEdit);
00586     newEdit->setText(QString::number(baseArray(row,col)));
00587     return newEdit;
00588   }
00589 
00591 
00592 public slots:
00593 
00596 
00597   void accept(){
00598     doAcceptWork();
00599   }
00600 
00602 
00603 };
00604 
00608 class Float2DArrayWidget : public Generic2DArrayWidget<float>{
00609 Q_OBJECT
00610 public:
00611 
00614 
00623   Float2DArrayWidget(
00624     QString name,
00625     QString type,
00626     const RCP<const ParameterEntryValidator> validator,
00627     QWidget *parent=0):
00628     Generic2DArrayWidget<float>(name, type, validator, parent)
00629   {}
00630 
00632 
00635 
00637   inline float getWidgetValue(int row, int col){
00638     return ((QLineEdit*)widgetArray(row,col))->text().toDouble();
00639   }
00640 
00641 protected:
00642 
00644   QWidget* getEditorWidget(int row, int col){
00645     QLineEdit *newEdit = new QLineEdit(this);
00646     RCP<const EnhancedNumberValidator<float> > validator = null;
00647     if(!is_null(getEntryValidator())){
00648       validator = rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<float>, float> >(getEntryValidator(),true)->getPrototype();
00649     }
00650     ValidatorApplier<float>::applyToLineEdit(validator, newEdit);
00651     newEdit->setText(QString::number(baseArray(row,col)));
00652     return newEdit;
00653   }
00654 
00656 
00657 public slots:
00658 
00661 
00662   void accept(){
00663     doAcceptWork();
00664   }
00665 
00667 
00668 };
00669 
00673 class String2DArrayWidget : public Generic2DArrayWidget<std::string>{
00674 Q_OBJECT
00675 public:
00676 
00679 
00688   String2DArrayWidget(
00689     QString name,
00690     QString type,
00691     const RCP<const ParameterEntryValidator> validator,
00692     QWidget *parent=0):
00693     Generic2DArrayWidget<std::string>(name, type, validator, parent)
00694   {}
00695 
00697 
00700 
00702   std::string getWidgetValue(int row, int col){
00703     if(is_null(getEntryValidator())){
00704        return ((QLineEdit*)widgetArray(row,col))->text().toStdString();
00705     }
00706     else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
00707        return ((FileNameWidget*)widgetArray(row,col))->getCurrentFileName().toStdString();
00708     }
00709     else if(getEntryValidator()->validStringValues()->size() !=0){
00710        return  ((QComboBox*)widgetArray(row,col))->currentText().toStdString();
00711     }
00712     else{
00713        return  ((QLineEdit*)widgetArray(row,col))->text().toStdString();
00714     }
00715   }
00716 
00717 protected:
00718 
00720   QWidget* getEditorWidget(int row, int col){
00721     QString currentData = QString::fromStdString(baseArray(row,col));
00722     if(is_null(getEntryValidator())){
00723       return new QLineEdit(currentData,this);
00724     }
00725     else if(!is_null(rcp_dynamic_cast<const TwoDArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
00726       return new FileNameWidget(
00727         currentData, 
00728         rcp_dynamic_cast<const TwoDArrayValidator<FileNameValidator, std::string> >(getEntryValidator())->getPrototype()->fileMustExist(), this);
00729     }
00730     else if(getEntryValidator()->validStringValues()->size() != 0){
00731       RCP<const Array<std::string> > options = getEntryValidator()->validStringValues();
00732       QComboBox *newCombo = new QComboBox(this);
00733       for(Array<std::string>::const_iterator itr = options->begin(); itr != options->end(); ++itr){
00734         newCombo->addItem(QString::fromStdString(*itr));
00735       }
00736       int selectedItem = newCombo->findText(currentData);
00737       newCombo->setCurrentIndex(selectedItem);
00738       return newCombo;
00739     }
00740     else{
00741       return new QLineEdit(currentData,this);
00742     }
00743   }
00744 
00746 
00747 public slots:
00750 
00752   void accept(){
00753     doAcceptWork();
00754   }
00755 
00757 
00758 };
00759 
00765 template <class S>
00766 class Generic1DArrayWidget : public GenericArrayWidget<S>{
00767 public:
00768 
00771 
00780   Generic1DArrayWidget(
00781     QString name, 
00782     QString type, 
00783     const RCP<const ParameterEntryValidator> validator,
00784     QWidget *parent=0);
00785 
00787   
00789 
00790 
00791 
00797   const Array<S> getData() const{
00798     return baseArray;
00799   }
00800 
00802 
00803 
00806 
00816   void initData(Array<S> array){
00817     baseArray = array;
00818     this->setupArrayLayout();
00819   }
00820 
00824   virtual QWidget* getEditorWidget(int index) = 0;
00825 
00831   virtual Array<S> getArrayFromWidgets() = 0;
00832 
00833 
00835 
00836 protected:
00837 
00840 
00844   typedef std::vector<QWidget*> WVector;
00845 
00847 
00850 
00854   WVector widgetVector;
00855 
00859   Array<S> baseArray;
00860   
00862 
00865 
00867   void doAcceptWork();
00868 
00870 
00871 private:
00872 
00875 
00876   QLayout* getArrayLayout();
00877 
00879 };
00880 
00881 template<class S>
00882 Generic1DArrayWidget<S>::Generic1DArrayWidget(
00883   QString name, 
00884   QString type, 
00885   const RCP<const ParameterEntryValidator> validator,
00886   QWidget *parent):
00887   GenericArrayWidget<S>(name, type, validator, parent)
00888 {}
00889 
00890 
00891 template<class S>
00892 QLayout* Generic1DArrayWidget<S>::getArrayLayout(){
00893   QGridLayout *widgetLayout = new QGridLayout;
00894   for(int i=0; i<baseArray.size(); ++i){
00895     widgetLayout->addWidget(new QLabel("Item: " +QString::number(i)),0,i,Qt::AlignLeft);
00896     QWidget* editorWidget = getEditorWidget(i);
00897     widgetLayout->addWidget(editorWidget,1,i,Qt::AlignLeft);
00898     widgetVector.push_back(editorWidget);
00899   }
00900   return widgetLayout;
00901 }
00902 
00903 template<class S>
00904 void Generic1DArrayWidget<S>::doAcceptWork(){
00905   baseArray.clear();
00906   baseArray = getArrayFromWidgets();
00907   this->done(QDialog::Accepted);
00908 }
00909 
00913 class IntArrayWidget: public Generic1DArrayWidget<int>{
00914   Q_OBJECT
00915 public:
00916 
00919 
00928   IntArrayWidget(
00929     QString name, 
00930     QString type, 
00931     const RCP<const ParameterEntryValidator> validator,
00932     QWidget *parent=0):
00933     Generic1DArrayWidget<int>(name, type, validator,parent){}
00934 
00936 
00939   
00943   Array<int> getArrayFromWidgets(){
00944     Array<int> toReturn(widgetVector.size(), 0);
00945     for(size_t i=0; i < widgetVector.size(); ++i){
00946       toReturn[i]= ((QSpinBox*)widgetVector[i])->value();
00947     }
00948     return toReturn;
00949   }
00950 
00951 private:
00952 
00956   QWidget* getEditorWidget(int index){
00957     QSpinBox *newSpin = new QSpinBox(this);
00958     RCP<const EnhancedNumberValidator<int> > validator = null;
00959     if(!is_null(getEntryValidator())){
00960       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<int>, int> >(getEntryValidator(),true)->getPrototype();
00961     }
00962     ValidatorApplier<int>::applyToSpinBox(validator, newSpin);
00963     newSpin->setValue(baseArray[index]);
00964     return newSpin;
00965   }
00966 
00968 
00969 
00970 public slots:
00971 
00974 
00976   void accept(){
00977     doAcceptWork();
00978   }
00979 
00981 
00982 };
00983 
00987 class ShortArrayWidget: public Generic1DArrayWidget<short>
00988 {
00989   Q_OBJECT
00990 public:
00991 
00994 
01003   ShortArrayWidget(
01004     QString name, 
01005     QString type, 
01006     const RCP<const ParameterEntryValidator> validator,
01007     QWidget *parent=0):
01008     Generic1DArrayWidget<short>(name, type, validator,parent){}
01009 
01011 
01014 
01016   Array<short> getArrayFromWidgets(){
01017     Array<short> toReturn(widgetVector.size(), 0);
01018     for(size_t i=0; i < widgetVector.size(); ++i){
01019       toReturn[i]= ((QSpinBox*)widgetVector[i])->value();
01020     }
01021     return toReturn;
01022   }
01023 
01024 
01025 private:
01026 
01028   QWidget* getEditorWidget(int index){
01029     QSpinBox *newSpin = new QSpinBox(this);
01030     RCP<const EnhancedNumberValidator<short> > validator = null;
01031     if(!is_null(getEntryValidator())){
01032       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<short>, short> >(getEntryValidator(),true)->getPrototype();
01033     }
01034     ValidatorApplier<short>::applyToSpinBox(validator, newSpin);
01035     newSpin->setValue(baseArray[index]);
01036     return newSpin;
01037   }
01038 
01040 
01041 public slots:
01044 
01046   void accept(){
01047     doAcceptWork();
01048   }
01049 
01051 };
01052 
01056 class DoubleArrayWidget: public Generic1DArrayWidget<double>
01057 {
01058   Q_OBJECT
01059 public:
01060 
01063 
01072   DoubleArrayWidget(
01073     QString name, 
01074     QString type, 
01075     const RCP<const ParameterEntryValidator> validator,
01076     QWidget *parent=0):
01077     Generic1DArrayWidget<double>(name, type, validator,parent){}
01078 
01080 
01083 
01085   Array<double> getArrayFromWidgets(){
01086     Array<double> toReturn(widgetVector.size(), 0.0);
01087     for(size_t i=0; i < widgetVector.size(); ++i){
01088       toReturn[i]= ((QLineEdit*)widgetVector[i])->text().toDouble();
01089     }
01090     return toReturn;
01091   }
01092 
01093 private:
01094 
01096   QWidget* getEditorWidget(int index){
01097     QLineEdit *newEdit = new QLineEdit(this);
01098     RCP<const EnhancedNumberValidator<double> > validator = null;
01099     if(!is_null(getEntryValidator())){
01100       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<double>, double> >(getEntryValidator(),true)->getPrototype();
01101     }
01102     ValidatorApplier<double>::applyToLineEdit(validator, newEdit);
01103     newEdit->setText(QString::number(baseArray[index], 'g', ((QDoubleValidator*)newEdit->validator())->decimals()));
01104     return newEdit;
01105   }
01106 
01108   
01109 public slots:
01112 
01114   void accept(){
01115     doAcceptWork();
01116   }
01117 
01119 
01120 };
01121 
01125 class FloatArrayWidget: public Generic1DArrayWidget<float>
01126 {
01127   Q_OBJECT
01128 public:
01131 
01140   FloatArrayWidget(
01141     QString name, 
01142     QString type, 
01143     const RCP<const ParameterEntryValidator> validator,
01144     QWidget *parent=0):
01145     Generic1DArrayWidget<float>(name, type, validator,parent){}
01146 
01148   
01151 
01153   Array<float> getArrayFromWidgets(){
01154     Array<float> toReturn(widgetVector.size(), 0.0);
01155     for(size_t i=0; i < widgetVector.size(); ++i){
01156       toReturn[i]= ((QLineEdit*)widgetVector[i])->text().toDouble();
01157     }
01158     return toReturn;
01159   }
01160 
01161 private:
01162 
01164   QWidget* getEditorWidget(int index){
01165     QLineEdit *newEdit = new QLineEdit(this);
01166     RCP<const EnhancedNumberValidator<float> > validator = null;
01167     if(!is_null(getEntryValidator())){
01168       validator = rcp_dynamic_cast<const ArrayValidator<EnhancedNumberValidator<float>, float> >(getEntryValidator(),true)->getPrototype();
01169     }
01170     ValidatorApplier<float>::applyToLineEdit(validator, newEdit);
01171     newEdit->setText(QString::number(baseArray[index], 'g', ((QDoubleValidator*)newEdit->validator())->decimals()));
01172     return newEdit;
01173   }
01174 
01175 
01177 
01178 public slots:
01179 
01182 
01184   void accept(){
01185     doAcceptWork();
01186   }
01187 
01189 
01190 };
01191 
01195 class StringArrayWidget : public Generic1DArrayWidget<std::string>{
01196   Q_OBJECT
01197 public:
01198 
01201 
01210   StringArrayWidget(
01211     QString name, 
01212     QString type, 
01213     const RCP<const ParameterEntryValidator> validator,
01214     QWidget *parent=0):
01215     Generic1DArrayWidget<std::string>(name, type, validator,parent)
01216   {}
01217 
01219 
01222 
01224   Array<std::string> getArrayFromWidgets(){
01225     Array<std::string> toReturn(widgetVector.size(), "");
01226     for(size_t i=0; i < widgetVector.size(); ++i){
01227       if(is_null(getEntryValidator())){
01228         toReturn[i] = ((QLineEdit*)widgetVector[i])->text().toStdString();
01229       }
01230       else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
01231         toReturn[i] = ((FileNameWidget*)widgetVector[i])->getCurrentFileName().toStdString();
01232       }
01233       else if(getEntryValidator()->validStringValues()->size() !=0){
01234         toReturn[i] = ((QComboBox*)widgetVector[i])->currentText().toStdString();
01235       }
01236       else{
01237         toReturn[i] = ((QLineEdit*)widgetVector[i])->text().toStdString();
01238       }
01239     }
01240     return toReturn;
01241   }
01242 
01243 private:
01244 
01246   QWidget* getEditorWidget(int index){
01247     QString currentData = QString::fromStdString(baseArray[index]);
01248     if(is_null(getEntryValidator())){
01249       return new QLineEdit(currentData,this);
01250     }
01251     else if(!is_null(rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator()))){
01252       return new FileNameWidget(
01253         currentData, 
01254         rcp_dynamic_cast<const ArrayValidator<FileNameValidator, std::string> >(getEntryValidator())->getPrototype()->fileMustExist(), this);
01255     }
01256     else if(getEntryValidator()->validStringValues()->size() != 0){
01257       RCP<const Array<std::string> > options = getEntryValidator()->validStringValues();
01258       QComboBox *newCombo = new QComboBox(this);
01259       for(Array<std::string>::const_iterator itr = options->begin(); itr != options->end(); ++itr){
01260         newCombo->addItem(QString::fromStdString(*itr));
01261       }
01262       int selectedItem = newCombo->findText(currentData);
01263       newCombo->setCurrentIndex(selectedItem);
01264       return newCombo;
01265     }
01266     else{
01267       return new QLineEdit(currentData,this);
01268     }
01269   }
01270 
01272 
01273 public slots:
01274 
01277 
01279   void accept(){
01280     doAcceptWork();
01281   }
01282 
01284 
01285 
01286 };
01287 
01288 
01289 } //end namespace
01290 #endif //OPTIKA_ARRAYWIDGET_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines