Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allow plugins and scripts to register custom logic to prevent
the QGIS application from exiting This interface allows plugins to implement custom logic to determine whether it is safe for the application to exit, e.g. by checking whether the plugin or script has any unsaved changes which should be saved or discarded before allowing QGIS to exit.
- Loading branch information
1 parent
64bf347
commit df6c8d7
Showing
10 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
python/gui/auto_generated/qgsapplicationexitblockerinterface.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsapplicationexitblockerinterface.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsApplicationExitBlockerInterface | ||
{ | ||
%Docstring | ||
An interface that may be implemented to allow plugins or scripts to temporarily block | ||
the QGIS application from exiting. | ||
|
||
This interface allows plugins to implement custom logic to determine whether it is safe | ||
for the application to exit, e.g. by checking whether the plugin or script has any | ||
unsaved changes which should be saved or discarded before allowing QGIS to exit. | ||
|
||
QgsApplicationExitBlockerInterface are registered via the iface object: | ||
|
||
Example | ||
------- | ||
|
||
.. code-block:: python | ||
|
||
class MyPluginExitBlocker(QgsApplicationExitBlockerInterface): | ||
|
||
def allowExit(self): | ||
if self.has_unsaved_changes(): | ||
# show a warning prompt | ||
# ... | ||
# prevent QGIS application from exiting | ||
return False | ||
|
||
# allow QGIS application to exit | ||
return True | ||
|
||
my_blocker = MyPluginExitBlocker() | ||
iface.registerApplicationExitBlocker(my_blocker) | ||
|
||
.. versionadded:: 3.16 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsapplicationexitblockerinterface.h" | ||
%End | ||
public: | ||
|
||
virtual ~QgsApplicationExitBlockerInterface(); | ||
|
||
virtual bool allowExit() = 0; | ||
%Docstring | ||
Called whenever the QGIS application has been asked to exit by a user. | ||
|
||
The subclass can use this method to implement custom logic handling whether it is safe | ||
for the application to exit, e.g. by checking whether the plugin or script has any unsaved | ||
changes which should be saved or discarded before allowing QGIS to exit. | ||
|
||
The implementation should return ``True`` if it is safe for QGIS to exit, or ``False`` if it | ||
wishes to prevent the application from exiting. | ||
|
||
.. note:: | ||
|
||
It is safe to use GUI widgets in implementations of this function, including message | ||
boxes or custom dialogs with event loops. | ||
%End | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsapplicationexitblockerinterface.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*************************************************************************** | ||
qgsapplicationexitblockerinterface.h | ||
--------------------- | ||
begin : October 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSAPPLICATIONEXITBLOCKERINTERFACE_H | ||
#define QGSAPPLICATIONEXITBLOCKERINTERFACE_H | ||
|
||
#include "qgis_gui.h" | ||
#include <QStringList> | ||
#include <QObject> | ||
|
||
/** | ||
* \ingroup gui | ||
* An interface that may be implemented to allow plugins or scripts to temporarily block | ||
* the QGIS application from exiting. | ||
* | ||
* This interface allows plugins to implement custom logic to determine whether it is safe | ||
* for the application to exit, e.g. by checking whether the plugin or script has any | ||
* unsaved changes which should be saved or discarded before allowing QGIS to exit. | ||
* | ||
* QgsApplicationExitBlockerInterface are registered via the iface object: | ||
* | ||
* ### Example | ||
* | ||
* \code{.py} | ||
* class MyPluginExitBlocker(QgsApplicationExitBlockerInterface): | ||
* | ||
* def allowExit(self): | ||
* if self.has_unsaved_changes(): | ||
* # show a warning prompt | ||
* # ... | ||
* # prevent QGIS application from exiting | ||
* return False | ||
* | ||
* # allow QGIS application to exit | ||
* return True | ||
* | ||
* my_blocker = MyPluginExitBlocker() | ||
* iface.registerApplicationExitBlocker(my_blocker) | ||
* \endcode | ||
* | ||
* \since QGIS 3.16 | ||
*/ | ||
class GUI_EXPORT QgsApplicationExitBlockerInterface | ||
{ | ||
|
||
public: | ||
|
||
virtual ~QgsApplicationExitBlockerInterface() = default; | ||
|
||
/** | ||
* Called whenever the QGIS application has been asked to exit by a user. | ||
* | ||
* The subclass can use this method to implement custom logic handling whether it is safe | ||
* for the application to exit, e.g. by checking whether the plugin or script has any unsaved | ||
* changes which should be saved or discarded before allowing QGIS to exit. | ||
* | ||
* The implementation should return TRUE if it is safe for QGIS to exit, or FALSE if it | ||
* wishes to prevent the application from exiting. | ||
* | ||
* \note It is safe to use GUI widgets in implementations of this function, including message | ||
* boxes or custom dialogs with event loops. | ||
*/ | ||
virtual bool allowExit() = 0; | ||
}; | ||
|
||
#endif // QgsCustomProjectOpenHandler_H |