Skip to content
Permalink
Browse files

[FEATURE] Add a "Revert Project" option to Project menu

Discards all unsaved changes to a project and reverts to the last
saved version of the project
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 251e1d5 commit 764e81276541bd0d0de1d41e4d843ebba3085dd5
Showing with 30 additions and 0 deletions.
  1. +19 −0 src/app/qgisapp.cpp
  2. +2 −0 src/app/qgisapp.h
  3. +9 −0 src/ui/qgisapp.ui
@@ -1323,6 +1323,13 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}
#endif

auto toggleRevert = [ = ]
{
mActionRevertProject->setEnabled( QgsProject::instance()->isDirty() &&!QgsProject::instance()->fileName().isEmpty() );
};
connect( QgsProject::instance(), &QgsProject::isDirtyChanged, mActionRevertProject, toggleRevert );
connect( QgsProject::instance(), &QgsProject::fileNameChanged, mActionRevertProject, toggleRevert );

} // QgisApp ctor

QgisApp::QgisApp()
@@ -1880,6 +1887,7 @@ void QgisApp::createActions()
connect( mActionNewProject, &QAction::triggered, this, [ = ] { fileNew(); } );
connect( mActionNewBlankProject, &QAction::triggered, this, &QgisApp::fileNewBlank );
connect( mActionOpenProject, &QAction::triggered, this, &QgisApp::fileOpen );
connect( mActionRevertProject, &QAction::triggered, this, &QgisApp::fileRevert );
connect( mActionSaveProject, &QAction::triggered, this, &QgisApp::fileSave );
connect( mActionCloseProject, &QAction::triggered, this, &QgisApp::fileClose );
connect( mActionSaveProjectAs, &QAction::triggered, this, &QgisApp::fileSaveAs );
@@ -5478,6 +5486,17 @@ void QgisApp::fileOpen()
}
}

void QgisApp::fileRevert()
{
if ( QMessageBox::question( this, tr( "Revert Project" ),
tr( "Are you sure you want to discard all unsaved changes the current project?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::No )
return;

// re-open the current project
addProject( QgsProject::instance()->fileInfo().filePath() );
}

void QgisApp::enableProjectMacros()
{
mTrustedMacros = true;
@@ -1227,6 +1227,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void saveMapAsPdf();
//! Open a project
void fileOpen();
//! Revert unsaved changes to a project
void fileRevert();
//! Create a new project
bool fileNew();
//! Create a new blank project (no template)
@@ -46,6 +46,7 @@
<addaction name="mActionOpenProject"/>
<addaction name="mProjectFromTemplateMenu"/>
<addaction name="mRecentProjectsMenu"/>
<addaction name="mActionRevertProject"/>
<addaction name="mActionCloseProject"/>
<addaction name="separator"/>
<addaction name="mActionSaveProject"/>
@@ -2968,6 +2969,14 @@ Acts on currently active editable layer</string>
<string>Close Project</string>
</property>
</action>
<action name="mActionRevertProject">
<property name="text">
<string>Revert Project…</string>
</property>
<property name="toolTip">
<string>Revert Project to Saved version</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 764e812

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