1

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.

asked Jul 16, 2019 at 13:03

1 Answer 1

2

Asked the same question on the QGIS dev mailing list and according to @nyalldawson this is intended behavior, so as not to receive misleading partial results.

answered Jul 23, 2019 at 7:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.