-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run QgsProcessingAlgorithm with explicitely defined QgsProcessingContext and QgisInterfaces. #60805
base: master
Are you sure you want to change the base?
Conversation
adds support for none-standard QgsProcessingContext, QgsProject != QgsProject.instance() and iface != qgis.util.iface to processing framework classes
for more information, see https://pre-commit.ci
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
Is this just theoretical? None of the built-in algorithms do this. And if an algorithm does try this, it still won't have access to the iface object as that's not part of the context passed to algorithms anyway. |
Sorry, I actually mean the callers of QgsProcessingAlgorithms and have corrected my description above. The ProcessingPanel uses the iface to create the QgsWidgetContext for parameter widgets, and Postprocessing.py handleAlgorithmResults calls For example, the EnMAP-Box and the EO TimeSeriesViewer plugins extend QGIS by additional QMainWindows, e.g. to be used on a 2nd screen, and visualize map layers in multiple QgsMapCanvases side by side. Both implement a QgisInterface and have their own QgsLayerTreeView and QgsProject to not mess-up the standard QGIS layer tree and QgsProject.instance(): class EnMAPBox(QgisInterface, QObject, QgsExpressionContextGenerator, QgsProcessingContextGenerator):
class EOTimeSeriesViewer(QgisInterface, QObject): If QgsProcessingAlgorithms like Create Layer from extent ( To comply with the QgisInterface, some of the QgisInterface functions can be implemented as (pseudo-code): def mapCanvas(self) -> QgsMapCanvas:
return <last map canvas that was used / touched by a user>
def activeLayer(self) -> QgsMapCanvas:
return <last layer selected in a layer tree>
def mainWindow(self) -> QWidget:
return <main EnMAP-Box / EO Time Series Viewer window or other widget> |
Description
This PR addresses #60764 and enables the processing plugin to execute
QgsProcessingAlgorithms
with none-standard QgsProcessingContext and QgisInterface.It is now possible use the algorithm dialogs with a set of map layers that differs from layers inside the
QgsProject.instance().
This allows plugin developers to focus on layers relevant for their QGIS plugin, or to avoid messing up with layers inside the global project
QgsProject.instance()
. Developers can now provide a QgsProcessingContext object (with its owncontext.project()
).Some
algorithmscallers of processing algorithms may want to add processing results back to a QgsMapCanvas, or read a mapcanvas extent.By providing an own
QgsInterface
akaiface
different to that from the main QGIS GUI (from qgis.utils import iface
), it becomes possible to provide an explicit mapcanvas and layer handling.Examples for the new functionality are given by two new unit test in
python/plugins/processing/tests/GuiTest.py
:def testIndividualProcessingContext(self):
shows how AlgorithmDialog and BatchAlgorithmDialog can be called with a self-defined context + iface,def testProcessingPlugin_executeAlgorithm(self):
shows howProcessingPlugin.executeAlgorithm(...)
can be called with an explicitly definedcontext
andiface
. As this test creates a blocking dialogs it is disable for running in a CI.