SpikeStream Application Library  0.2
AnalysisParameterDialog.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "NumberConversionException.h"
00003 #include "AnalysisParameterDialog.h"
00004 #include "Util.h"
00005 using namespace spikestream;
00006 
00007 //Qt includes
00008 #include <QDebug>
00009 #include <QDoubleValidator>
00010 #include <QLayout>
00011 #include <QLabel>
00012 #include <QPushButton>
00013 
00014 
00016 AnalysisParameterDialog::AnalysisParameterDialog(QWidget* parent, const AnalysisInfo &analysisInfo) : QDialog(parent){
00017         //Store variables
00018         this->info = analysisInfo;
00019 
00020         //Create layouts
00021         QVBoxLayout* mainVerticalBox = new QVBoxLayout(this);
00022         QGridLayout* gridLayout = new QGridLayout();
00023         gridLayout->setMargin(10);
00024 
00025         //Validators for double and integer parameters
00026         QDoubleValidator* doubleValidator = new QDoubleValidator(this);
00027         doubleValidator->setDecimals(5);
00028         QIntValidator* intValidator = new QIntValidator(0, 50, this);
00029 
00030         //Add the description
00031         gridLayout->addWidget(new QLabel("Analysis description: "), 0, 0);
00032         descriptionEdit = new QLineEdit(info.getDescription());
00033         gridLayout->addWidget(descriptionEdit, 0, 1);
00034 
00035         //Add the number of threads
00036         gridLayout->addWidget(new QLabel("Number of simultaneous threads: "), 1, 0);
00037         numThreadsEdit = new QLineEdit(QString::number(info.getNumberOfThreads()));
00038         numThreadsEdit->setValidator(intValidator);
00039         gridLayout->addWidget(numThreadsEdit, 1, 1);
00040 
00041         //Add the parameters
00042         int cntr = 2;
00043         for(QHash<QString, double>::iterator iter = info.getParameterMap().begin(); iter != info.getParameterMap().end(); ++iter){
00044                 gridLayout->addWidget(new QLabel(iter.key()), cntr, 0);
00045                 QLineEdit* tmpEdit = new QLineEdit(QString::number(iter.value(), 'g', 10));//'g' sets the output similar to sprintf; 10 is the maximum precision
00046                 tmpEdit->setValidator(doubleValidator);
00047                 //Disable parameter editing if it is loaded from the database
00048                 if(analysisInfo.getID() != 0){
00049                         tmpEdit->setEnabled(false);
00050                 }
00051                 gridLayout->addWidget(tmpEdit, cntr, 1);
00052                 editMap[iter.key()] = tmpEdit;
00053                 ++cntr;
00054         }
00055         mainVerticalBox->addLayout(gridLayout);
00056 
00057         //Add Ok and Cancel buttons
00058         QHBoxLayout *okCanButtonBox = new QHBoxLayout();
00059         QPushButton *okPushButton = new QPushButton("Ok");
00060         connect(okPushButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
00061         QPushButton *cancelPushButton = new QPushButton("Cancel");
00062         connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(reject()));
00063         okCanButtonBox->addWidget(okPushButton);
00064         okCanButtonBox->addWidget(cancelPushButton);
00065         mainVerticalBox->addLayout(okCanButtonBox);
00066 
00067 }
00068 
00069 
00071 AnalysisParameterDialog::~AnalysisParameterDialog(){
00072 }
00073 
00074 
00075 /*----------------------------------------------------------*/
00076 /*-----                  PUBLIC METHODS                -----*/
00077 /*----------------------------------------------------------*/
00078 
00080 const AnalysisInfo& AnalysisParameterDialog::getInfo(){
00081         return info;
00082 }
00083 
00084 
00085 /*----------------------------------------------------------*/
00086 /*-----                  PRIVATE SLOTS                 -----*/
00087 /*----------------------------------------------------------*/
00088 
00090 void AnalysisParameterDialog::okButtonClicked(){
00091         //Add the description
00092         if(descriptionEdit->text() == "")
00093                 info.setDescription("Undescribed");
00094         else
00095                 info.setDescription(descriptionEdit->text());
00096 
00097         //Number of simultaneous threads
00098         if(numThreadsEdit->text() == ""){
00099                 qCritical()<<"Number of threads has not been set.";
00100                 return;
00101         }
00102 
00103         //Load the current parameters into the analysis info
00104         try{
00105                 info.setNumberOfThreads( Util::getUInt(numThreadsEdit->text()) );
00106 
00107                 for(QHash<QString, QLineEdit*>::iterator iter = editMap.begin(); iter != editMap.end(); ++iter){
00108                         info.getParameterMap()[iter.key()] = Util::getDouble(iter.value()->text());
00109                 }
00110         }
00111         catch(NumberConversionException& ex){
00112                 //Reset map and display error message
00113                 info.getParameterMap().clear();
00114                 qCritical()<<ex.getMessage();
00115                 return;
00116         }
00117 
00118         //If we have reached this point, info should be ok
00119         accept();
00120 }
00121 
00122 
 All Classes Files Functions Variables Typedefs Friends Defines