Nyall Dawson 6d4392a0f7 Allow QgsTask subclasses to defined a finished function, which is
called when the task has completed (successfully or otherwise).

This allows for simpler task design when the signal/slot
based approach is not required. Just implement run() with your
heavy lifting, and finished() to do whatever follow up stuff
should happen after the task is complete. finished is always
called from the main thread, so it's safe to do GUI operations
here.

Python based tasks using the simplified QgsTask.fromFunction
approach can now set a on_finished argument to a function
to call when the task is complete.

eg:

def calculate(task):
    # pretend this is some complex maths and stuff we want
    # to run in the background
    return 5*6

def calculation_finished(result, value=None):
    if result == QgsTask.ResultSuccess:
	iface.messageBar().pushMessage(
            'the magic number is {}'.format(value))
    elif result == QgsTask.ResultFail:
        iface.messageBar().pushMessage(
            'couldn\'t work it out, sorry')

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)

Multiple values can also be returned, eg:

def calculate(task):
    return (4, 8, 15)

def calculation_finished(result, count=None, max=None, sum=None):
    # here:
    # count = 4
    # max = 8
    # sum = 15

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)
2016-12-05 14:08:11 +10:00
..
2016-02-14 03:50:49 +01:00
2016-12-05 14:08:10 +10:00
2016-11-16 09:33:19 +01:00
2016-11-16 09:33:19 +01:00
2016-02-14 03:50:49 +01:00
2016-07-25 10:15:46 +10:00
2016-02-14 03:50:49 +01:00
2016-10-01 15:39:03 +02:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-09-07 09:48:36 +02:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-09-15 18:34:15 +10:00
2016-07-21 08:40:50 +10:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-02-14 03:50:49 +01:00
2016-09-15 18:34:15 +10:00
2016-02-14 03:50:49 +01:00
2016-11-08 09:05:47 +10:00
2016-02-14 03:50:49 +01:00
2016-07-25 15:22:36 +10:00