##// END OF EJS Templates
Check unsaved data on close
trabillard -
r1270:4a8f0335d243
parent child
Show More
@@ -52,6 +52,7 public slots:
52
52
53 protected:
53 protected:
54 void changeEvent(QEvent *e);
54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55
56
56 private:
57 private:
57 std::unique_ptr<Ui::MainWindow> m_Ui;
58 std::unique_ptr<Ui::MainWindow> m_Ui;
@@ -22,6 +22,7
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <Catalogue/CatalogueController.h>
25 #include <Catalogue/CatalogueExplorer.h>
26 #include <Catalogue/CatalogueExplorer.h>
26 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceWidget.h>
28 #include <DataSource/DataSourceWidget.h>
@@ -36,9 +37,11
36 #include <Visualization/VisualizationController.h>
37 #include <Visualization/VisualizationController.h>
37
38
38 #include <QAction>
39 #include <QAction>
40 #include <QCloseEvent>
39 #include <QDate>
41 #include <QDate>
40 #include <QDir>
42 #include <QDir>
41 #include <QFileDialog>
43 #include <QFileDialog>
44 #include <QMessageBox>
42 #include <QToolBar>
45 #include <QToolBar>
43 #include <QToolButton>
46 #include <QToolButton>
44 #include <memory.h>
47 #include <memory.h>
@@ -74,6 +77,8 public:
74 SqpSettingsDialog *m_SettingsDialog;
77 SqpSettingsDialog *m_SettingsDialog;
75 /// Catalogue dialog. MainWindow has the ownership
78 /// Catalogue dialog. MainWindow has the ownership
76 CatalogueExplorer *m_CatalogExplorer;
79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 };
82 };
78
83
79 MainWindow::MainWindow(QWidget *parent)
84 MainWindow::MainWindow(QWidget *parent)
@@ -364,3 +369,37 void MainWindow::changeEvent(QEvent *e)
364 break;
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 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63
63
64 void saveAll();
64 void saveAll();
65 bool hasChanges() const;
65
66
66 /// Returns the MIME data associated to a list of variables
67 /// Returns the MIME data associated to a list of variables
67 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
68 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
@@ -249,6 +249,11 void CatalogueController::saveAll()
249 impl->m_EventKeysWithChanges.clear();
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 QByteArray
257 QByteArray
253 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
258 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
254 {
259 {
General Comments 0
You need to be logged in to leave comments. Login now