X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..cf93fd850a8b6e9a6f40faed9f796a0e2fb0cedb:/MainWindow.cpp diff --git a/MainWindow.cpp b/MainWindow.cpp index 01c23c1..e772425 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // creating block library library = new BlockLibraryWidget(dispatcher,params); - isCurrentProject = false; + params->isCurrentProject = false; QLabel* labDefault = new QLabel("BLAST: BLock ASsembler Tool"); stackedWidget = new QStackedWidget; @@ -270,15 +270,17 @@ void MainWindow::slotLoadProject(){ GroupWidget* topGroup = dispatcher->loadProject(absoluteFilename); if (topGroup != NULL) { addTopGroup(topGroup); + library->updateComboScene(); + params->isCurrentProject = true; + enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); } else { QMessageBox msgBox; - msgBox.setText("Cannot open the project."); - msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setText("Cannot open the project."); msgBox.setStandardButtons(QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); + msgBox.exec(); } } } @@ -289,24 +291,54 @@ void MainWindow::slotNewProject(){ enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ); GroupWidget* topGroup = dispatcher->createTopScene(); addTopGroup(topGroup); - + library->updateComboScene(); + library->show(); + params->isCurrentProject = true; } -void MainWindow::slotCloseProject(){ +bool MainWindow::slotCloseProject(){ - // removing the GroupWidget from stack - QWidget *widget = stackedWidget->widget(1); - stackedWidget->removeWidget(widget); - stackedWidget->setCurrentIndex(0); + bool doClose = false; - dispatcher->closeCurrentProject(); + if(params->isCurrentProject) { + if (params->unsaveModif) { + QMessageBox msgBox; + msgBox.setText("The project has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); - isCurrentProject = false; - params->unsaveModif = false; - absoluteFilename = QString(); + switch(ret) { + case QMessageBox::Save : + slotSaveProject(); + doClose = true; + break; + case QMessageBox::Discard : + doClose = true; + break; + } + } + else { + doClose = true; + } + if (doClose) { + // removing the GroupWidget from stack + QWidget *widget = stackedWidget->widget(1); + stackedWidget->removeWidget(widget); + stackedWidget->setCurrentIndex(0); - initialize(); + dispatcher->closeCurrentProject(); + + params->isCurrentProject = false; + params->unsaveModif = false; + absoluteFilename = QString(); + + initialize(); + } + } + return doClose; } @@ -323,7 +355,7 @@ void MainWindow::slotSaveProject(){ } void MainWindow::slotSaveAsProject(){ - if(isCurrentProject){ + if(params->isCurrentProject){ QFileDialog dial(0, "Select a file", "save/"); dial.setDefaultSuffix(".xml"); dial.setAcceptMode(QFileDialog::AcceptSave); @@ -341,7 +373,12 @@ void MainWindow::slotOpenBlockLibrary() { void MainWindow::slotGraphValidation() { - params->parametersValidation(); + try { + params->getGraph()->computeOutputPatterns(5); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + } } void MainWindow::addTopGroup(GroupWidget *_topGroup) { @@ -356,29 +393,16 @@ void MainWindow::removeTopGroup() { stackedWidget->setCurrentIndex(0); } -void MainWindow::closeEvent(QCloseEvent *event){ - if(isCurrentProject){ - QMessageBox msgBox; - msgBox.setText("The project has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Save); - - int ret = msgBox.exec(); - - switch(ret) { - case QMessageBox::Save : - slotSaveProject(); - slotCloseProject(); - break; - case QMessageBox::Discard : - slotCloseProject(); - break; - } +void MainWindow::closeEvent(QCloseEvent *event) { + + if (params->isCurrentProject) { + slotCloseProject(); event->ignore(); - } else { - exit(0); } + else { + library->deleteLater(); + } + } void MainWindow::mousePressEvent(QMouseEvent *e) {