diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-09-30 18:19:08 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-09-30 18:19:08 +0200 |
commit | 90d54a3aa48f8b1c050754f866ef0cf013f4f06b (patch) | |
tree | 5c489f5fed90b260d335e396a285b323a28bff22 /src/mainwindow.cc | |
parent | f4a6644a827fd8da95e62ecfbbbf683b3ce35bc2 (diff) |
Ask user to save on new and quit if project is dirty.
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r-- | src/mainwindow.cc | 68 |
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(); |