<div dir="ltr">Hi Matteo,<div><br><br><div class="gmail_quote"><div dir="ltr">Le lun. 26 juin 2017 à 13:11, matteo <<a href="mailto:matteo.ghetta@gmail.com">matteo.ghetta@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I'm writing a plugin that uses QgsFieldExpressionWidget to get the field<br>
and its attributes from a layer.<br>
<br>
I'm really fighting to find a method to get the attributes of the field<br>
as a list when an expression if typed.<br></blockquote><div><br></div><div>It's a bit unclear to me the distinction you make between fields and attributes. Can you detail what you call "attributes of the field"? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Supposing the layer has a field called PH and n attributes:<br>
<br>
1. if just PH (so the name of the field) is selected than it is pretty<br>
straightforward:<br>
<br>
# self.expBox is the name of the widget<br>
field = self.expBox.currentText()<br>
data = []<br>
for i in vl.getFeatures():<br>
    data.append(i[field])<br>
<br>
2. if a whatever expression is typed, e.g. PH > 7, than I get some<br>
problem on how I can retrieve the name of the field from the widget.<br></blockquote><div><br></div><div>Well, you don't have a field anymore as you typed an expression. There might be ways to get fields out of an expression I guess. Not sure it's in the public API though. Better ask experts here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Knowing the field name it should be something like:<br>
<br>
exp = QgsFeatureRequest().setFilterExpression(' PH > 7 ')<br>
request.setSubsetOfAttributes([])<br>
<br>
data = []<br>
for f in vl.getFeatures(request):<br>
    data.append(f['PH'])<br>
<br>
so I don't understand how I can get just the PH string (so the field<br>
name) from the widget in order to put it in the loop and get only the<br>
required attributes .<br></blockquote><div><br></div><div> So, if I understand well you want to retrieve the fields used in an expression, is this correct?</div><div>Matthias or others can answer this for sure.<br></div><div><br></div><div>Denis</div><div><br></div></div></div></div>