##// END OF EJS Templates
Check unsaved data on close
trabillard -
r1294:af6db233f5d0
parent child
Show More
@@ -52,6 +52,7 public slots:
52 52
53 53 protected:
54 54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55 56
56 57 private:
57 58 std::unique_ptr<Ui::MainWindow> m_Ui;
@@ -22,6 +22,7
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24 24
25 #include <Catalogue/CatalogueController.h>
25 26 #include <Catalogue/CatalogueExplorer.h>
26 27 #include <DataSource/DataSourceController.h>
27 28 #include <DataSource/DataSourceWidget.h>
@@ -36,9 +37,11
36 37 #include <Visualization/VisualizationController.h>
37 38
38 39 #include <QAction>
40 #include <QCloseEvent>
39 41 #include <QDate>
40 42 #include <QDir>
41 43 #include <QFileDialog>
44 #include <QMessageBox>
42 45 #include <QToolBar>
43 46 #include <QToolButton>
44 47 #include <memory.h>
@@ -74,6 +77,8 public:
74 77 SqpSettingsDialog *m_SettingsDialog;
75 78 /// Catalogue dialog. MainWindow has the ownership
76 79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 82 };
78 83
79 84 MainWindow::MainWindow(QWidget *parent)
@@ -364,3 +369,37 void MainWindow::changeEvent(QEvent *e)
364 369 break;
365 370 }
366 371 }
372
373 void MainWindow::closeEvent(QCloseEvent *event)
374 {
375 if (!impl->checkDataToSave(this)) {
376 event->ignore();
377 }
378 else {
379 event->accept();
380 }
381 }
382
383 bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget *parentWidget)
384 {
385 auto hasChanges = sqpApp->catalogueController().hasChanges();
386 if (hasChanges) {
387 // There are some unsaved changes
388 switch (QMessageBox::question(
389 parentWidget, "Save changes",
390 tr("The catalogue controller unsaved changes.\nDo you want to save them ?"),
391 QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel,
392 QMessageBox::SaveAll)) {
393 case QMessageBox::SaveAll:
394 sqpApp->catalogueController().saveAll();
395 break;
396 case QMessageBox::Discard:
397 break;
398 case QMessageBox::Cancel:
399 default:
400 return false;
401 }
402 }
403
404 return true;
405 }
@@ -62,6 +62,7 public:
62 62 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 63
64 64 void saveAll();
65 bool hasChanges() const;
65 66
66 67 /// Returns the MIME data associated to a list of variables
67 68 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
@@ -249,6 +249,11 void CatalogueController::saveAll()
249 249 impl->m_EventKeysWithChanges.clear();
250 250 }
251 251
252 bool CatalogueController::hasChanges() const
253 {
254 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
255 }
256
252 257 QByteArray
253 258 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
254 259 {
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now