[Qgis-user] Customised attributes form
emmexx
emmexx at tiscalinet.it
Tue Mar 17 15:37:46 PDT 2015
Il 03/13/2015 10:50 AM, Matthias Kuhn scrisse:
> Create a python plugin that registers a custom widget like the one in
> the referenced blog post.
Following your tips I created a plugin that registers a tree widget.
And following the tutorial that you linked I was able to add a parameter
to set the layer that the treewidget should use as a model (sort of) for
data.
There's only one glitch. I expected that that parameter would be saved
when saving the project and loaded when opening it. But that is not the
case.
class TreeWidgetWrapperFactory( QgsEditorWidgetFactory ):
...
def readConfig( self, elem, layer, idx ):
""" Read a config object from an XML element """
pdb.set_trace()
config = dict()
config['MyTreeWidget'] = elem.attribute( 'MyTreeWidget' )
return config
The readConfig function never runs. I don't understand what could be
wrong because I copied and pasted the tutorial code for that class and
changed only the name of the parameter where to save the configuration
("MyTreeWidget" instead of "rule".)
All other functions regarding config['MyTreeWidget'] in the
wrapperConfig and WrapperFactory classes work as expected.
Inside the qgs file of the project I found 2 "instances" where the
parameter is present:
<projectlayers layercount="2">
...
<expressionfields/>
<edittypes>
<edittype widgetv2type="MyQTreeWidget" name="TYPE">
<widgetv2config fieldEditable="1" labelOnTop="0"
MyTreeWidget="tags"/>
</edittype>
</edittypes>
...
<attributeactions/>
<edittypes>
<edittype widgetv2type="MyQTreeWidget" name="TYPE">
<widgetv2config fieldEditable="1" labelOnTop="0"
MyTreeWidget="tags"/>
</edittype>
</edittypes>
What am I missing?
Thank you
maxx
More information about the Qgis-user
mailing list