Bug report #17307
Problem with conversion of python strings, e.g. when labeling using setCustomProperty()
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | - | ||
Category: | Python bindings / sipify | ||
Affected QGIS version: | 2.18.13 | Regression?: | Yes |
Operating System: | Windows 10 x64 | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | fixed/implemented |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 25205 |
Description
For me it's not possible anymore to configure labeling (for QgsVectorLayer) using setCustomProperty().
I found out that setCustomProperty() is working fine in the python console.
So my problem is not setCustomProperty() itself, but something with the QVariant and/or QLatin1String type.
Labeling seems to be correctly configured when I check it in the python console:
layer = iface.activeLayer()
layer.customProperty("labeling")'pal'
layer.customProperty("labeling/enabled")
'true'
But when I look at the types the result is this:
layer.customProperty("labeling").__class__
<class 'future.types.newstr.newstr'>
layer.customProperty("labeling/enabled").__class__
<class 'future.types.newstr.newstr'>
This code does NOT make labeling work:
layer.setCustomProperty("labeling", layer.customProperty("labeling"))
layer.setCustomProperty("labeling/enabled", layer.customProperty("labeling/enabled"))
But this code does:
layer.setCustomProperty("labeling", 'pal')
layer.setCustomProperty("labeling/enabled", 'true')
And this code also - at least in the python console:
layer.setCustomProperty("labeling",str(layer.customProperty("labeling")))
layer.setCustomProperty("labeling/enabled",str(layer.customProperty("labeling/enabled")))
I am not able to workaround this issue, because in my plugin the str() function always return a "newstr".
Do you have any hints how I could workaround this issue?
Maybe this line of code is the cause of this problem (QgsVectorLayer.cs, line 4546 in master):
if ( customProperty( QStringLiteral( "labeling" ) ).toString()==QLatin1String( "pal" ) )
History
#1 Updated by Giovanni Manghi about 7 years ago
- Priority changed from Normal to High
#2 Updated by Borys Jurgiel almost 7 years ago
- Category changed from Python plugins to Python bindings / sipify
#3 Updated by Jürgen Fischer almost 6 years ago
- Status changed from Open to Feedback
Please test with QGIS 3.4 - QGIS 2.18 reached it's end of life.
#4 Updated by Markus Woehling almost 6 years ago
With QGIS 3.4 everything is working fine.
#5 Updated by Nyall Dawson almost 6 years ago
- Resolution set to fixed/implemented
- Status changed from Feedback to Closed