SpikeStream Application Library  0.2
ConnectionGroupDialog.cpp
Go to the documentation of this file.
00001 #include "Globals.h"
00002 #include "ConnectionGroupDialog.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 ConnectionGroupDialog::ConnectionGroupDialog(const ConnectionGroupInfo& conGrpInfo, QWidget* parent) : QDialog(parent){
00015         connectionGroupInfo = conGrpInfo;
00016         buildGUI();
00017 }
00018 
00019 
00021 ConnectionGroupDialog::~ConnectionGroupDialog(){
00022 }
00023 
00024 
00025 /*----------------------------------------------------------*/
00026 /*-----                 PRIVATE SLOTS                  -----*/
00027 /*----------------------------------------------------------*/
00028 
00030 void ConnectionGroupDialog::cancelButtonPressed(){
00031         this->reject();
00032 }
00033 
00034 
00036 void ConnectionGroupDialog::okButtonPressed(){
00037         try{
00038                 //Check network is loaded
00039                 if(!Globals::networkLoaded())
00040                         throw SpikeStreamException("Network not loaded when editing connection group properties.");
00041 
00042                 //Set the new properties in the network if they have changed
00043                 if(connectionGroupInfo.getDescription() != getDescription()){
00044                         Globals::getNetwork()->setConnectionGroupProperties(connectionGroupInfo.getID(), getDescription());
00045                 }
00046 
00047                 //Hide the dialog
00048                 this->accept();
00049         }
00050         catch(SpikeStreamException& ex){
00051                 qCritical()<<ex.getMessage();
00052         }
00053 }
00054 
00055 
00056 /*----------------------------------------------------------*/
00057 /*-----                 PRIVATE METHODS                -----*/
00058 /*----------------------------------------------------------*/
00059 
00061 void ConnectionGroupDialog::buildGUI(){
00062         //Create layout managers
00063         QVBoxLayout* mainVBox = new QVBoxLayout(this);
00064         QGridLayout* gridLayout = new QGridLayout();
00065         gridLayout->setMargin(10);
00066 
00067         //Field to enter description of connection group
00068         gridLayout->addWidget(new QLabel("Description: "), 1, 0);
00069         descLineEdit = new QLineEdit(connectionGroupInfo.getDescription());
00070         descLineEdit->setMinimumSize(250, 30);
00071         gridLayout->addWidget(descLineEdit, 1, 1);
00072 
00073         mainVBox->addLayout(gridLayout);
00074 
00075         //Add buttons
00076         QHBoxLayout* buttonBox = new QHBoxLayout();
00077         QPushButton* okButton = new QPushButton("Ok");
00078         connect(okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
00079         buttonBox->addWidget(okButton);
00080         QPushButton* cancelButton = new QPushButton("Cancel");
00081         connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed()));
00082         buttonBox->addWidget(cancelButton);
00083         mainVBox->addLayout(buttonBox);
00084 }
00085 
00086 
00088 QString ConnectionGroupDialog::getDescription(){
00089         QString descStr = descLineEdit->text();
00090         if(descStr.isEmpty())
00091                 descStr = "Undescribed";
00092         return descStr;
00093 }
00094 
00095 
 All Classes Files Functions Variables Typedefs Friends Defines