<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Thank you for your help!</p>
    <p>I try to implement a data defined button to select a feature
      subset for the DataPlotly plugin. You can see my code here:<br>
    </p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/SGroe/DataPlotly/blob/master/DataPlotly/gui/layout_item_gui.py">https://github.com/SGroe/DataPlotly/blob/master/DataPlotly/gui/layout_item_gui.py</a></p>
    <p>Unfortunately, when I click on the data defined button, it
      freezes a minute until QGIS crashes with the following error:</p>
    <p><font size="-2"><span style=" font-family:'Courier New';">QList::QList
          qlist.h:809<br>
          QgsExpressionContext::variableNames
          qgsexpressioncontext.cpp:408<br>
          QgsPropertyOverrideButton::aboutToShowMenu
          qgspropertyoverridebutton.cpp:475<br>
          QMetaObject::activate :<br>
          QMenu::popup :<br>
          QMenu::exec :<br>
          QToolButton::paintEvent :<br>
          QToolButton::showMenu :<br>
          QToolButton::~QToolButton :</span></font></p>
    <p><font size="-2"><span style=" font-family:'Courier New';">...</span></font></p>
    <div class="moz-cite-prefix">Do you have an idea why this happens?</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Simon<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Am 18.10.2019 um 01:07 schrieb Nyall
      Dawson:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAB28AsjAwHV=VEu=F=p9KpkxBx0ANCLqwX3GgcghcfDqK6cJ6g@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">On Fri, 18 Oct 2019 at 06:29, Simon Gröchenig
<a class="moz-txt-link-rfc2396E" href="mailto:simon.groechenig@salzburgresearch.at"><simon.groechenig@salzburgresearch.at></a> wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
Hi,

I want to add a QgsPropertyOverrideButton to define a expression to filter features in a python plugin. Specifically, I want to filter the features using the @altas_feature variable. However, all variables are missing in the expression dialog.

Can anyone tell me how I can add the variables to the expression dialog?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Hi Simon,

This is all controlled via expression contexts. There's a few parts to
the puzzle:

1. Crafting an appropriate expression context using the individual
"scope" creation functions available through
QgsExpressionContextUtils. You generally start with a global, project
and layer scope, and then add additional scopes on top depending on
the "context" in which the expression will be evaluated.

So something like:

context = QgsExpressionContext()
context.appendScope( QgsExpressionContextUtils.globalScope() )
context.appendScope( QgsExpressionContextUtils.projectScope(
QgsProject.instance() ) )
context.appendScope( QgsExpressionContextUtils.atlasScope( None ) )
context.appendScope( QgsExpressionContextUtils.mapSettingsScope(
iface.mapCanvas() ) )

OR -- depending on the context -- you can get a pre-made context given
straight to you. E.g. if the expression evaluation is occurring inside
a layout item, then you must use

context = item.createExpressionContext()

instead of making your own.

So this part is very dependant on the "context" in which the
expression will be evaluated.

2. Make your dialog or widget which contains the button implement the
QgsExpressionContextGenerator interface.

3. Register your dialog/widget as the context generator for the button
by calling something like

button.registerExpressionContextGenerator( dialog )


Nyall






</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
Regards,
Simon

_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
      </blockquote>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Simon Gröchenig MSc
MOWI - Mobile and Web-based Information Systems

Salzburg Research Forschungsgesellschaft mbH
Jakob-Haringer-Straße 5/3 | 5020 Salzburg, Austria
T: +43.662.2288-314
<a class="moz-txt-link-abbreviated" href="mailto:simon.groechenig@salzburgresearch.at">simon.groechenig@salzburgresearch.at</a>
<a class="moz-txt-link-freetext" href="http://www.salzburgresearch.at">http://www.salzburgresearch.at</a></pre>
  </body>
</html>