Skip to content

Commit 764e812

Browse files
committed
[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
1 parent 251e1d5 commit 764e812

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/app/qgisapp.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,13 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
13231323
}
13241324
#endif
13251325

1326+
auto toggleRevert = [ = ]
1327+
{
1328+
mActionRevertProject->setEnabled( QgsProject::instance()->isDirty() &&!QgsProject::instance()->fileName().isEmpty() );
1329+
};
1330+
connect( QgsProject::instance(), &QgsProject::isDirtyChanged, mActionRevertProject, toggleRevert );
1331+
connect( QgsProject::instance(), &QgsProject::fileNameChanged, mActionRevertProject, toggleRevert );
1332+
13261333
} // QgisApp ctor
13271334

13281335
QgisApp::QgisApp()
@@ -1880,6 +1887,7 @@ void QgisApp::createActions()
18801887
connect( mActionNewProject, &QAction::triggered, this, [ = ] { fileNew(); } );
18811888
connect( mActionNewBlankProject, &QAction::triggered, this, &QgisApp::fileNewBlank );
18821889
connect( mActionOpenProject, &QAction::triggered, this, &QgisApp::fileOpen );
1890+
connect( mActionRevertProject, &QAction::triggered, this, &QgisApp::fileRevert );
18831891
connect( mActionSaveProject, &QAction::triggered, this, &QgisApp::fileSave );
18841892
connect( mActionCloseProject, &QAction::triggered, this, &QgisApp::fileClose );
18851893
connect( mActionSaveProjectAs, &QAction::triggered, this, &QgisApp::fileSaveAs );
@@ -5478,6 +5486,17 @@ void QgisApp::fileOpen()
54785486
}
54795487
}
54805488

5489+
void QgisApp::fileRevert()
5490+
{
5491+
if ( QMessageBox::question( this, tr( "Revert Project" ),
5492+
tr( "Are you sure you want to discard all unsaved changes the current project?" ),
5493+
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::No )
5494+
return;
5495+
5496+
// re-open the current project
5497+
addProject( QgsProject::instance()->fileInfo().filePath() );
5498+
}
5499+
54815500
void QgisApp::enableProjectMacros()
54825501
{
54835502
mTrustedMacros = true;

src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12271227
void saveMapAsPdf();
12281228
//! Open a project
12291229
void fileOpen();
1230+
//! Revert unsaved changes to a project
1231+
void fileRevert();
12301232
//! Create a new project
12311233
bool fileNew();
12321234
//! Create a new blank project (no template)

src/ui/qgisapp.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<addaction name="mActionOpenProject"/>
4747
<addaction name="mProjectFromTemplateMenu"/>
4848
<addaction name="mRecentProjectsMenu"/>
49+
<addaction name="mActionRevertProject"/>
4950
<addaction name="mActionCloseProject"/>
5051
<addaction name="separator"/>
5152
<addaction name="mActionSaveProject"/>
@@ -2968,6 +2969,14 @@ Acts on currently active editable layer</string>
29682969
<string>Close Project</string>
29692970
</property>
29702971
</action>
2972+
<action name="mActionRevertProject">
2973+
<property name="text">
2974+
<string>Revert Project…</string>
2975+
</property>
2976+
<property name="toolTip">
2977+
<string>Revert Project to Saved version</string>
2978+
</property>
2979+
</action>
29712980
</widget>
29722981
<resources>
29732982
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)