Re: [QGIS-Developer] QgsExpression python pattern

2018-01-31 Thread Nyall Dawson
On 1 February 2018 at 05:45, Chris Crook  wrote:
> I am updating some plugins which use QgsExpression, and I'm wondering about 
> the best way to use expressions in QGIS3.  It in the past I used a pattern 
> like:
>
>   exp=QgsExpression(expressionText)
>   exp.prepare(fields)
>   request=QgsFeatureRequest()
>   request.setSubsetOfAttributes( expression.referencedColumns(), fields )
>   for feat in layer.getFeatures(request)
>   value=expression.evaluate(feat)
>
> However with QGIS3 this has clearly changed!  QgsExpression is not included 
> in the QGIS3 API https://qgis.org/api/annotated.html.

That's a bug with the generated docs (fix incoming ) - it's still
around. BTW you may prefer the work-in-progress Python API docs here:
http://python.qgis.org/api/

> The prepare and referencedColumns are no longer defined. I did have a look at 
> the C++ code for QgsExpression, but I find I'm still looking for guidance.
>
> I've searched the QEP issues  been able to locate a QEP, or other 
> documentation.  Can anyone point me to some documentation or provide an 
> example of current best practice please.

Best place to check first is the API breaks docs:

https://qgis.org/api/api_break.html

This details the changes in QgsExpression (amongst all the other classes).

Hope that helps!

Nyall
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] QgsExpression python pattern

2018-01-31 Thread Chris Crook
Chris Crook wrote
> I am updating some plugins which use QgsExpression, and I'm wondering
> about the best way to use expressions in QGIS3.  It in the past I used a
> pattern like:
> 
>   exp=QgsExpression(expressionText)
>   exp.prepare(fields)
>   request=QgsFeatureRequest()
>   request.setSubsetOfAttributes( expression.referencedColumns(), fields )
>   for feat in layer.getFeatures(request)
>   value=expression.evaluate(feat)
> 
> However with QGIS3 this has clearly changed!  QgsExpression is not
> included in the QGIS3 API https://qgis.org/api/annotated.html.  The
> prepare and referencedColumns are no longer defined. I did have a look at
> the C++ code for QgsExpression, but I find I'm still looking for guidance.
> 
> I've searched the QEP issues  been able to locate a QEP, or other
> documentation.  Can anyone point me to some documentation or provide an
> example of current best practice please.

Correction: prepare and referencedColumns are still present, prepare takes
QgsExpressionContext rather than fields.  So I think the pattern is very
little changed





--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] QgsExpression python pattern

2018-01-31 Thread Chris Crook
I am updating some plugins which use QgsExpression, and I'm wondering about the 
best way to use expressions in QGIS3.  It in the past I used a pattern like:

  exp=QgsExpression(expressionText)
  exp.prepare(fields)
  request=QgsFeatureRequest()
  request.setSubsetOfAttributes( expression.referencedColumns(), fields )
  for feat in layer.getFeatures(request)
  value=expression.evaluate(feat)

However with QGIS3 this has clearly changed!  QgsExpression is not included in 
the QGIS3 API https://qgis.org/api/annotated.html.  The prepare and 
referencedColumns are no longer defined. I did have a look at the C++ code for 
QgsExpression, but I find I'm still looking for guidance.

I've searched the QEP issues  been able to locate a QEP, or other 
documentation.  Can anyone point me to some documentation or provide an example 
of current best practice please.



This message contains information, which may be in confidence and may be 
subject to legal privilege. If you are not the intended recipient, you must not 
peruse, use, disseminate, distribute or copy this message. If you have received 
this message in error, please notify us immediately (Phone 0800 665 463 or 
i...@linz.govt.nz) and destroy the original message. LINZ accepts no 
responsibility for changes to this email, or for any attachments, after its 
transmission from LINZ. Thank You.
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer