2

I have a problem with predefined values and their order in 'value map' field. Wnen I tried this Creating predefined values in field using PyQGIS it works, but I'm not able to keep order (even when I use OrderedDict instead of dict). The second problem is how to insert also empty value.

    val_map = OrderedDict()
    for value,label in sorted(val['values'].items()):
        val_map[label.decode("utf-8")] = label.decode("utf-8")
    print(val_map)
    vlayer.setEditorWidgetV2( index, 'ValueMap' )
    vlayer.setEditorWidgetV2Config(index, val_map)

Result:

OrderedDict([(u'silnice I.t\u0159', u'silnice I.t\u0159'), (u'silnice II.t\u0159', u'silnice II.t\u0159'), (u'silnice III.t\u0159', u'silnice III.t\u0159'), (u'MK I.t\u0159', u'MK I.t\u0159'), (u'MK II.t\u0159', u'MK II.t\u0159'), (u'MK III.t\u0159', u'MK III.t\u0159'), (u'MK IV.t\u0159', u'MK IV.t\u0159'), (u'UK', u'UK')])

But you can see, that there is alphabetical order in value map enter image description here

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
betka
  • 31
  • 2
  • 3
    Did you try your OrderedDict.keys() and orderedDict.values()? It would be good if you post the code that didn't work for you so that we know what went wrong. – wondim Jun 23 '17 at 15:19

0 Answers0