Skip to content

Commit 868f1cf

Browse files
author
g_j_m
committed
Fix for ticket #64.
When quitting with a modified state the user is prompted as to whether they want to save the project. Qgis now also captures the window close event and treats it like a File:Quit menu item. git-svn-id: http://svn.osgeo.org/qgis/trunk@5445 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 07fe394 commit 868f1cf

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/gui/qgisapp.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,8 +2271,11 @@ findLayers_( QString const & fileFilters, list<QDomNode> const & layerNodes )
22712271

22722272
void QgisApp::fileExit()
22732273
{
2274-
removeAllLayers();
2275-
qApp->exit(0);
2274+
if (saveDirty() != QMessageBox::Cancel)
2275+
{
2276+
removeAllLayers();
2277+
qApp->exit(0);
2278+
}
22762279
}
22772280

22782281

@@ -2662,7 +2665,7 @@ bool QgisApp::addProject(QString projectFile)
26622665

26632666

26642667

2665-
void QgisApp::fileSave()
2668+
bool QgisApp::fileSave()
26662669
{
26672670
// if we don't have a filename, then obviously we need to get one; note
26682671
// that the project file name is reset to null in fileNew()
@@ -2697,7 +2700,7 @@ void QgisApp::fileSave()
26972700
{
26982701
// if they didn't select anything, just return
26992702
// delete saveFileDialog; auto_ptr auto destroys
2700-
return;
2703+
return false;
27012704
}
27022705

27032706
// make sure we have the .qgs extension in the file name
@@ -2746,7 +2749,7 @@ void QgisApp::fileSave()
27462749
Qt::NoButton );
27472750

27482751
}
2749-
2752+
return true;
27502753
} // QgisApp::fileSave
27512754

27522755

@@ -4319,7 +4322,8 @@ int QgisApp::saveDirty()
43194322
QMessageBox::Cancel | QMessageBox::Escape);
43204323
if (QMessageBox::Yes == answer )
43214324
{
4322-
fileSave();
4325+
if (!fileSave())
4326+
answer = QMessageBox::Cancel;
43234327
}
43244328
}
43254329

@@ -4330,6 +4334,15 @@ int QgisApp::saveDirty()
43304334
} // QgisApp::saveDirty()
43314335

43324336

4337+
void QgisApp::closeEvent(QCloseEvent* event)
4338+
{
4339+
// We'll close in our own good time, thank you very much
4340+
event->ignore();
4341+
// Do the usual checks and ask if they want to save, etc
4342+
fileExit();
4343+
}
4344+
4345+
43334346
void QgisApp::whatsThis()
43344347
{
43354348
QWhatsThis::enterWhatsThisMode();

src/gui/qgisapp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public slots:
212212
void saveWindowState();
213213
//! Restore the window and toolbar state
214214
void restoreWindowState();
215-
//! Save project
216-
void fileSave();
215+
//! Save project. Returns true if the user selected a file to save to, false if not.
216+
bool fileSave();
217217
//! Save project as
218218
void fileSaveAs();
219219
//! Open the project file corresponding to the
@@ -396,8 +396,8 @@ public slots:
396396
void pasteTransformations();
397397
//! check to see if file is dirty and if so, prompt the user th save it
398398
int saveDirty();
399-
//! Set the pointer to the splash screen so status messages can be
400-
399+
//! Have some control over closing of the application
400+
virtual void closeEvent(QCloseEvent* event);
401401

402402
/// QgisApp aren't copyable
403403
QgisApp( QgisApp const & );

0 commit comments

Comments
 (0)