Skip to content

Commit 49ea51e

Browse files
committed
[FEATURE] warn on save if last modification date of a loaded project changed
1 parent 7882fe2 commit 49ea51e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/app/qgisapp.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
513513
, mpTileScaleWidget( 0 )
514514
, mpGpsWidget( 0 )
515515
, mSnappingUtils( 0 )
516+
, mProjectLastModified()
516517
{
517518
if ( smInstance )
518519
{
@@ -916,6 +917,7 @@ QgisApp::QgisApp()
916917
, mVectorLayerTools( 0 )
917918
, mBtnFilterLegend( 0 )
918919
, mSnappingUtils( 0 )
920+
, mProjectLastModified()
919921
{
920922
smInstance = this;
921923
setupUi( this );
@@ -3599,6 +3601,8 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
35993601
}
36003602
}
36013603

3604+
mProjectLastModified = QDateTime();
3605+
36023606
QSettings settings;
36033607

36043608
closeProject();
@@ -3989,7 +3993,7 @@ bool QgisApp::addProject( QString projectFile )
39893993
// close the previous opened project if any
39903994
closeProject();
39913995

3992-
if ( ! QgsProject::instance()->read( projectFile ) )
3996+
if ( !QgsProject::instance()->read( projectFile ) )
39933997
{
39943998
QApplication::restoreOverrideCursor();
39953999
statusBar()->clearMessage();
@@ -4004,6 +4008,8 @@ bool QgisApp::addProject( QString projectFile )
40044008
return false;
40054009
}
40064010

4011+
mProjectLastModified = pfi.lastModified();
4012+
40074013
setTitleBarText_( *this );
40084014
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
40094015
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
@@ -4123,6 +4129,19 @@ bool QgisApp::fileSave()
41234129
else
41244130
{
41254131
QFileInfo fi( QgsProject::instance()->fileName() );
4132+
if ( fi.exists() && !mProjectLastModified.isNull() && mProjectLastModified != fi.lastModified() )
4133+
{
4134+
if ( QMessageBox::warning( this,
4135+
tr( "Project file was changed" ),
4136+
tr( "The loaded project file on disk was meanwhile changed. Do you want to overwrite the changes?\n"
4137+
"\nLast modification date on load was: %1"
4138+
"\nCurrent last modification date is: %2" )
4139+
.arg( mProjectLastModified.toString( Qt::DefaultLocaleLongDate ) )
4140+
.arg( fi.lastModified().toString( Qt::DefaultLocaleLongDate ) ),
4141+
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
4142+
return false;
4143+
}
4144+
41264145
if ( fi.exists() && ! fi.isWritable() )
41274146
{
41284147
messageBar()->pushMessage( tr( "Insufficient permissions" ),
@@ -4143,6 +4162,9 @@ bool QgisApp::fileSave()
41434162
QSettings settings;
41444163
saveRecentProjectPath( fullPath.filePath(), settings );
41454164
}
4165+
4166+
QFileInfo fi( QgsProject::instance()->fileName() );
4167+
mProjectLastModified = fi.lastModified();
41464168
}
41474169
else
41484170
{

src/app/qgisapp.h

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class QgsTileScaleWidget;
9191
#include <QAbstractSocket>
9292
#include <QPointer>
9393
#include <QSslError>
94+
#include <QDateTime>
9495

9596
#include "qgsconfig.h"
9697
#include "qgsfeature.h"
@@ -1653,6 +1654,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
16531654

16541655
QgsSnappingUtils* mSnappingUtils;
16551656

1657+
QDateTime mProjectLastModified;
1658+
16561659
#ifdef HAVE_TOUCH
16571660
bool gestureEvent( QGestureEvent *event );
16581661
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );

0 commit comments

Comments
 (0)