Skip to content
Permalink
Browse files

[FEATURE] warn on save if last modification date of a loaded project …

…changed
  • Loading branch information
jef-n committed Mar 19, 2015
1 parent 7882fe2 commit 49ea51eb1f9320d2f1a01384f0e418e45d861bda
Showing with 26 additions and 1 deletion.
  1. +23 −1 src/app/qgisapp.cpp
  2. +3 −0 src/app/qgisapp.h
@@ -513,6 +513,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mpTileScaleWidget( 0 )
, mpGpsWidget( 0 )
, mSnappingUtils( 0 )
, mProjectLastModified()
{
if ( smInstance )
{
@@ -916,6 +917,7 @@ QgisApp::QgisApp()
, mVectorLayerTools( 0 )
, mBtnFilterLegend( 0 )
, mSnappingUtils( 0 )
, mProjectLastModified()
{
smInstance = this;
setupUi( this );
@@ -3599,6 +3601,8 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
}
}

mProjectLastModified = QDateTime();

QSettings settings;

closeProject();
@@ -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();
@@ -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 );
@@ -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" ),
@@ -4143,6 +4162,9 @@ bool QgisApp::fileSave()
QSettings settings;
saveRecentProjectPath( fullPath.filePath(), settings );
}

QFileInfo fi( QgsProject::instance()->fileName() );
mProjectLastModified = fi.lastModified();
}
else
{
@@ -91,6 +91,7 @@ class QgsTileScaleWidget;
#include <QAbstractSocket>
#include <QPointer>
#include <QSslError>
#include <QDateTime>

#include "qgsconfig.h"
#include "qgsfeature.h"
@@ -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 );

0 comments on commit 49ea51e

Please sign in to comment.
You can’t perform that action at this time.