Bug report #14153

loadNamedStyle fail to load edit widget

Added by Peter Petrik about 8 years ago. Updated about 5 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Edit widget
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:end of life
Crashes QGIS or corrupts data:No Copied to github as #:22155

Description

This code correctly loads style from qml file and adds layer 'test' to the map canvas (see attached zip file).
The QML file defines edit widget for attribute called 'attr' with the 'value map' type (see attached screenshot):

vl = QgsVectorLayer('test.shp', 'test', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(vl)
vl.loadNamedStyle('style.qml')

But this code doesn't load correct edit widget, just shows default 'Text Edit' edit widget

vl = QgsVectorLayer('test.shp', 'test', 'ogr')
vl.loadNamedStyle('style.qml')
QgsMapLayerRegistry.instance().addMapLayer(vl)

Note: both codes correctly load renderer style

edit_bug.zip (3.89 KB) Peter Petrik, 2016-01-21 05:58 AM

edit_value_map.png (73.5 KB) Peter Petrik, 2016-01-21 05:58 AM

History

#1 Updated by Sebastian Dietrich about 8 years ago

  • Affected QGIS version changed from 2.10.1 to master

Widgets are loaded separately from the layers by QgsEditorWidgetRegistry. It watches the layers that are known to it and when a layer is loading a new style, QgsEditorWidgetRegistry loads the widgets for that layer.
Unfortunately QgsEditorWidgetRegistry only knows of the layers that are added to QgsMapLayerRegistry. So the effect is as you describe: loading QML after adding the layer works, loading QML before adding the layer does not.

The solution could be to simply make all (vector-)layers known to QgsEditorWidgetRegistry. But that might have other, probably unwanted, effects. I can't tell.

#2 Updated by Giovanni Manghi almost 7 years ago

  • Easy fix? set to No
  • Regression? set to No

#3 Updated by Giovanni Manghi about 5 years ago

  • Resolution set to end of life
  • Status changed from Open to Closed

Also available in: Atom PDF