For one plugin I maintain, I can't figure out how to return output layer when the user hits 'Cancel'. Basically I'm looping over a set of results in processAlgorithm which populates the output layer and I'd expect to have the output layer returned with all results calculated until 'Cancel' was clicked.
A minimal example:
def processAlgorithm(self, parameters, context, feedback):
(sink, self.dest_id) = self.parameterAsSink(parameters, 'Output', context,
list_of_fields,
QgsWkbTypes.Polygon,
CRS)
for result in results:
if feedback.isCanceled():
break
# Do smth smart
sink.addFeature(result)
return {'Output': self.dest_id}
However, no layer is added to the map when 'Cancel' is hit mid-way through processing.
EDIT
Just to clarify, I'd have expected that if feedback.isCanceled(): break would yield return {'Output': self.dest_id}, i.e. the output layer with the added features until feedback.isCanceled() is called.