summaryrefslogtreecommitdiff
path: root/src/mainwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r--src/mainwindow.cc68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index ad13975..0120eab 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -348,12 +348,64 @@ void MainWindow::updateWindowTitle()
setWindowTitle("DGEdit - " + project_string);
}
-void MainWindow::closeEvent(QCloseEvent*)
+void MainWindow::closeEvent(QCloseEvent* event)
{
+ if(!checkDirty())
+ {
+ event->ignore();
+ return;
+ }
+
saveSettings();
QApplication::quit();
}
+bool MainWindow::checkDirty()
+{
+ if(project_dirty)
+ {
+ int ret =
+ QMessageBox::question(this, tr("Save before closing project?"),
+ tr("The project has changed. Do you want to save "
+ "before closing?"),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ switch(ret)
+ {
+ case QMessageBox::Yes:
+ saveProject();
+ if(project_dirty)
+ {
+ // Project still dirty - it was not saved (user pressed cancel?)
+ return false;
+ }
+ break;
+ case QMessageBox::No:
+ // Proceed to quit
+ break;
+ case QMessageBox::Cancel:
+ return false;
+ default:
+ break;
+ }
+ }
+
+ return true; // not dirty or user chose not to save
+}
+
+void MainWindow::reset()
+{
+ // Close all tabs
+ while(tab_widget->count())
+ {
+ tab_widget->removeTab(0);
+ }
+
+ instrument_list->clear();
+ channel_list->clear();
+
+ project.reset();
+}
+
void MainWindow::loadSettings()
{
QByteArray state;
@@ -372,6 +424,13 @@ void MainWindow::saveSettings()
void MainWindow::newProject()
{
+ if(!checkDirty())
+ {
+ return;
+ }
+
+ reset();
+
ProjectDialog dlg(this, project);
dlg.show();
dlg.exec();
@@ -379,6 +438,11 @@ void MainWindow::newProject()
void MainWindow::loadProject()
{
+ if(!checkDirty())
+ {
+ return;
+ }
+
QString filename =
QFileDialog::getOpenFileName(this,
tr("Load DGEdit Project"),
@@ -401,6 +465,8 @@ void MainWindow::loadProject(QString filename)
return;
}
+ reset();
+
QString xml(file.readAll());
file.close();