Navigation Menu

Skip to content

Commit

Permalink
[FEATURE] warn on save if last modification date of a loaded project …
Browse files Browse the repository at this point in the history
…changed
  • Loading branch information
jef-n committed Mar 19, 2015
1 parent 7882fe2 commit 49ea51e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -513,6 +513,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mpTileScaleWidget( 0 )
, mpGpsWidget( 0 )
, mSnappingUtils( 0 )
, mProjectLastModified()
{
if ( smInstance )
{
Expand Down Expand Up @@ -916,6 +917,7 @@ QgisApp::QgisApp()
, mVectorLayerTools( 0 )
, mBtnFilterLegend( 0 )
, mSnappingUtils( 0 )
, mProjectLastModified()
{
smInstance = this;
setupUi( this );
Expand Down Expand Up @@ -3599,6 +3601,8 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
}
}

mProjectLastModified = QDateTime();

QSettings settings;

closeProject();
Expand Down Expand Up @@ -3989,7 +3993,7 @@ bool QgisApp::addProject( QString projectFile )
// close the previous opened project if any
closeProject();

if ( ! QgsProject::instance()->read( projectFile ) )
if ( !QgsProject::instance()->read( projectFile ) )
{
QApplication::restoreOverrideCursor();
statusBar()->clearMessage();
Expand All @@ -4004,6 +4008,8 @@ bool QgisApp::addProject( QString projectFile )
return false;
}

mProjectLastModified = pfi.lastModified();

setTitleBarText_( *this );
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
Expand Down Expand Up @@ -4123,6 +4129,19 @@ bool QgisApp::fileSave()
else
{
QFileInfo fi( QgsProject::instance()->fileName() );
if ( fi.exists() && !mProjectLastModified.isNull() && mProjectLastModified != fi.lastModified() )
{
if ( QMessageBox::warning( this,
tr( "Project file was changed" ),
tr( "The loaded project file on disk was meanwhile changed. Do you want to overwrite the changes?\n"
"\nLast modification date on load was: %1"
"\nCurrent last modification date is: %2" )
.arg( mProjectLastModified.toString( Qt::DefaultLocaleLongDate ) )
.arg( fi.lastModified().toString( Qt::DefaultLocaleLongDate ) ),
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
return false;
}

if ( fi.exists() && ! fi.isWritable() )
{
messageBar()->pushMessage( tr( "Insufficient permissions" ),
Expand All @@ -4143,6 +4162,9 @@ bool QgisApp::fileSave()
QSettings settings;
saveRecentProjectPath( fullPath.filePath(), settings );
}

QFileInfo fi( QgsProject::instance()->fileName() );
mProjectLastModified = fi.lastModified();
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -91,6 +91,7 @@ class QgsTileScaleWidget;
#include <QAbstractSocket>
#include <QPointer>
#include <QSslError>
#include <QDateTime>

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

QgsSnappingUtils* mSnappingUtils;

QDateTime mProjectLastModified;

#ifdef HAVE_TOUCH
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
Expand Down

0 comments on commit 49ea51e

Please sign in to comment.