This allows nice and simple, elegant construction of checks for
Python.
To use, Python based checks should use the decorator syntax:
from qgis.core import check
@check.register(type=QgsAbstractValidityCheck.TypeLayoutCheck)
def my_layout_check(context, feedback):
results = ...
return results
Or, a more complete example. This one throws a warning when attempting
to export a layout with a map item set to the Web Mercator projection:
@check.register(type=QgsAbstractValidityCheck.TypeLayoutCheck)
def layout_map_crs_choice_check(context, feedback):
layout = context.layout
results = []
for i in layout.items():
if isinstance(i, QgsLayoutItemMap) and i.crs().authid() == 'EPSG:3857':
res = QgsValidityCheckResult()
res.type = QgsValidityCheckResult.Warning
res.title='Map projection is misleading'
res.detailedDescription='The projection for the map item {} is set to <i>Web Mercator (EPSG:3857)</i> which misrepresents areas and shapes. Consider using an appropriate local projection instead.'.format(i.displayName())
results.append(res)
return results
Up to date it was not possible to create a function that handles NULL values with the
@qgsfunction decorator. As soon as any parameter was NULL, the return value would also
be NULL.
Example of a function that returns a value now with a NULL paramter and would have returned NULL before
```
@qgsfunction(args=-1, group='Custom', handlesnull=True)
def mean_value(vals, feature, parent):
valid_vals = [val for val in vals if val != NULL]
return sum(valid_vals)/len(valid_vals)
```
[FEATURE]
* [pyqgis] add QgsSettings.enumValue and flagValue to the bindings
these are done in pure Python since no implementation is possible in SIP
there is a dirty hack for flags since QgsMapLayerProxyModel.Filters.__qualname__
returns 'Filters' and not 'QgsMapLayerProxyModel.Filters'
* fix typo