Still hot from our forge: a new QGIS plugin allows dynamic filtering of items in combo boxes in attribute forms.
This plugin has been partially funded (50%) by ARPA Piemonte.
Description
This is a core-enhancement QGIS plugin that makes the implementation of complex dynamic filters in QGIS attribute forms an easy task. For example, this widget can be used to implement drill-down forms, where the values available in one field depend on the values of other fields.Download
The plugin is available on the official QGIS Python Plugin Repository and the source code is on GitHub QGIS Form Value Relation plugin repositoryImplementation
The new “Form Value Relation” widget is essentially a clone of the core “Value Relation” widget with some important differences: When the widget is created:- the whole unfiltered features of the related layer are loaded and cached
- the form values of all the attributes are added to the context (see below)
- the filtering against the expression happens every time the widget is refreshed
- a signal is bound to the form changes and if the changed field is present in the filter expression, the features are filtered against the expression and the widget is refreshed
Using form values in the expression
A new expression function is available (in the “Custom” section):CurrentFormValue('FIELD_NAME')This function returns the current value of a field in the editor form.
Note
- This function can only be used inside forms and it’s particularly useful when used together with the custom widget `Form Value Relation`
- If the field does not exists the function returns an empty string.
Anonymous
Thanks for this plugin,
It’s exactly what I need but i do not manage to use it. Would it be possible to describe the layer that you are working with and the field of this layers ? With that I would be able to adapt it to my needs.
Alessandro Pasotti
Just added an example project, hope that helps.
Colin
That’s perfect, I get it working with what I wanted to do.
Thanks a lot
DV
can I use this plugin together with a Qt Designer form?
Anonymous
@DV
No: a QT designer form uses its own widgets.
Eduardo
Looks like a nice addition! I will test in more detail later. I though on mentioning that when I did a quick test, the ui in the Edit Widget Properties did not load properly while having a locale language for QGIS (Finnish).
Alessandro Pasotti
@Eduardo,
Should be fixed with version 1.3
Casper B. Jensen
If I try to change the content of an attribute after I’ve created the feature my program crashes as I double-click on the attribute field with a pop-up windows saying
Minidump written to C: … \Temp\qgis-20160310-071702-9988-4565-99ac688.dmp
As well when I delete features they are kept in ‘Show feature Count’ and I get this Python-error:
2016-03-10T07:12:03 1 Traceback (most recent call last):
File “C:/Users/CasperBJ/.qgis2/python/plugins\FormAwareValueRelationWidget\FormAwareValueRelationWidget.py”, line 357, in createCache
layer = QgsMapLayerRegistry.instance().mapLayer( self.config( “Layer” ) )
RuntimeError: wrapped C/C++ object of type FormAwareValueRelationWidgetWrapper has been deleted
2016-03-10T07:12:24 1 Traceback (most recent call last):
File “C:/Users/CasperBJ/.qgis2/python/plugins\FormAwareValueRelationWidget\FormAwareValueRelationWidget.py”, line 357, in createCache
layer = QgsMapLayerRegistry.instance().mapLayer( self.config( “Layer” ) )
RuntimeError: wrapped C/C++ object of type FormAwareValueRelationWidgetWrapper has been deleted
2016-03-10T07:12:37 1 Traceback (most recent call last):
File “C:/Users/CasperBJ/.qgis2/python/plugins\FormAwareValueRelationWidget\FormAwareValueRelationWidget.py”, line 357, in createCache
layer = QgsMapLayerRegistry.instance().mapLayer( self.config( “Layer” ) )
RuntimeError: wrapped C/C++ object of type FormAwareValueRelationWidgetWrapper has been deleted
2016-03-10T07:12:37 1 Traceback (most recent call last):
File “C:/Users/CasperBJ/.qgis2/python/plugins\FormAwareValueRelationWidget\FormAwareValueRelationWidget.py”, line 357, in createCache
layer = QgsMapLayerRegistry.instance().mapLayer( self.config( “Layer” ) )
RuntimeError: wrapped C/C++ object of type FormAwareValueRelationWidgetWrapper has been deleted
2016-03-10T07:13:52 1 Traceback (most recent call last):
File “C:/Users/CasperBJ/.qgis2/python/plugins\FormAwareValueRelationWidget\FormAwareValueRelationWidget.py”, line 357, in createCache
layer = QgsMapLayerRegistry.instance().mapLayer( self.config( “Layer” ) )
RuntimeError: wrapped C/C++ object of type FormAwareValueRelationWidgetWrapper has been deleted
Anonymous
@Casper:
please file a ticket here: https://github.com/elpaso/qgis-formawarevaluerelationwidget/issues
Anonymous
Good job!
This works fine except when we use a subform (relation 1-n of a database).