From 1318a90c022d9ce77c05cd4ad0ef1ff2e3d77aa5 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 23 Oct 2020 12:53:36 +0200 Subject: [PATCH] Adapt tests --- .../layertree/qgslayertreeview.sip.in | 10 ++++---- src/gui/layertree/qgslayertreeview.h | 10 ++++---- tests/src/python/test_qgslayertreeview.py | 25 ++++++++++++++----- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/python/gui/auto_generated/layertree/qgslayertreeview.sip.in b/python/gui/auto_generated/layertree/qgslayertreeview.sip.in index f10adcbfdd8..92896cc2196 100644 --- a/python/gui/auto_generated/layertree/qgslayertreeview.sip.in +++ b/python/gui/auto_generated/layertree/qgslayertreeview.sip.in @@ -104,7 +104,7 @@ Returns the proxy model used by the view. This can be used to set filters controlling which layers are shown in the view. -.. versionadded:: 3.16 +.. versionadded:: 3.18 %End QgsLayerTreeNode *index2node( const QModelIndex &index ) const; @@ -115,7 +115,7 @@ Returns ``None`` if index does not refer to a layer tree node (e.g. it is a lege Unlike :py:func:`QgsLayerTreeModel.index2Node()`, calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model. -.. versionadded:: 3.16 +.. versionadded:: 3.18 %End QModelIndex node2index( QgsLayerTreeNode *node ) const; @@ -125,7 +125,7 @@ Returns index for a given node. If the node does not belong to the layer tree, t Unlike :py:func:`QgsLayerTreeModel.node2index()`, calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model. -.. versionadded:: 3.16 +.. versionadded:: 3.18 %End QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index ) const; @@ -135,7 +135,7 @@ Returns legend node for given index. Returns ``None`` for invalid index Unlike :py:func:`QgsLayerTreeModel.index2legendNode()`, calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model. -.. versionadded:: 3.16 +.. versionadded:: 3.18 %End QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode ); @@ -146,7 +146,7 @@ If the legend node is belongs to the tree but it is filtered out, invalid model Unlike :py:func:`QgsLayerTreeModel.legendNode2index()`, calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model. -.. versionadded:: 3.16 +.. versionadded:: 3.18 %End QgsLayerTreeViewDefaultActions *defaultActions(); diff --git a/src/gui/layertree/qgslayertreeview.h b/src/gui/layertree/qgslayertreeview.h index 6374f6bb627..c7ae439d6dc 100644 --- a/src/gui/layertree/qgslayertreeview.h +++ b/src/gui/layertree/qgslayertreeview.h @@ -110,7 +110,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView * * This can be used to set filters controlling which layers are shown in the view. * - * \since QGIS 3.16 + * \since QGIS 3.18 */ QgsLayerTreeProxyModel *proxyModel() const; @@ -121,7 +121,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView * Unlike QgsLayerTreeModel::index2Node(), calling this method correctly accounts * for mapping the view indexes through the view's proxy model to the source model. * - * \since QGIS 3.16 + * \since QGIS 3.18 */ QgsLayerTreeNode *index2node( const QModelIndex &index ) const; @@ -131,7 +131,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView * Unlike QgsLayerTreeModel::node2index(), calling this method correctly accounts * for mapping the view indexes through the view's proxy model to the source model. * - * \since QGIS 3.16 + * \since QGIS 3.18 */ QModelIndex node2index( QgsLayerTreeNode *node ) const; @@ -141,7 +141,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView * Unlike QgsLayerTreeModel::index2legendNode(), calling this method correctly accounts * for mapping the view indexes through the view's proxy model to the source model. * - * \since QGIS 3.16 + * \since QGIS 3.18 */ QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index ) const; @@ -152,7 +152,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView * Unlike QgsLayerTreeModel::legendNode2index(), calling this method correctly accounts * for mapping the view indexes through the view's proxy model to the source model. * - * \since QGIS 3.16 + * \since QGIS 3.18 */ QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode ); diff --git a/tests/src/python/test_qgslayertreeview.py b/tests/src/python/test_qgslayertreeview.py index 630fc69ebf9..c15a89fdbcf 100644 --- a/tests/src/python/test_qgslayertreeview.py +++ b/tests/src/python/test_qgslayertreeview.py @@ -38,6 +38,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def __init__(self, methodName): """Run once on class initialization.""" + unittest.TestCase.__init__(self, methodName) # setup a dummy project @@ -56,8 +57,8 @@ class TestQgsLayerTreeView(unittest.TestCase): self.model = QgsLayerTreeModel(self.project.layerTreeRoot()) def nodeOrder(self, group): + nodeorder = [] - layerTree = QgsLayerTree() for node in group: if QgsLayerTree.isGroup(node): groupname = node.name() @@ -69,6 +70,7 @@ class TestQgsLayerTreeView(unittest.TestCase): return nodeorder def testSetModel(self): + view = QgsLayerTreeView() # should not work @@ -78,9 +80,10 @@ class TestQgsLayerTreeView(unittest.TestCase): # should work view.setModel(self.model) - self.assertEqual(view.model(), self.model) + self.assertEqual(view.layerTreeModel(), self.model) def testSetCurrentLayer(self): + view = QgsLayerTreeView() view.setModel(self.model) current_layer_changed_spy = QSignalSpy(view.currentLayerChanged) @@ -111,6 +114,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveOutOfGroupActionLayer(self): """Test move out of group action on layer""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().addGroup("embeddedgroup") group.addLayer(self.layer4) @@ -141,6 +145,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToTopActionLayer(self): """Test move to top action on layer""" + view = QgsLayerTreeView() view.setModel(self.model) actions = QgsLayerTreeViewDefaultActions(view) @@ -152,6 +157,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToTopActionGroup(self): """Test move to top action on group""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().addGroup("embeddedgroup") group.addLayer(self.layer4) @@ -168,7 +174,7 @@ class TestQgsLayerTreeView(unittest.TestCase): groupname + '-' + self.layer5.name(), ]) - nodeLayerIndex = self.model.node2index(group) + nodeLayerIndex = view.node2index(group) view.setCurrentIndex(nodeLayerIndex) movetotop = actions.actionMoveToTop() movetotop.trigger() @@ -183,6 +189,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToTopActionEmbeddedGroup(self): """Test move to top action on embeddedgroup layer""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().addGroup("embeddedgroup") group.addLayer(self.layer4) @@ -213,6 +220,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToTopActionLayerAndGroup(self): """Test move to top action for a group and it's layer simultaneously""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().addGroup("embeddedgroup") group.addLayer(self.layer4) @@ -231,7 +239,7 @@ class TestQgsLayerTreeView(unittest.TestCase): selectionMode = view.selectionMode() view.setSelectionMode(QgsLayerTreeView.MultiSelection) - nodeLayerIndex = self.model.node2index(group) + nodeLayerIndex = view.node2index(group) view.setCurrentIndex(nodeLayerIndex) view.setCurrentLayer(self.layer5) view.setSelectionMode(selectionMode) @@ -248,6 +256,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToBottomActionLayer(self): """Test move to bottom action on layer""" + view = QgsLayerTreeView() view.setModel(self.model) actions = QgsLayerTreeViewDefaultActions(view) @@ -259,6 +268,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToBottomActionGroup(self): """Test move to bottom action on group""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup") group.addLayer(self.layer4) @@ -275,7 +285,7 @@ class TestQgsLayerTreeView(unittest.TestCase): self.layer3.name(), ]) - nodeLayerIndex = self.model.node2index(group) + nodeLayerIndex = view.node2index(group) view.setCurrentIndex(nodeLayerIndex) movetobottom = actions.actionMoveToBottom() movetobottom.trigger() @@ -290,6 +300,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToBottomActionEmbeddedGroup(self): """Test move to bottom action on embeddedgroup layer""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().addGroup("embeddedgroup") group.addLayer(self.layer4) @@ -320,6 +331,7 @@ class TestQgsLayerTreeView(unittest.TestCase): def testMoveToBottomActionLayerAndGroup(self): """Test move to top action for a group and it's layer simultaneously""" + view = QgsLayerTreeView() group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup") group.addLayer(self.layer4) @@ -338,7 +350,7 @@ class TestQgsLayerTreeView(unittest.TestCase): selectionMode = view.selectionMode() view.setSelectionMode(QgsLayerTreeView.MultiSelection) - nodeLayerIndex = self.model.node2index(group) + nodeLayerIndex = view.node2index(group) view.setCurrentIndex(nodeLayerIndex) view.setCurrentLayer(self.layer4) view.setSelectionMode(selectionMode) @@ -354,6 +366,7 @@ class TestQgsLayerTreeView(unittest.TestCase): ]) def testSetLayerVisible(self): + view = QgsLayerTreeView() view.setModel(self.model) self.project.layerTreeRoot().findLayer(self.layer).setItemVisibilityChecked(True)