Bug report #17305
Labeling using setCustomProperty()
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | - | ||
Category: | Labelling | ||
Affected QGIS version: | 2.18.13 | Regression?: | Yes |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 25203 |
Description
It's not possible anymore to configure labeling (for QgsVectorLayer) using setCustomProperty().
It will be a breaking change in QGIS 3.0, but it's not working in 2.18.13 right now.
So I think it's a bug - especially because 2.18.13 is a LTR.
History
#1 Updated by Giovanni Manghi about 7 years ago
- Status changed from Open to Feedback
did it worked in previous qgis releases?
#2 Updated by Markus Woehling about 7 years ago
Yes, it did work up to version 2.14 (but I did not check 2.16).
#3 Updated by Giovanni Manghi about 7 years ago
- Priority changed from Normal to High
- Status changed from Feedback to Open
#4 Updated by Regis Haubourg about 7 years ago
Can you test EasyCustomLabeling plugin?
It uses setCustomProperty() a lot and in my experience, it works on 2.18.13.
#5 Updated by Markus Woehling about 7 years ago
EasyCustomLabeling is working on 2.18.13, right.
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" ) )
#6 Updated by Giovanni Manghi about 7 years ago
- Status changed from Open to Feedback
Markus Woehling wrote:
EasyCustomLabeling is working on 2.18.13, right.
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.
so maybe is better to close this and file a different one? or maybe edit the title and description of this one. Thanks.
#7 Updated by Markus Woehling about 7 years ago
I wanted to change the title of this issue to:
Problem with conversion of strings, e.g. when labeling using setCustomProperty()
But I'm not able to do it... so I'll created a new issue.
#8 Updated by Giovanni Manghi about 7 years ago
- Resolution set to invalid
- Status changed from Feedback to Closed
Closed in favor of #17307