Skip to content

Commit 21370d9

Browse files
committedNov 23, 2012
Add extra check on project close for any layer in edit mode with unsaved edits
- Ensures user has opportunity to save provider edits - Make project dirty if any unsaved edits found - Add red notification to project save prompt dialog, and set Cancel to default - Fix for #6054 and #6732
1 parent 7f8768a commit 21370d9

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6076,6 +6076,37 @@ void QgisApp::setExtent( QgsRectangle theRect )
60766076
*/
60776077
bool QgisApp::saveDirty()
60786078
{
6079+
QString whyDirty = "";
6080+
bool hasUnsavedEdits = false;
6081+
// extra check to see if there are any vector layers with unsaved provider edits
6082+
// to ensure user has opportunity to save any editing
6083+
if ( QgsMapLayerRegistry::instance()->count() > 0 )
6084+
{
6085+
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
6086+
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
6087+
{
6088+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
6089+
if ( !vl )
6090+
{
6091+
continue;
6092+
}
6093+
6094+
hasUnsavedEdits = ( vl->isEditable() && vl->isModified() );
6095+
if ( hasUnsavedEdits )
6096+
{
6097+
break;
6098+
}
6099+
}
6100+
6101+
if ( hasUnsavedEdits )
6102+
{
6103+
markDirty();
6104+
whyDirty = "<p style='color:darkred;'>";
6105+
whyDirty += tr( "Project has layer(s) in edit mode with unsaved edits, which will NOT be saved!" );
6106+
whyDirty += "</p>";
6107+
}
6108+
}
6109+
60796110
QMessageBox::StandardButton answer( QMessageBox::Discard );
60806111
mMapCanvas->freeze( true );
60816112

@@ -6096,8 +6127,10 @@ bool QgisApp::saveDirty()
60966127

60976128
// prompt user to save
60986129
answer = QMessageBox::information( this, tr( "Save?" ),
6099-
tr( "Do you want to save the current project?" ),
6100-
QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard );
6130+
tr( "Do you want to save the current project?%1" )
6131+
.arg( whyDirty ),
6132+
QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard,
6133+
hasUnsavedEdits ? QMessageBox::Cancel : QMessageBox::Save );
61016134
if ( QMessageBox::Save == answer )
61026135
{
61036136
if ( !fileSave() )

0 commit comments

Comments
 (0)
Please sign in to comment.