diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-30 18:39:27 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 58f2e5f77c2faaf4c2f75767ee8fde67cc0931ac (patch) | |
tree | 9f76fbf3ccb1cb17c516f077af08810f11fcb40d /desktop-widgets/mainwindow.cpp | |
parent | 837ab6c90b7952095c0dadf2de18db883b0f5ecf (diff) | |
download | subsurface-58f2e5f77c2faaf4c2f75767ee8fde67cc0931ac.tar.gz |
Undo: use QUndoStack::isClean() to determine unsaved changes
Properly implement the unsaved-changes flag(s). Since we currently have
two kinds of changes, there are two flags:
1) dive_list_changed in divelist.c marks non-undoable changes. This flag
is only cleared on save or load.
2) QUndoStack::isClean() is used to determine the state of undoable
changes. Every time the user returns to the state where they saved,
this flag is cleared.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/mainwindow.cpp')
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index cc1adc3b2..09af6414f 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -128,6 +128,7 @@ MainWindow::MainWindow() : QMainWindow(), m_Instance = this; ui.setupUi(this); read_hashes(); + Command::init(); // Define the States of the Application Here, Currently the states are situations where the different // widgets will change on the mainwindow. @@ -589,7 +590,15 @@ void MainWindow::on_actionCloudstoragesave_triggered() return; setCurrentFile(qPrintable(filename)); - mark_divelist_changed(false); + setFileClean(); +} + +// Currently we have two markers for unsaved changes: +// 1) unsaved_changes() returns true for non-undoable changes. +// 2) Command::isClean() returns false for undoable changes. +static bool unsavedChanges() +{ + return unsaved_changes() || !Command::isClean(); } void MainWindow::on_actionCloudOnline_triggered() @@ -611,7 +620,7 @@ void MainWindow::on_actionCloudOnline_triggered() git_local_only = isOffline; if (!isOffline) { // User requests to go online. Try to sync cloud storage - if (unsaved_changes()) { + if (unsavedChanges()) { // If there are unsaved changes, ask the user if they want to save them. // If they don't, they have to sync manually. if (QMessageBox::warning(this, tr("Save changes?"), @@ -653,12 +662,18 @@ bool MainWindow::okToClose(QString message) QMessageBox::warning(this, tr("Warning"), message); return false; } - if (unsaved_changes() && askSaveChanges() == false) + if (unsavedChanges() && askSaveChanges() == false) return false; return true; } +void MainWindow::setFileClean() +{ + mark_divelist_changed(false); + Command::setClean(); +} + void MainWindow::closeCurrentFile() { graphics->setEmptyState(); @@ -667,7 +682,7 @@ void MainWindow::closeCurrentFile() clear_dive_file_data(); setCurrentFile(nullptr); cleanUpEmpty(); - mark_divelist_changed(false); + setFileClean(); clear_events(); @@ -763,7 +778,7 @@ void MainWindow::on_actionQuit_triggered() return; } - if (unsaved_changes() && (askSaveChanges() == false)) + if (unsavedChanges() && (askSaveChanges() == false)) return; writeSettings(); QApplication::quit(); @@ -1421,7 +1436,7 @@ void MainWindow::closeEvent(QCloseEvent *event) return; } - if (unsaved_changes() && (askSaveChanges() == false)) { + if (unsavedChanges() && (askSaveChanges() == false)) { event->ignore(); return; } @@ -1555,7 +1570,7 @@ int MainWindow::file_save_as(void) return -1; setCurrentFile(qPrintable(filename)); - mark_divelist_changed(false); + setFileClean(); addRecentFile(filename, true); return 0; } @@ -1592,7 +1607,7 @@ int MainWindow::file_save(void) } if (is_cloud) hideProgressBar(); - mark_divelist_changed(false); + setFileClean(); addRecentFile(QString(existing_filename), true); return 0; } @@ -1631,7 +1646,7 @@ void MainWindow::setTitle() return; } - QString unsaved = (unsaved_changes() ? " *" : ""); + QString unsaved = (unsavedChanges() ? " *" : ""); QString shown = QString(" (%1)").arg(filterWidget2.shownText()); setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved + shown); } |