SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "Globals.h" 00003 #include "LoadAnalysisDialog.h" 00004 #include "Util.h" 00005 #include "SpikeStreamException.h" 00006 using namespace spikestream; 00007 00008 //Qt includes 00009 #include <QDebug> 00010 #include <QLayout> 00011 #include <QMessageBox> 00012 #include <QPushButton> 00013 #include <QItemSelectionModel> 00014 00015 00017 LoadAnalysisDialog::LoadAnalysisDialog(QWidget* parent, unsigned int analysisType) : QDialog(parent) { 00018 //Store analysis type to filter results 00019 this->analysisType = analysisType; 00020 00021 //Check that both a network and an archive have been loaded 00022 if(!Globals::networkLoaded() || !Globals::archiveLoaded()){ 00023 qCritical()<<"Analyses are linked to a particular network and archive, which must be loaded first."; 00024 return; 00025 } 00026 00027 QVBoxLayout *mainVerticalBox = new QVBoxLayout(this); 00028 00029 //Create model and add view 00030 analysesModel = new AnalysesModel(analysisType); 00031 QTableView* analysesTableView = new AnalysesTableView(this, analysesModel); 00032 analysesTableView->setMinimumSize(600, 300); 00033 mainVerticalBox->addWidget(analysesTableView); 00034 00035 //Add buttons 00036 QHBoxLayout* buttonBox = new QHBoxLayout(); 00037 QPushButton* okPushButton = new QPushButton("Ok"); 00038 buttonBox->addWidget(okPushButton); 00039 QPushButton* deletePushButton = new QPushButton("Delete selected analyses"); 00040 buttonBox->addWidget(deletePushButton); 00041 QPushButton* cancelPushButton = new QPushButton("Cancel"); 00042 buttonBox->addWidget(cancelPushButton); 00043 mainVerticalBox->addLayout(buttonBox); 00044 00045 connect (okPushButton, SIGNAL(clicked()), this, SLOT(okButtonPressed())); 00046 connect (deletePushButton, SIGNAL(clicked()), this, SLOT(deleteButtonPressed())); 00047 connect (cancelPushButton, SIGNAL(clicked()), this, SLOT(reject())); 00048 00049 //Automatically hide when network display changes 00050 connect(Globals::getEventRouter(), SIGNAL(networkDisplayChangedSignal()), this, SLOT(hide())); 00051 } 00052 00053 00055 LoadAnalysisDialog::~LoadAnalysisDialog(){ 00056 } 00057 00058 00059 /*----------------------------------------------------------*/ 00060 /*----- PUBLIC METHODS -----*/ 00061 /*----------------------------------------------------------*/ 00062 00065 const AnalysisInfo& LoadAnalysisDialog::getAnalysisInfo(){ 00066 if(analysisInfo.getID() == 0) 00067 throw SpikeStreamException("Analysis info ID is 0. This method should not be called if the user has cancelled selection of analysis."); 00068 return analysisInfo; 00069 } 00070 00071 00072 /*----------------------------------------------------------*/ 00073 /*----- PRIVATE SLOTS -----*/ 00074 /*----------------------------------------------------------*/ 00075 00078 void LoadAnalysisDialog::okButtonPressed(){ 00079 QList<AnalysisInfo> selectedAnalysisList = analysesModel->getSelectedAnalyses(); 00080 00081 //Check that there is exactly one selection 00082 if(selectedAnalysisList.size() != 1){ 00083 qCritical()<<"A single analysis must be selected for loading."; 00084 return; 00085 } 00086 00087 //Store the selected analysis and accept dialog 00088 analysisInfo = selectedAnalysisList.at(0); 00089 this->accept(); 00090 } 00091 00092 00094 void LoadAnalysisDialog::deleteButtonPressed(){ 00095 QList<AnalysisInfo> selectedAnalysisList = analysesModel->getSelectedAnalyses(); 00096 00097 //Check that there is at least one selection 00098 if(selectedAnalysisList.size() == 0){ 00099 return; 00100 } 00101 00102 //Confirm that user wants to delete the analyses 00103 QMessageBox msgBox; 00104 msgBox.setText("Deleting Analyses"); 00105 msgBox.setInformativeText("Are you sure that you want to delete " + QString::number(selectedAnalysisList.size()) + " analyses? This step cannot be undone."); 00106 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); 00107 msgBox.setDefaultButton(QMessageBox::Cancel); 00108 int ret = msgBox.exec(); 00109 if(ret != QMessageBox::Ok) 00110 return; 00111 00112 //Delete the analyses 00113 foreach(AnalysisInfo anaInfo, selectedAnalysisList){ 00114 Globals::getAnalysisDao()->deleteAnalysis(anaInfo.getID()); 00115 } 00116 00117 //Reload the model 00118 analysesModel->reload(); 00119 } 00120 00121 00122