Bug report #11382

TopoViewer: all layers are added as visible while code asks them NOT to be

Added by Sandro Santilli over 9 years ago. Updated over 9 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:Martin Dobias
Category:DB Manager
Affected QGIS version:2.4.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:19669

Description

I guess something changed in the TOC api as the TopoViewer plugin of the DBManager now adds all layers as visible even if it makes its best to request then NOT to be.

Code snippet:

# NODES
group = legend.addGroup(u'Nodes', False, supergroup)
# should not be needed: #6938
legend.setGroupVisible(group, False)
layer = QgsVectorLayer(uri.uri(), u'%s.node' % toponame, provider)
registry.addMapLayers([layer])
legend.setLayerVisible(layer, False)
legend.setLayerExpanded(layer, False)
legend.moveLayer(layer, group)

Associated revisions

Revision 1ff2ad3c
Added by Sandro Santilli over 9 years ago

[TopoViewer] fix layer visibility after QgsLegendInterface API changes

It was broken with 2.4, whereas QgsLegendInterface::moveLayer started
forcing layer visibility on (undocumented behaviour).

Fixes #11382

Revision 3546b325
Added by Martin Dobias over 9 years ago

Fix #11382 (keep check state of the moved layer)

Cloning of the existing node will preserve the check state, in addition
it will keep other custom properties that would be lost prevously.

History

#1 Updated by Sandro Santilli over 9 years ago

  • Affected QGIS version changed from master to 2.4.0

#2 Updated by Sandro Santilli over 9 years ago

2.2.0 was fine

#3 Updated by Giovanni Manghi over 9 years ago

  • Priority changed from Normal to Severe/Regression

#4 Updated by Jürgen Fischer over 9 years ago

  • Subject changed from DBManager TopoViewer: all layers are added as visible while code asks them NOT to be to TopoViewer: all layers are added as visible while code asks them NOT to be
  • Category changed from Python plugins to DB Manager

#5 Updated by gillian milani over 9 years ago

The moveLayer(layer, group) make your layer visible.
So it's normal behavior.
Just change the order of commands, it sould work fine.

#6 Updated by Sandro Santilli over 9 years ago

Thank you Gillian, the change fixes the problem. But as of version 2.2 the behaviour was different.
Also, the API documentation doesn't say anything about moveLayer making the layer visible:
http://qgis.org/api/classQgsLegendInterface.html#a23183b102f51dfecb81b26ea570ff224

#7 Updated by Sandro Santilli over 9 years ago

  • Status changed from Open to Closed

#8 Updated by Salvatore Larosa over 9 years ago

I would reopen this issue as the moveLayer should not make the layer visible if it was not.
IMO, the normal behavior when moving a layer into a group is keeping the initial state of the layer.

here my proposal patch: https://github.com/qgis/QGIS/pull/1629

I also think you can drop all the stuff like "should not be needed: #6938" from topoviewer plugin :)

Thoughts?

#9 Updated by Sandro Santilli over 9 years ago

  • Status changed from Closed to Reopened

Agreed, reopened.

#10 Updated by Martin Dobias over 9 years ago

  • Status changed from Reopened to Closed

#11 Updated by Sandro Santilli over 9 years ago

Thanks, Martin. Could you also look at #6938 since you're at it ? Would be nice to drop other hacks from the plugin, like
https://github.com/qgis/QGIS/blob/final-2_4_0/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py#L154-L155

#12 Updated by Martin Dobias over 9 years ago

I think #6938 should not be an issue since 2.4 because the logic for visibility has been rewritten. Would you mind to check if your code works without that workaround in 2.4 / master - and eventually close that ticket?

Also available in: Atom PDF