Thank you for your help!

I try to implement a data defined button to select a feature subset for the DataPlotly plugin. You can see my code here:

https://github.com/SGroe/DataPlotly/blob/master/DataPlotly/gui/layout_item_gui.py

Unfortunately, when I click on the data defined button, it freezes a minute until QGIS crashes with the following error:

QList::QList qlist.h:809
QgsExpressionContext::variableNames qgsexpressioncontext.cpp:408
QgsPropertyOverrideButton::aboutToShowMenu qgspropertyoverridebutton.cpp:475
QMetaObject::activate :
QMenu::popup :
QMenu::exec :
QToolButton::paintEvent :
QToolButton::showMenu :
QToolButton::~QToolButton :

...

Do you have an idea why this happens?

Simon


Am 18.10.2019 um 01:07 schrieb Nyall Dawson:
On Fri, 18 Oct 2019 at 06:29, Simon Gröchenig
<simon.groeche...@salzburgresearch.at> wrote:
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?
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






Regards,
Simon

_______________________________________________
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

--
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
simon.groeche...@salzburgresearch.at
http://www.salzburgresearch.at

_______________________________________________
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