51 Commits

Author SHA1 Message Date
Etienne Trimaille
c606abc702 enable custom help in python expressions 2017-08-23 12:00:57 +02:00
Nyall Dawson
bc9b1b64f9 Astyle 2017-06-12 07:28:36 +10:00
Nyall Dawson
cb41ef1adc Output useful logging when running algorithms from toolbox
Now outputs the input parameters, execution time, and results
2017-06-12 07:26:02 +10:00
Matthias Kuhn
1e4c1595c0 Adapt “@qgsfunction" decorator to new expression structure 2017-05-19 07:13:11 +02:00
Matthias Kuhn
5f7a2912f6 Expose "context" to expression functions 2017-05-05 15:39:29 +02:00
Juergen E. Fischer
c77172ed3d fix more flake8 warnings 2017-03-05 10:21:24 +01: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
Nyall Dawson
b5480633e4 Standardise names for static variables
All non-const variables are prefixed with "s", all const
statics are ALL_CAPS
2017-01-14 16:40:24 +10:00
Nyall Dawson
9d4adc1c70 Remove some singletons by moving instances to QgsApplication
- QgsColorSchemeRegistry
- QgsDataItemProviderRegistry
- QgsGPSConnectionRegistry
- QgsMessageLog
- QgsPaintEffectRegistry
- QgsPluginLayerRegistry
- QgsRasterRendererRegistry
- QgsRendererRegistry
- QgsSvgCache
- QgsSymbolLayerRegistry
2016-12-28 16:59:03 +10:00
Nyall Dawson
cc702c9c81 Remove (probably unnecessary) copy_func usage 2016-12-05 16:46:10 +10:00
Nyall Dawson
d03d0a5b47 Add some python docstrings to QgsTask.fromFunction 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
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
29f310c070 Convert QgsTask.fromFunction to a static method 2016-12-05 14:08:11 +10:00
Nyall Dawson
619381c0ad Call QgsTaskWrapper.on_finished with exception rather than result 2016-12-05 14:08:11 +10:00
Nyall Dawson
fded1a1f39 Don't explode returned values in QgsTaskWrapper
Breaks returning list values
2016-12-05 14:08:11 +10:00
Nyall Dawson
0dcff4491e Respect QgsTask::CanCancel flag in gui 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
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
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
b64025df5c Add python test for task manager 2016-12-05 14:08:11 +10:00
Nyall Dawson
b065edeed7 Improvements to QgsTaskWrapper 2016-12-05 14:08:11 +10:00
Nyall Dawson
5d4689294d Add simple python method QgsTask.fromFunction for creation of tasks
from a function without having to create a QgsTask subclass
2016-12-05 14:08:10 +10:00
Matthias Kuhn
0b3646b252 Expression functions can dynamically report geometry and columns 2016-10-27 23:11:51 +02:00
Juergen E. Fischer
31df84aa6b run 2to3 on source 2016-09-21 23:30:04 +02:00
Nyall Dawson
7da8110536 Remove deprecated methods from QgsExpression
Now all evaluate/prepare/etc methods must be called using QgsExpressionContexts

Also remove most remaining traces of special variables. This brings some
user facing changes, such that existing expressions may need to be
updated if they used these old special variables (eg $scale,
$feature). These changes are noted in doc/qgis3_user_changes.dox
so that we can include them in the release notes.
2016-08-10 17:55:06 +10:00
Nyall Dawson
b7ca001c9c Add __nonzero__ and __bool__ methods to QgsGeometry 2016-08-02 08:39:58 +10:00
Nyall Dawson
1bc17e6c4f Default to requesting all attributes for python expression functions
Fix #14985
2016-06-10 10:03:34 +10:00
Matthias Kuhn
89b7a4aaa2 Introduce NULL QVariant to PyQt5 2016-05-13 22:23:03 +02:00
Denis Rouzaud
8071acd064 move PyQt compat folder to python/qgis 2016-04-29 14:10:26 +02:00
Juergen E. Fischer
271750fd53 switch bindings to pyqt wrappers 2016-03-21 17:00:26 +01:00
Juergen E. Fischer
fb3fcfa3a0 Python3/Qt5/2to3 updates:
* pyqtwrappers update (add QtNetwork, QtXml, QtSql, QtTest, uic)
* 2to3 updates
* move QPyNullVariant/NULL to PyQt.QtCore
* add global unicode/basestring/long for Python3
* expand QtGui, QtCore module and star exports
* Qscintilla2
* replace Set import with set builtin
2016-03-14 20:38:20 +01:00
Juergen E. Fischer
4e1cf3c081 add missing copyright headers 2016-01-08 21:32:11 +01:00
Nathan Woodrow
e9ef51341c Use geometry by default on custom expression functions
Got burnt by my own code. Them feels.
2015-12-09 13:02:58 +10:00
Matthias Kuhn
197ee6cb3a Fallback to pure PyQt4 for the moment
Fix #13948

Will probably require some packaging adjustments when reintroducing this.
2015-12-08 16:19:53 +01:00
Juergen E. Fischer
0519423b0f fix pyuic wrapper where qt4 & 5 are available 2015-11-29 17:04:56 +01:00
Matthias Kuhn
9ff6e1d499 Migrate first python test to be compatible with PyQt4 and PyQt5 2015-11-16 07:42:48 +01:00
Juergen E. Fischer
cc9c789760 avoid on duplicate user functions (fixes #13579) 2015-10-18 00:27:28 +02:00
Juergen E. Fischer
b39055b39c indentation update (now including autopep8) 2015-08-22 14:29:41 +02:00
Matthias Kuhn
8ab69e9386 with edit(layer) raises an error if the commit fails 2015-08-12 14:55:36 +02:00
Matthias Kuhn
f64783493e PyQgis: Move NULL and edit to qgis.core 2015-08-12 13:50:06 +02:00
Nathan Woodrow
f2144918d2 Less verbose template function message.
args='auto' and group='custom' as default
2015-05-27 22:39:12 +10:00
Nathan Woodrow
e6403da7b2 Remove adding $ to front of custom functions
Fixes calling no argument functions
2015-05-27 21:27:24 +10:00
Juergen E. Fischer
956c155e8f fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
     --exclude="ui_*.py,debian/*,python/ext-libs/*" \
     .
2015-02-01 20:46:47 +01:00
Juergen E. Fischer
cce2eb50cb indentation update 2015-01-22 20:56:02 +01:00
Nathan Woodrow
bed278a729 Expand args for custom functions. Add auto arg count
Format test to use spaces and not tabs
2015-01-22 09:21:41 +10:00
Nathan Woodrow
d9042f590f Follow up 6a17a60ae2 - Fix error when passing usesgeometry to qgsfunction 2015-01-10 10:43:12 +10:00
Nathan Woodrow
391d105ce0 [Expression] Don't unregister function if not registering 2014-11-30 00:40:22 +10:00
Nathan Woodrow
6a17a60ae2 Move qgsfunction to qgis.core.
Add new register_function method when not using decorator
Wrap function call in try block to catch and report errors
2014-11-29 18:37:26 +10:00