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

EditSynapseParametersDialog.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 "EditSynapseParametersDialog.h"
00025 #include "Debug.h"
00026 
00027 //Qt includes
00028 #include <qlabel.h>
00029 #include <qpushbutton.h>
00030 
00031 //Other includes
00032 #include <map>
00033 #include <iostream>
00034 using namespace std;
00035 
00036 
00037 /*! Constructor. */
00038 EditSynapseParametersDialog::EditSynapseParametersDialog(QWidget *parent, map<const char*, double, charKeyCompare> descValueMap, map<const char*, double, charKeyCompare> *defValMap, unsigned int connGrpID) : QDialog(parent, "EdNeurParamDlg", true){
00039         //Set caption to dialog
00040         this->setCaption("Connection Group " + QString::number(connGrpID));
00041 
00042         //Store reference to map containing default values.
00043         defaultValueMap = defValMap;
00044 
00045         //Create a validator to control inputs
00046         paramValidator = new QDoubleValidator(-100000.0, 100000.0, 4, this);
00047 
00048         //Create a vertical box to organise layout 
00049         QVBoxLayout *verticalBox = new QVBoxLayout(this, 5, 10);
00050         verticalBox->addSpacing(5);
00051 
00052         //Work through the map linking descriptions and values
00053         for(map<const char*, double>::iterator iter = descValueMap.begin(); iter != descValueMap.end(); ++iter){
00054                 //Create a line edit to display and edit this value
00055                 QLineEdit *parameterText = new QLineEdit(this);
00056                 parameterText->setText(QString::number(iter->second));
00057 
00058                 //Store the link between the value description and the line edit
00059                 descriptionLineEditMap[iter->first] = parameterText;
00060 
00061                 //Add a label and text box for this parameter
00062                 addSynapseParameter(QString(iter->first), parameterText, verticalBox);
00063         }
00064 
00065         verticalBox->addSpacing(5);
00066 
00067         //Add buttons to apply and reset the parameters
00068         QHBoxLayout *buttonBox = new QHBoxLayout();
00069         QPushButton *okButton = new QPushButton("Ok", this);
00070         connect (okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
00071         buttonBox->addWidget(okButton);
00072 
00073         QPushButton *loadDefaultsButton = new QPushButton("Load Defaults", this);
00074         connect (loadDefaultsButton, SIGNAL(clicked()), this, SLOT(loadDefaultsButtonPressed()));
00075         buttonBox->addWidget(loadDefaultsButton);
00076 
00077         QPushButton *makeDefaultsButton = new QPushButton("Make Defaults", this);
00078         connect (makeDefaultsButton, SIGNAL(clicked()), this, SLOT(makeDefaultsButtonPressed()));
00079         buttonBox->addWidget(makeDefaultsButton);
00080         
00081         QPushButton *cancelButton = new QPushButton("Cancel", this);
00082         connect (cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed()));
00083         buttonBox->addWidget(cancelButton);
00084         verticalBox->addLayout(buttonBox);
00085 }
00086 
00087 
00088 /*! Destructor. */
00089 EditSynapseParametersDialog::~ EditSynapseParametersDialog(){
00090         #ifdef MEMORY_DEBUG
00091                 cout<<"DESTROYING EDIT SYNAPSE PARAMETERS DIALOG"<<endl;
00092         #endif//MEMORY_DEBUG
00093 }
00094 
00095 
00096 //---------------------------------------------------------------------------
00097 //-----------------------    PUBLIC METHODS    ------------------------------
00098 //---------------------------------------------------------------------------
00099 
00100 /*! Returns a map linking the line edits with the description of the parameter. */
00101 map<const char*, QLineEdit*, charKeyCompare>* EditSynapseParametersDialog::getDescriptionLineEditMap(){
00102         return &descriptionLineEditMap;
00103 }
00104 
00105 
00106 //--------------------------------------------------------------------------
00107 //------------------------    SLOTS    -------------------------------------
00108 //--------------------------------------------------------------------------
00109 
00110 /*! Hides the dialog. */
00111 void EditSynapseParametersDialog::cancelButtonPressed(){
00112         reject();
00113 }
00114 
00115 
00116 /*! Loads the default parameter values from the supplied map. */
00117 void EditSynapseParametersDialog::loadDefaultsButtonPressed(){
00118         for(map<const char*, double, charKeyCompare>::iterator iter = defaultValueMap->begin(); iter != defaultValueMap->end(); ++iter){
00119                 if(descriptionLineEditMap.count(iter->first))
00120                         descriptionLineEditMap[iter->first]->setText(QString::number(iter->second));
00121                 else
00122                         cerr<<"EditSynapseParametersDialog: MAP KEY NOT FOUND WHEN LOADING DEFAULTS: \""<<iter->first<<"\""<<endl;
00123         }
00124 }
00125 
00126 
00127 /*! Makes the current parameters the default parameters. */
00128 //FIXME NOT IMPLEMENTED YET 
00129 void EditSynapseParametersDialog::makeDefaultsButtonPressed(){
00130 }
00131 
00132 
00133 /*! Closes the dialog. */
00134 void EditSynapseParametersDialog::okButtonPressed(){
00135         accept();
00136 }
00137 
00138 
00139 //-----------------------------------------------------------------------------
00140 //-----------------------        PRIVATE METHODS     --------------------------
00141 //-----------------------------------------------------------------------------
00142 
00143 /*! Adds a synapse parameter to the dialog. */
00144 void EditSynapseParametersDialog::addSynapseParameter(QString labelText, QLineEdit *lineEdit, QVBoxLayout *vBox){
00145         lineEdit->setMaximumSize(50, 20);
00146         lineEdit->setValidator(paramValidator);
00147         QHBoxLayout *hBoxLayout = new QHBoxLayout();
00148         hBoxLayout->addSpacing(10);
00149         hBoxLayout->addWidget(new QLabel(labelText, this));
00150         hBoxLayout->addWidget(lineEdit);
00151         hBoxLayout->addStretch(5);
00152         vBox->addLayout(hBoxLayout);
00153 }
00154 
00155 

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