SpikeStream Application Library
0.2
|
00001 #include "Globals.h" 00002 #include "NeuronGroupDialog.h" 00003 #include "SpikeStreamException.h" 00004 using namespace spikestream; 00005 00006 //Qt includes 00007 #include <QDebug> 00008 #include <QLabel> 00009 #include <QLayout> 00010 #include <QPushButton> 00011 00012 00014 NeuronGroupDialog::NeuronGroupDialog(const NeuronGroupInfo& neurGrpInfo, QWidget* parent) : QDialog(parent){ 00015 neuronGroupInfo = neurGrpInfo; 00016 buildGUI(); 00017 } 00018 00019 00021 NeuronGroupDialog::~NeuronGroupDialog(){ 00022 } 00023 00024 00025 /*----------------------------------------------------------*/ 00026 /*----- PRIVATE SLOTS -----*/ 00027 /*----------------------------------------------------------*/ 00028 00030 void NeuronGroupDialog::cancelButtonPressed(){ 00031 this->reject(); 00032 } 00033 00034 00036 void NeuronGroupDialog::okButtonPressed(){ 00037 try{ 00038 //Check network is loaded 00039 if(!Globals::networkLoaded()) 00040 throw SpikeStreamException("Network not loaded when editing neuron group properties."); 00041 00042 //Set the new properties in the network if they have changed 00043 if(neuronGroupInfo.getName() != getName() || neuronGroupInfo.getDescription() != getDescription()){ 00044 Globals::getNetwork()->setNeuronGroupProperties( 00045 neuronGroupInfo.getID(), getName(), getDescription()); 00046 } 00047 00048 //Hide the dialog 00049 this->accept(); 00050 } 00051 catch(SpikeStreamException& ex){ 00052 qCritical()<<ex.getMessage(); 00053 } 00054 } 00055 00056 00057 /*----------------------------------------------------------*/ 00058 /*----- PRIVATE METHODS -----*/ 00059 /*----------------------------------------------------------*/ 00060 00062 void NeuronGroupDialog::buildGUI(){ 00063 //Create layout managers 00064 QVBoxLayout* mainVBox = new QVBoxLayout(this); 00065 QGridLayout* gridLayout = new QGridLayout(); 00066 gridLayout->setMargin(10); 00067 00068 //Field to enter name of new network 00069 gridLayout->addWidget(new QLabel("Name: "), 0, 0); 00070 nameLineEdit = new QLineEdit(neuronGroupInfo.getName()); 00071 nameLineEdit->setMinimumSize(250, 30); 00072 gridLayout->addWidget(nameLineEdit, 0, 1); 00073 00074 //Field to enter description of new network 00075 gridLayout->addWidget(new QLabel("Description: "), 1, 0); 00076 descLineEdit = new QLineEdit(neuronGroupInfo.getDescription()); 00077 descLineEdit->setMinimumSize(250, 30); 00078 gridLayout->addWidget(descLineEdit, 1, 1); 00079 00080 mainVBox->addLayout(gridLayout); 00081 00082 //Add buttons 00083 QHBoxLayout* buttonBox = new QHBoxLayout(); 00084 QPushButton* okButton = new QPushButton("Ok"); 00085 connect(okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed())); 00086 buttonBox->addWidget(okButton); 00087 QPushButton* cancelButton = new QPushButton("Cancel"); 00088 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed())); 00089 buttonBox->addWidget(cancelButton); 00090 mainVBox->addLayout(buttonBox); 00091 } 00092 00093 00094 00096 QString NeuronGroupDialog::getName(){ 00097 QString nameStr = nameLineEdit->text(); 00098 if(nameStr.isEmpty()) 00099 nameStr = "Unnamed"; 00100 return nameStr; 00101 } 00102 00103 00105 QString NeuronGroupDialog::getDescription(){ 00106 QString descStr = descLineEdit->text(); 00107 if(descStr.isEmpty()) 00108 descStr = "Undescribed"; 00109 return descStr; 00110 } 00111 00112