Skip to content

Commit

Permalink
iface.newProject() should return False if a new project could not
Browse files Browse the repository at this point in the history
be created (e.g. if the user opts to cancel when prompted to save the
current project)
  • Loading branch information
nyalldawson committed Dec 4, 2019
1 parent caf8cfa commit b4bc7cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
12 changes: 10 additions & 2 deletions python/gui/auto_generated/qgisinterface.sip.in
Expand Up @@ -687,9 +687,17 @@ Adds a mesh layer to the current project.
%Docstring
Adds (opens) a project
%End
virtual void newProject( bool promptToSaveFlag = false ) = 0;

virtual bool newProject( bool promptToSaveFlag = false ) = 0;
%Docstring
Starts a new blank project
Starts a new blank project.

If ``promptToSaveFlag`` is ``True`` then users will be prompted to save any currently open
project (if that project has changes). If the flag is ``False``, then the current project will
be closed without prompting to save (possibly resulting in data loss).

Since QGIS 3.10.1, returns ``True`` if a new project was created, or ``False`` if the operation was not successful (e.g.
the user opted to cancel when prompted to save the current project).
%End

virtual void reloadConnections( ) = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisappinterface.cpp
Expand Up @@ -167,9 +167,9 @@ bool QgisAppInterface::addProject( const QString &projectName )
return qgis->addProject( projectName );
}

void QgisAppInterface::newProject( bool promptToSaveFlag )
bool QgisAppInterface::newProject( bool promptToSaveFlag )
{
qgis->fileNew( promptToSaveFlag );
return qgis->fileNew( promptToSaveFlag );
}

void QgisAppInterface::reloadConnections()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisappinterface.h
Expand Up @@ -71,7 +71,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QgsRasterLayer *addRasterLayer( const QString &url, const QString &baseName, const QString &providerKey ) override;
QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) override;
bool addProject( const QString &projectName ) override;
void newProject( bool promptToSaveFlag = false ) override;
bool newProject( bool promptToSaveFlag = false ) override;
void reloadConnections( ) override;
QgsMapLayer *activeLayer() override;
bool setActiveLayer( QgsMapLayer *layer ) override;
Expand Down
14 changes: 12 additions & 2 deletions src/gui/qgisinterface.h
Expand Up @@ -616,8 +616,18 @@ class GUI_EXPORT QgisInterface : public QObject

//! Adds (opens) a project
virtual bool addProject( const QString &project ) = 0;
//! Starts a new blank project
virtual void newProject( bool promptToSaveFlag = false ) = 0;

/**
* Starts a new blank project.
*
* If \a promptToSaveFlag is TRUE then users will be prompted to save any currently open
* project (if that project has changes). If the flag is FALSE, then the current project will
* be closed without prompting to save (possibly resulting in data loss).
*
* Since QGIS 3.10.1, returns TRUE if a new project was created, or FALSE if the operation was not successful (e.g.
* the user opted to cancel when prompted to save the current project).
*/
virtual bool newProject( bool promptToSaveFlag = false ) = 0;

/**
* Triggered when connections have changed.
Expand Down

0 comments on commit b4bc7cb

Please sign in to comment.