Skip to content

Commit 87d742d

Browse files
committed
prompt the user to load backup when load project fails
If an error occurs while loading the project file, prompt the user to load the backup file instead, if it exists.
1 parent e158642 commit 87d742d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/app/qgisapp.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -4312,13 +4312,35 @@ bool QgisApp::addProject( const QString& projectFile )
43124312

43134313
if ( !QgsProject::instance()->read( projectFile ) )
43144314
{
4315+
QString backupFile = projectFile + "~";
4316+
QString loadBackupPrompt;
4317+
QMessageBox::StandardButtons buttons;
4318+
if ( QFile( backupFile ).exists() )
4319+
{
4320+
loadBackupPrompt = "\n\n" + tr( "Do you want to open the backup file\n%1\ninstead?" ).arg( backupFile );
4321+
buttons |= QMessageBox::Yes;
4322+
buttons |= QMessageBox::No;
4323+
}
4324+
else
4325+
{
4326+
buttons |= QMessageBox::Ok;
4327+
}
43154328
QApplication::restoreOverrideCursor();
43164329
statusBar()->clearMessage();
43174330

4318-
QMessageBox::critical( this,
4319-
tr( "Unable to open project" ),
4320-
QgsProject::instance()->error() );
4331+
int r = QMessageBox::critical( this,
4332+
tr( "Unable to open project" ),
4333+
QgsProject::instance()->error() + loadBackupPrompt,
4334+
buttons );
43214335

4336+
if ( QMessageBox::Yes == r && addProject( backupFile ) )
4337+
{
4338+
// We loaded data from the backup file, but we pretend to work on the original project file.
4339+
QgsProject::instance()->setFileName( projectFile );
4340+
QgsProject::instance()->setDirty( true );
4341+
mProjectLastModified = pfi.lastModified();
4342+
return true;
4343+
}
43224344

43234345
mMapCanvas->freeze( false );
43244346
mMapCanvas->refresh();

0 commit comments

Comments
 (0)