Bug report #5970

Loss of project when cancelling in "Save project as" dialog

Added by Leyan Ouyang about 12 years ago. Updated about 12 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed
Crashes QGIS or corrupts data:No Copied to github as #:15388

Description

Steps to reproduce:
  • Start a new project
  • Work on it
  • Quit, which will prompt a dialog to save the project
  • When asked where to save, cancel the dialog (in my case, I realized I needed information from the layers to choose the project name)
  • Qgis will quit anyway, without saving the project

I had a look at the code and based on my understanding, it is enough to change line 3197 of qgisapp.cpp to return false and cancel the operation when no file has been chosen.

diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp
index 92ed138..23c3eec 100644
--- a/src/app/qgisapp.cpp
+++ b/src/app/qgisapp.cpp
@@ -3192,7 +3192,7 @@ bool QgisApp::fileSave()
                      lastUsedDir + "/" + QgsProject::instance()->title(),
                      tr( "QGis files" ) + " (*.qgs *.QGS)" );
     if ( path.isEmpty() )
-      return true;
+      return false;

History

#1 Updated by Larry Shaffer about 12 years ago

I can confirm this issue exists on Mac 10.7.4 with 1.8.0 and master branch. The supplied patch fixes the issue and logically follows the comment on line # 5630 of /src/app/qgisapp.cpp:

/**
  Prompt and save if project has been modified.
  @return true if saved or discarded, false if cancelled
 */
bool QgisApp::saveDirty()

The supplied patch by Leyan causes saveDirty to return false as if the Cancel button was clicked in the initial dialog, which is the expected result. Loss of work, as reported, is the unexpected result.

A little clarification on reproducing the issue:

  • ...
  • Quit, which will prompt a dialog to save the project
  • + Choose to save the project to disk
  • When asked where to save, ...
  • ...

Nice work finding the quick fix Leyan.

#2 Updated by Jürgen Fischer about 12 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

applied in 299857e3

Also available in: Atom PDF