mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[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
This commit is contained in:
parent
251e1d5352
commit
764e812765
@ -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"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user