Re: [QGIS-Developer] QGIS python action with Expression problem

2022-11-07 Thread Alessandro Pasotti via QGIS-Developer
On Mon, Nov 7, 2022 at 11:59 AM Andreas Neumann  wrote:
>
> Hi Ale,
>
> Thanks for the hint!

You're welcome!

the formScope adds another feature: the "form" feature which
represents a virtual feature with the values taken from the current
form status.

>
> With
>
> expContext.setFeature(form.feature())
>
> it seems to work.
>
> I was assuming that adding the formScope would also add the feature context 
> ... but apparently not.
>
> Now I can continue adding the more complex expression.
>
> Thank you for your help!
>
> Andreas
>
> On 2022-11-07 11:46, Alessandro Pasotti wrote:
>
> You need to set the feature if you want to access the feature fields.
>
> QgsExpressionContext::setFeature( const QgsFeature &feature )
>
> If you want the form feature values you need to use the current_value
> or the current_feature functions.
>
> Regards.
>
> On Mon, Nov 7, 2022 at 11:27 AM Andreas Neumann via QGIS-Developer
>  wrote:
>
>
> Hi,
>
> I am trying to implement a Python action in "form" and "feature" action scope 
> that uses a QGIS expression, but fail to get a valid expression calculation.
>
> Here is my code so far:
>
> from qgis.PyQt.QtWidgets import *
> from qgis.core import QgsMessageLog
>
> expContext = QgsExpressionContext()
> expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))
> expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))
>
> exp = QgsExpression('t_id')
>
> expResult = exp.evaluate(expContext)
> QgsMessageLog.logMessage('Expression Result=' + str(expResult))
>
>
> So even the most basic expression (getting a field value) will not work in my 
> code. I always get "None" as a result.
>
> Any idea what is missing? Am I missing a certain scope or an import statement?
>
> Thank you very much for any hints what might be wrong here ...
>
> Andreas
>
> ___
> 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
>
>
>
>


-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it
___
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] QGIS python action with Expression problem

2022-11-07 Thread Andreas Neumann via QGIS-Developer

Hi Ale,

Thanks for the hint!

With

expContext.setFeature(form.feature())

it seems to work.

I was assuming that adding the formScope would also add the feature 
context ... but apparently not.


Now I can continue adding the more complex expression.

Thank you for your help!

Andreas

On 2022-11-07 11:46, Alessandro Pasotti wrote:


You need to set the feature if you want to access the feature fields.

QgsExpressionContext::setFeature( const QgsFeature &feature )

If you want the form feature values you need to use the current_value
or the current_feature functions.

Regards.

On Mon, Nov 7, 2022 at 11:27 AM Andreas Neumann via QGIS-Developer
 wrote:


Hi,

I am trying to implement a Python action in "form" and "feature" 
action scope that uses a QGIS expression, but fail to get a valid 
expression calculation.


Here is my code so far:

from qgis.PyQt.QtWidgets import *
from qgis.core import QgsMessageLog

expContext = QgsExpressionContext()
expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))
expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))

exp = QgsExpression('t_id')

expResult = exp.evaluate(expContext)
QgsMessageLog.logMessage('Expression Result=' + str(expResult))

So even the most basic expression (getting a field value) will not 
work in my code. I always get "None" as a result.


Any idea what is missing? Am I missing a certain scope or an import 
statement?


Thank you very much for any hints what might be wrong here ...

Andreas

___
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 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] QGIS python action with Expression problem

2022-11-07 Thread Alessandro Pasotti via QGIS-Developer
You need to set the feature if you want to access the feature fields.

QgsExpressionContext::setFeature( const QgsFeature &feature )

If you want the form feature values you need to use the current_value
or the current_feature functions.

Regards.

On Mon, Nov 7, 2022 at 11:27 AM Andreas Neumann via QGIS-Developer
 wrote:
>
> Hi,
>
> I am trying to implement a Python action in "form" and "feature" action scope 
> that uses a QGIS expression, but fail to get a valid expression calculation.
>
> Here is my code so far:
>
> from qgis.PyQt.QtWidgets import *
> from qgis.core import QgsMessageLog
>
> expContext = QgsExpressionContext()
> expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))
> expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))
>
> exp = QgsExpression('t_id')
>
> expResult = exp.evaluate(expContext)
> QgsMessageLog.logMessage('Expression Result=' + str(expResult))
>
>
> So even the most basic expression (getting a field value) will not work in my 
> code. I always get "None" as a result.
>
> Any idea what is missing? Am I missing a certain scope or an import statement?
>
> Thank you very much for any hints what might be wrong here ...
>
> Andreas
>
> ___
> 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



-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it
___
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] QGIS python action with Expression problem

2022-11-07 Thread Andreas Neumann via QGIS-Developer

Hi,

I am trying to implement a Python action in "form" and "feature" action 
scope that uses a QGIS expression, but fail to get a valid expression 
calculation.


Here is my code so far:

from qgis.PyQt.QtWidgets import *
from qgis.core import QgsMessageLog

expContext = QgsExpressionContext()
expContext.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(form.layer()))
expContext.appendScope(QgsExpressionContextUtils.formScope(form.feature(),'SingleEditMode'))

exp = QgsExpression('t_id')

expResult = exp.evaluate(expContext)
QgsMessageLog.logMessage('Expression Result=' + str(expResult))

So even the most basic expression (getting a field value) will not work 
in my code. I always get "None" as a result.


Any idea what is missing? Am I missing a certain scope or an import 
statement?


Thank you very much for any hints what might be wrong here ...

Andreas___
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