Hi all,

I'm writing a plugin that uses QgsFieldExpressionWidget to get the field
and its attributes from a layer.

I'm really fighting to find a method to get the attributes of the field
as a list when an expression if typed.

Supposing the layer has a field called PH and n attributes:

1. if just PH (so the name of the field) is selected than it is pretty
straightforward:

# self.expBox is the name of the widget
field = self.expBox.currentText()
data = []
for i in vl.getFeatures():
    data.append(i[field])

2. if a whatever expression is typed, e.g. PH > 7, than I get some
problem on how I can retrieve the name of the field from the widget.
Knowing the field name it should be something like:

exp = QgsFeatureRequest().setFilterExpression(' PH > 7 ')
request.setSubsetOfAttributes([])

data = []
for f in vl.getFeatures(request):
    data.append(f['PH'])

so I don't understand how I can get just the PH string (so the field
name) from the widget in order to put it in the loop and get only the
required attributes .


I hope I have explained my problem...

Thanks to any feedback

Cheers

Matteo
_______________________________________________
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

Reply via email to