Skip to content

Commit

Permalink
Dox++, unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 30, 2019
1 parent 62f5f5e commit b9482dd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/layertree/qgslayertreenode.sip.in
Expand Up @@ -169,6 +169,8 @@ Returns whether a node is checked (independently of its ancestors or children)
%Docstring
Check or uncheck a node (independently of its ancestors or children)

.. seealso:: :py:func:`QgsLayerTreeView.setLayerVisible`

.. versionadded:: 3.0
%End

Expand Down
4 changes: 3 additions & 1 deletion python/gui/auto_generated/layertree/qgslayertreeview.sip.in
Expand Up @@ -79,7 +79,9 @@ Returns the currently selected layer, or ``None`` if no layers is selected.

void setLayerVisible( QgsMapLayer *layer, bool visible );
%Docstring
Sets the visible state of the specified layer
Convenience methods which sets the visible state of the specified map ``layer``.

.. seealso:: :py:func:`QgsLayerTreeNode.setItemVisibilityChecked`

.. versionadded:: 3.10
%End
Expand Down
3 changes: 3 additions & 0 deletions src/core/layertree/qgslayertreenode.h
Expand Up @@ -170,6 +170,9 @@ class CORE_EXPORT QgsLayerTreeNode : public QObject

/**
* Check or uncheck a node (independently of its ancestors or children)
*
* \see QgsLayerTreeView::setLayerVisible()
*
* \since QGIS 3.0
*/
void setItemVisibilityChecked( bool checked );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/layertree/qgslayertreeview.h
Expand Up @@ -88,8 +88,9 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
QgsMapLayer *currentLayer() const;

/**
* Sets the visible state of the specified layer
* Convenience methods which sets the visible state of the specified map \a layer.
*
* \see QgsLayerTreeNode::setItemVisibilityChecked()
* \since QGIS 3.10
*/
void setLayerVisible( QgsMapLayer *layer, bool visible );
Expand Down
16 changes: 16 additions & 0 deletions tests/src/python/test_qgslayertreeview.py
Expand Up @@ -211,6 +211,22 @@ def testMoveToTopActionEmbeddedGroup(self):
groupname + '-' + self.layer4.name(),
])

def testSetLayerVisible(self):
view = QgsLayerTreeView()
view.setModel(self.model)
self.project.layerTreeRoot().findLayer(self.layer).setItemVisibilityChecked(True)
self.project.layerTreeRoot().findLayer(self.layer2).setItemVisibilityChecked(True)
self.assertTrue(self.project.layerTreeRoot().findLayer(self.layer).itemVisibilityChecked())
self.assertTrue(self.project.layerTreeRoot().findLayer(self.layer2).itemVisibilityChecked())

view.setLayerVisible(None, True)
view.setLayerVisible(self.layer, True)
self.assertTrue(self.project.layerTreeRoot().findLayer(self.layer).itemVisibilityChecked())
view.setLayerVisible(self.layer2, False)
self.assertFalse(self.project.layerTreeRoot().findLayer(self.layer2).itemVisibilityChecked())
view.setLayerVisible(self.layer2, True)
self.assertTrue(self.project.layerTreeRoot().findLayer(self.layer2).itemVisibilityChecked())


if __name__ == '__main__':
unittest.main()

0 comments on commit b9482dd

Please sign in to comment.