Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

EditNeuronParametersDialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "EditNeuronParametersDialog.h"
00025 #include "Debug.h"
00026 
00027 //Qt includes
00028 #include <qlabel.h>
00029 #include <qpushbutton.h>
00030 
00031 //Other includes
00032 #include <mysql++.h>
00033 #include <map>
00034 #include <iostream>
00035 using namespace std;
00036 using namespace mysqlpp;
00037 
00038 
00039 /*! Constructor. */
00040 EditNeuronParametersDialog::EditNeuronParametersDialog(QWidget *parent, map<const char*, double, charKeyCompare> descValueMap, map<const char*, double, charKeyCompare> *defValMap, unsigned int neuronGrpID) : QDialog(parent, "EdNeurParamDlg", true){
00041         //Set caption to dialog
00042         this->setCaption("Neuron group " + QString::number(neuronGrpID));
00043 
00044         //Store reference to default values
00045         defaultValueMap = defValMap;
00046 
00047         //Create a validator to control inputs
00048         paramValidator = new QDoubleValidator(-100000.0, 100000.0, 4, this);
00049 
00050         //Create a vertical box to organise layout 
00051         QVBoxLayout *verticalBox = new QVBoxLayout(this, 5, 10);
00052         verticalBox->addSpacing(5);
00053 
00054         //Work through the map linking descriptions and values
00055         for(map<const char*, double>::iterator iter = descValueMap.begin(); iter != descValueMap.end(); ++iter){
00056                 //Create a line edit to display and edit this value
00057                 QLineEdit *parameterText = new QLineEdit(this);
00058                 parameterText->setText(QString::number(iter->second));
00059 
00060                 //Store the link between the value description and the line edit
00061                 descriptionLineEditMap[iter->first] = parameterText;
00062 
00063                 //Add a label and text box for this parameter
00064                 addNeuronParameter(QString(iter->first), parameterText, verticalBox);
00065         }
00066 
00067         verticalBox->addSpacing(5);
00068 
00069         //Add buttons to apply and reset the parameters
00070         QHBoxLayout *buttonBox = new QHBoxLayout();
00071         QPushButton *okButton = new QPushButton("Ok", this);
00072         connect (okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
00073         buttonBox->addWidget(okButton);
00074 
00075         QPushButton *loadDefaultsButton = new QPushButton("Load Defaults", this);
00076         connect (loadDefaultsButton, SIGNAL(clicked()), this, SLOT(loadDefaultsButtonPressed()));
00077         buttonBox->addWidget(loadDefaultsButton);
00078 
00079         QPushButton *makeDefaultsButton = new QPushButton("Make Defaults", this);
00080         connect (makeDefaultsButton, SIGNAL(clicked()), this, SLOT(makeDefaultsButtonPressed()));
00081         buttonBox->addWidget(makeDefaultsButton);
00082         
00083         QPushButton *cancelButton = new QPushButton("Cancel", this);
00084         connect (cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed()));
00085         buttonBox->addWidget(cancelButton);
00086         verticalBox->addLayout(buttonBox);
00087 }
00088 
00089 
00090 /*! Destructor. */
00091 EditNeuronParametersDialog::~ EditNeuronParametersDialog(){
00092         #ifdef MEMORY_DEBUG
00093                 cout<<"DESTROYING EDIT NEURON PARAMETERS DIALOG"<<endl;
00094         #endif//MEMORY_DEBUG
00095 }
00096 
00097 
00098 //---------------------------------------------------------------------------
00099 //-----------------------    PUBLIC METHODS    ------------------------------
00100 //---------------------------------------------------------------------------
00101 
00102 /*! Returns a map linking the line edits with the description of the parameter. */
00103 map<const char*, QLineEdit*, charKeyCompare>* EditNeuronParametersDialog::getDescriptionLineEditMap(){
00104         return &descriptionLineEditMap;
00105 }
00106 
00107 
00108 //--------------------------------------------------------------------------
00109 //------------------------    SLOTS    -------------------------------------
00110 //--------------------------------------------------------------------------
00111 
00112 /*! Closes the dialog without changing anything. */
00113 void EditNeuronParametersDialog::cancelButtonPressed(){
00114         reject();
00115 }
00116 
00117 
00118 /*! Loads the default values. */
00119 void EditNeuronParametersDialog::loadDefaultsButtonPressed(){
00120         for(map<const char*, double, charKeyCompare>::iterator iter = defaultValueMap->begin(); iter != defaultValueMap->end(); ++iter){
00121                 if(descriptionLineEditMap.count(iter->first))
00122                         descriptionLineEditMap[iter->first]->setText(QString::number(iter->second));
00123                 else
00124                         cerr<<"EditNeuronParametersDialog: MAP KEY NOT FOUND LOADING DEFAULTS"<<endl;
00125         }
00126 }
00127 
00128 
00129 /*! Should store the current values as the default values. */
00130 //FIXME NOT IMPLEMENTED YET.
00131 void EditNeuronParametersDialog::makeDefaultsButtonPressed(){
00132 }
00133 
00134 
00135 /*! Closes the dialog. */
00136 void EditNeuronParametersDialog::okButtonPressed(){
00137         accept();
00138 }
00139 
00140 
00141 //-----------------------------------------------------------------------------
00142 //-----------------------        PRIVATE METHODS     --------------------------
00143 //-----------------------------------------------------------------------------
00144 
00145 /*! Adds widgets to gather information about a neuron parameter to the neuron 
00146         parameter box. */
00147 void EditNeuronParametersDialog::addNeuronParameter(QString labelText, QLineEdit *lineEdit, QVBoxLayout *vBox){
00148         lineEdit->setMaximumSize(50, 20);
00149         lineEdit->setValidator(paramValidator);
00150         QHBoxLayout *hBoxLayout = new QHBoxLayout();
00151         hBoxLayout->addSpacing(10);
00152         hBoxLayout->addWidget(new QLabel(labelText, this));
00153         hBoxLayout->addWidget(lineEdit);
00154         hBoxLayout->addStretch(5);
00155         vBox->addLayout(hBoxLayout);
00156 }
00157 
00158 
00159 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4