40 Commits

Author SHA1 Message Date
Matthias Kuhn
f9842426dc Improve stability of QgsTask::waitForFinished test 2017-05-12 10:51:13 +02:00
Matthias Kuhn
eaabce28e9 Doxyfication 2017-05-11 12:42:26 +02:00
Matthias Kuhn
52676774ba Sipify QgsTask[Manager] 2017-05-11 12:42:26 +02:00
Denis Rouzaud
7d459149c7 [sip] align missing bits and replace nullptr by 0 2017-05-02 08:09:53 +02:00
Denis Rouzaud
93971d5ed3 [sip] align pointer and reference in blacklisted files
this will facilitate sip diff checking
2017-05-01 17:49:43 +02:00
Nyall Dawson
77e7693c48 Fix spelling errors in processing algorithm help 2017-03-25 16:23:29 +10:00
Nyall Dawson
35bb5c611f Flip task manager to use weak layer pointers instead of layer ids 2017-02-13 08:55:55 +10:00
Nyall Dawson
95d000f662 [FEATURE] Background saving of vector layers
Switches the vector layer save operation to a background task
using the task manager framework. Allows layers to saved without
blocking the interface.
2017-02-13 08:30:29 +10:00
Denis Rouzaud
b119744773 replace cancelling, cancelled and cancellation by canceling, canceled and cancelation, respectively (#4000)
* replace cancelling and cancelled by canceling and canceled, respectively

see https://github.com/qgis/qgis3_UIX_discussion/issues/19

* replace cancellation by cancelation
2017-01-16 22:27:14 +01:00
Denis Rouzaud
0a63d1f2c2 [spellcheck] properly look into various cases and add more fixes" 2017-01-16 16:39:20 +01:00
Denis Rouzaud
748be8de71 [spelling] replace behaviour by behavior 2017-01-11 11:35:19 +01:00
Harrissou Sant-anna
ef85cdcf83 Replace "eg" by "e.g." or "for example" 2016-12-30 00:03:22 +01:00
Denis Rouzaud
2ffe1a764b spelling fixes 2016-12-15 15:26:36 +01:00
Denis Rouzaud
90fc0bb226 use Travis to look for spelling errors
use silver searcher for faster search (instead of grep)
2016-12-15 15:26:36 +01:00
Nyall Dawson
adff069d5a Cleanup QgsTask API for dependent layers 2016-12-06 20:02:34 +10:00
Nyall Dawson
feb3219852 Update doxygen 2016-12-05 14:08:12 +10:00
Nyall Dawson
e35420a8d9 Force QgsTask::run() to fully complete
Remove support for signal based completion/termination

Also unfortunately disable a lot of the test suite as a result,
since it's not easily translatable
2016-12-05 14:08:12 +10:00
Nyall Dawson
268e5127f2 Make QgsTask::start private
Only allow starting tasks to be done by QgsTaskManager
2016-12-05 14:08:12 +10:00
Nyall Dawson
297b5724df QgsTask is no longer a QRunnable
Instead use a private wrapper class to make QgsTask compatible
with QThreadPool
2016-12-05 14:08:12 +10:00
Nyall Dawson
466b0b96b7 Tasks are treated as progressless until they first report a progress 2016-12-05 14:08:11 +10:00
Nyall Dawson
4dc3dd9077 Allow task priority to be specified 2016-12-05 14:08:11 +10:00
Nyall Dawson
5216220872 Fix more racy conditions
Switch from QtConcurrent::run to QThreadPool::start

QtConcurrent doesn't give us anyway to cancel queued but not
started tasks. QThreadPool does (and also allows us to specify
task priority)
2016-12-05 14:08:11 +10:00
Nyall Dawson
14b6b3f6ee Harden everything up
And finally fix a racy condition which has been plaguing me for
ages
2016-12-05 14:08:11 +10:00
Nyall Dawson
32a9e1e9d6 QgsTasks can have subtasks
Now, a QgsTask can have subtask QgsTasks set by calling
QgsTask::addSubTask. Sub tasks can have their own set of
dependent tasks.

Subtasks are not visible to users, and users only see the overall
progress and status of the parent task.

This allows creation of tasks which are themselves built off
many smaller component tasks. The task manager will still handle
firing up and scheduling the subtasks, so eg subtasks can run
in parallel (if their dependancies allow this).

Subtasks can themselves have subtasks.

This change is designed to allow the processing concept of
algorithms and modeller algorithms to be translatable
directly to the task manager architecture.
2016-12-05 14:08:11 +10:00
Nyall Dawson
3999a3710f Remove QgsTaskManager singleton, and instead attach an instance
to QgsApplication.

ie instead of QgsTaskManager.instance(), use
QgsApplication.taskManager()
2016-12-05 14:08:11 +10:00
Nyall Dawson
b6b7a7f8c6 Remove delete* methods from QgsTaskManager API
On further consideration allowing external control of task
deletion is a bad idea.
2016-12-05 14:08:11 +10:00
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
Nyall Dawson
252f2e1102 Rename overloaded signal, flip remaining connects to new style 2016-12-05 14:08:11 +10:00
Nyall Dawson
f71c78e14f Rename stopped to terminated for consistency 2016-12-05 14:08:11 +10:00
Nyall Dawson
e01c306edb Simplify reporting completion of tasks
QgsTask subclasses can now return a result (success or fail)
directly from QgsTask::run. If they do so then there's no
need for them to manually call completed() or stopped()
to report their completion.

Alternatively, tasks can also return the ResultPending value
to indicate that the task is still operating and will
manually report its completion by calling completed() or
stopped(). This may be useful for tasks which rely on external
events for completion, eg downloading a file. In this case
Qt slots could be created which are connected to the download
completion or termination and which call completed() or
stopped() to indicate the task has finished operations.
2016-12-05 14:08:11 +10:00
Nyall Dawson
95dbb3a7e3 Add deleteAllTasks to manager 2016-12-05 14:08:11 +10:00
Nyall Dawson
d270b4f9c2 Improvements to task manager ui 2016-12-05 14:08:11 +10:00
Nyall Dawson
55e9d32671 Add handling of dependent layers to task manager
If a task has dependent layers which are about to be removed,
the task will automatically be cancelled
2016-12-05 14:08:11 +10:00
Nyall Dawson
4c0f4ee6f0 Resolve circular dependencies 2016-12-05 14:08:11 +10:00
Nyall Dawson
4291904c8d Support for dependent tasks
Cancelling a task on which others depend leads to all these other
tasks getting cancelled as well.
2016-12-05 14:08:11 +10:00
Nyall Dawson
dcecf4476f Add support for placing queued tasks on hold 2016-12-05 14:08:10 +10:00
Nyall Dawson
cf5eeb758b API cleanups 2016-12-05 14:08:10 +10:00
Nyall Dawson
e29dd79432 Api + test cleanups 2016-12-05 14:08:10 +10:00
Nyall Dawson
6021d7806e Make QgsTaskManager handle threading of tasks 2016-12-05 14:08:10 +10:00
Nyall Dawson
ebae15f23a Framework for task manager
Adds new classes:
- QgsTask. An interface for long-running background tasks
- QgsTaskManager. Handles groups of tasks - also available as a global
instance for tracking application wide tasks
- QgsTaskManagerWidget. A list view for showing active tasks and their
progress, and for cancelling them

A new dock widget has been added with a task manager widget showing
global tasks
2016-12-05 14:08:10 +10:00