SpikeStream Application Library
0.2
|
00001 #include "Globals.h" 00002 #include "NetworkInfo.h" 00003 #include "NetworkDialog.h" 00004 #include "SpikeStreamException.h" 00005 using namespace spikestream; 00006 00007 //Qt includes 00008 #include <QDebug> 00009 #include <QLabel> 00010 #include <QLayout> 00011 #include <QPushButton> 00012 00013 00015 NetworkDialog::NetworkDialog(QWidget* parent) : QDialog(parent){ 00016 addNetworkToDatabase = true; 00017 00018 buildGUI("Unnamed", "Undescribed"); 00019 } 00020 00021 00023 NetworkDialog::NetworkDialog(const QString& name, const QString& description, QWidget* parent) : QDialog(parent){ 00024 addNetworkToDatabase = false; 00025 00026 buildGUI(name, description); 00027 } 00028 00029 00031 NetworkDialog::~NetworkDialog(){ 00032 } 00033 00034 00036 QString NetworkDialog::getName(){ 00037 QString nameStr = nameLineEdit->text(); 00038 if(nameStr.isEmpty()) 00039 nameStr = "Unnamed"; 00040 return nameStr; 00041 } 00042 00043 00045 QString NetworkDialog::getDescription(){ 00046 QString descStr = descLineEdit->text(); 00047 if(descStr.isEmpty()) 00048 descStr = "Undescribed"; 00049 return descStr; 00050 } 00051 00052 00053 /*----------------------------------------------------------*/ 00054 /*----- PRIVATE SLOTS -----*/ 00055 /*----------------------------------------------------------*/ 00056 00058 void NetworkDialog::cancelButtonPressed(){ 00059 this->reject(); 00060 } 00061 00062 00064 void NetworkDialog::okButtonPressed(){ 00065 if(addNetworkToDatabase){ 00066 //Add the network 00067 NetworkInfo netInfo(0, getName(), getDescription()); 00068 try{ 00069 Globals::getNetworkDao()->addNetwork(netInfo); 00070 Globals::getEventRouter()->networkListChangedSlot(); 00071 } 00072 catch(SpikeStreamException& ex){ 00073 qCritical()<<ex.getMessage(); 00074 } 00075 } 00076 00077 //Hide the dialog 00078 this->accept(); 00079 } 00080 00081 00082 /*----------------------------------------------------------*/ 00083 /*----- PRIVATE METHODS -----*/ 00084 /*----------------------------------------------------------*/ 00085 00087 void NetworkDialog::buildGUI(const QString& name, const QString& description){ 00088 //Create layout managers 00089 QVBoxLayout* mainVBox = new QVBoxLayout(this); 00090 QGridLayout* gridLayout = new QGridLayout(); 00091 gridLayout->setMargin(10); 00092 00093 //Field to enter name of new network 00094 gridLayout->addWidget(new QLabel("Name: "), 0, 0); 00095 nameLineEdit = new QLineEdit(name); 00096 nameLineEdit->setMinimumSize(250, 30); 00097 gridLayout->addWidget(nameLineEdit, 0, 1); 00098 00099 //Field to enter description of new network 00100 gridLayout->addWidget(new QLabel("Description: "), 1, 0); 00101 descLineEdit = new QLineEdit(description); 00102 descLineEdit->setMinimumSize(250, 30); 00103 gridLayout->addWidget(descLineEdit, 1, 1); 00104 00105 mainVBox->addLayout(gridLayout); 00106 00107 //Add buttons 00108 QHBoxLayout* buttonBox = new QHBoxLayout(); 00109 QPushButton* okButton = new QPushButton("Ok"); 00110 connect(okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed())); 00111 buttonBox->addWidget(okButton); 00112 QPushButton* cancelButton = new QPushButton("Cancel"); 00113 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed())); 00114 buttonBox->addWidget(cancelButton); 00115 mainVBox->addLayout(buttonBox); 00116 } 00117