Skip to content

Commit

Permalink
[FEATURE] Add a "Revert Project" option to Project menu
Browse files Browse the repository at this point in the history
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 764e812
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down

0 comments on commit 764e812

Please sign in to comment.