Bug report #15844
Layertree node texts in legend are not repainted after (name) change?
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | Martin Dobias | ||
Category: | Unknown | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 23762 |
Description
Having a layer of which the data is periodically updated, I wanted to show the update time in the layer in the legend.
It is easy to do (and to test in Python console):
treenode = QgsProject.instance().layerTreeRoot().insertGroup(0, 'Test node') treenode.setName('Renamed Test Node')
Result: the Legend is NOT updated UNTILL you move your mouse over the legend. But moving your mouse over the legend THEN it is.
Apparently some kind of repaint event is missing somewhere?
I could not find a handle to the legend (in python) to do a repaint/refresh of the widget.
Tested in 2.18 and master/3
(assigning to Martin??, as he is the layertreenodeman :-) but feel free to move it around)
Associated revisions
Propagate layer/group name changes in the layer tree (fixes #15844)
Propagate layer/group name changes in the layer tree (fixes #15844)
(cherry picked from commit 968e02d6fe38b024855ef75852eb033b4ad9ecbd)
History
#1 Updated by Richard Duivenvoorde about 8 years ago
Could this be related to: #14756 ?
#2 Updated by Richard Duivenvoorde about 8 years ago
Here on a Windows computer with 2.14.1 (I know.. old...) it does not refresh the name when hovering over the panel (like it does on a Linux desktop). You have to click(!) in the legend panel (or on the legend panel title bar) to have it repainted.
#3 Updated by Martin Dobias about 8 years ago
There are some missing signals, that is why the updates do not work automatically. For 2.x one could use this as a workaround:
model = iface.layerTreeView().model() index = model.node2index(treenode) model.setData(index, 'new name')
The issue is there also when renaming raster layers (for unknown reasons only vector layers used to have name changed signal).
For master/3.0 I will make a fix, and possibly port it to 2.18.x
#4 Updated by Martin Dobias about 8 years ago
- Status changed from Open to Closed
Fixed in changeset 968e02d6fe38b024855ef75852eb033b4ad9ecbd.
#5 Updated by Richard Duivenvoorde about 8 years ago
@Martin: Tested and Working in 3.0. thanks!
Looking at this line
https://github.com/qgis/QGIS/blob/master/src/core/layertree/qgslayertreemodel.cpp#L206
I think the creation of a layername+featurecount is also done there, but I'm not sure if this also fixes this issue:
#14756
which is working with "layer.setSubsetString(subsetString)"...
which also should update the 'name' of the layer because it contains the featurecount...
What do you think, is that also fixed now? I cannot test because TimeManager is not working yet in QGIS3...
Do you think we could/should cherrypick this to 2.16 or 2.18?
#6 Updated by Martin Dobias about 8 years ago
I will port the fix to 2.18. (2.14 would need extra patching, 2.16 is not updated)
#14756 is a different problem - setSubsetString() does not have a specific signal to be emitted to indicate that feature count needs to be updated.
#7 Updated by Richard Duivenvoorde about 8 years ago
@Martin I tested in 2.18: OK now
but instead of creating a 'setName' signal, shouldn't there be a more generic signal? To update the layertree labels?
I reckon more plugins/functions will start updating names/featurecounts/whateverfuturebrings and it would be good to have a 'updatelegend' signal or so? So it can be used as some "'repaint/reconstruct' the legend again based on the model"?
Or do you think that is overkill?
#8 Updated by Martin Dobias about 8 years ago
The layer tree does not know anything about legend, so requests for legend update need to be handled elsewhere. Layer tree only cares about groups and layers.
There is QgsLayerTreeModel::refreshLayerLegend(nodeLayer) method to update legend of a layer in a particular tree model. It is already called automatically on various occasions.
#9 Updated by Jürgen Fischer about 7 years ago
- Category set to Unknown