[QGIS-Developer] Processing algorithm to open up external dialog window
C Hamilton
adenaculture at gmail.com
Mon Feb 14 07:33:31 PST 2022
I have been trying to run a processing algorithm that generates a table
from the stats calculated from an input point layer. After the processing
algorithm is run I display an external dialog window and populate that
window with the output results of the processing algorithm. I like using
the processing toolbox because the algorithms run in their own thread and
allow the user to continue working. I don't know if what I am trying to do
is completely possible or not but I am most of the way there, but I have
encountered one problem that I am not sure how to solve. Here is what I
have so far
I run my processing algorithm and then in postProcessingAlgorithm I open up
the dialog window as follows. Note for right now I am calling the plugin
"testcapabilities'. The returned result from processAlgorithm is a table.
from qgis.utils import plugins
...
def processAlgorithm(self, parameters, context, feedback):
...
return {self.PrmOutputResults: self.dest_id}
...
def postProcessAlgorithm(self, context, feedback):
retval = super().postProcessAlgorithm(context, feedback)
# This gives me access to the root of my plugin which contains both
the
# processing algorithm and the post analysis window.
plugin = plugins['testcapabilities']
plugin.showDialog() # This opens up my dialog window
# This is the input point vector layer in the processing algorithm
input_layer = self.parameterAsLayer(self.parameters,
self.PrmInputLayer, context)
# I believe this gives me access to the table layer I generated in
the algorithm
table_layer = QgsProcessingUtils.mapLayerFromString(self.dest_id,
context)
# This is to attach the input and table layers to my dialogs
QgsMaplayerComboBox widgets
plugin.setData(input_layer, table_layer)
return retval
This successfully displays the dialog and passes on the input_layer to
the dialog box and will display it in a QgsMaplayerComboBox in the dialog.
The table generated in processAlgorithm is valid in postProcessAlgorithm,
but if I try to have it displayed in a QgsMaplayerComboBox, it does not
work. I think the reason is because it has not yet been added to the QGS
map layers.
Is there a QgsProcessingAlgorithm method that is called after the output
layer has been added to the QGIS layers panel? If there is then at that
point I should be able to add it to my dialog box.
If this is not possible, then I won't be able to use the processing toolbox
and will need to deal with implementing it in my own dialog box and in a
separate thread.
Thanks,
Calvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220214/b393fae2/attachment.html>
More information about the QGIS-Developer
mailing list