Adapt tests

This commit is contained in:
Alessandro Pasotti 2020-10-23 12:53:36 +02:00
parent 2b7f2c8ca3
commit 1318a90c02
3 changed files with 29 additions and 16 deletions

View File

@ -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. This can be used to set filters controlling which layers are shown in the view.
.. versionadded:: 3.16 .. versionadded:: 3.18
%End %End
QgsLayerTreeNode *index2node( const QModelIndex &index ) const; 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 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. for mapping the view indexes through the view's proxy model to the source model.
.. versionadded:: 3.16 .. versionadded:: 3.18
%End %End
QModelIndex node2index( QgsLayerTreeNode *node ) const; 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 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. for mapping the view indexes through the view's proxy model to the source model.
.. versionadded:: 3.16 .. versionadded:: 3.18
%End %End
QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index ) const; 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 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. for mapping the view indexes through the view's proxy model to the source model.
.. versionadded:: 3.16 .. versionadded:: 3.18
%End %End
QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode ); 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 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. for mapping the view indexes through the view's proxy model to the source model.
.. versionadded:: 3.16 .. versionadded:: 3.18
%End %End
QgsLayerTreeViewDefaultActions *defaultActions(); QgsLayerTreeViewDefaultActions *defaultActions();

View File

@ -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. * 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; QgsLayerTreeProxyModel *proxyModel() const;
@ -121,7 +121,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
* Unlike QgsLayerTreeModel::index2Node(), calling this method correctly accounts * Unlike QgsLayerTreeModel::index2Node(), calling this method correctly accounts
* for mapping the view indexes through the view's proxy model to the source model. * 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; QgsLayerTreeNode *index2node( const QModelIndex &index ) const;
@ -131,7 +131,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
* Unlike QgsLayerTreeModel::node2index(), calling this method correctly accounts * Unlike QgsLayerTreeModel::node2index(), calling this method correctly accounts
* for mapping the view indexes through the view's proxy model to the source model. * 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; QModelIndex node2index( QgsLayerTreeNode *node ) const;
@ -141,7 +141,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
* Unlike QgsLayerTreeModel::index2legendNode(), calling this method correctly accounts * Unlike QgsLayerTreeModel::index2legendNode(), calling this method correctly accounts
* for mapping the view indexes through the view's proxy model to the source model. * 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; QgsLayerTreeModelLegendNode *index2legendNode( const QModelIndex &index ) const;
@ -152,7 +152,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
* Unlike QgsLayerTreeModel::legendNode2index(), calling this method correctly accounts * Unlike QgsLayerTreeModel::legendNode2index(), calling this method correctly accounts
* for mapping the view indexes through the view's proxy model to the source model. * 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 ); QModelIndex legendNode2index( QgsLayerTreeModelLegendNode *legendNode );

View File

@ -38,6 +38,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def __init__(self, methodName): def __init__(self, methodName):
"""Run once on class initialization.""" """Run once on class initialization."""
unittest.TestCase.__init__(self, methodName) unittest.TestCase.__init__(self, methodName)
# setup a dummy project # setup a dummy project
@ -56,8 +57,8 @@ class TestQgsLayerTreeView(unittest.TestCase):
self.model = QgsLayerTreeModel(self.project.layerTreeRoot()) self.model = QgsLayerTreeModel(self.project.layerTreeRoot())
def nodeOrder(self, group): def nodeOrder(self, group):
nodeorder = [] nodeorder = []
layerTree = QgsLayerTree()
for node in group: for node in group:
if QgsLayerTree.isGroup(node): if QgsLayerTree.isGroup(node):
groupname = node.name() groupname = node.name()
@ -69,6 +70,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
return nodeorder return nodeorder
def testSetModel(self): def testSetModel(self):
view = QgsLayerTreeView() view = QgsLayerTreeView()
# should not work # should not work
@ -78,9 +80,10 @@ class TestQgsLayerTreeView(unittest.TestCase):
# should work # should work
view.setModel(self.model) view.setModel(self.model)
self.assertEqual(view.model(), self.model) self.assertEqual(view.layerTreeModel(), self.model)
def testSetCurrentLayer(self): def testSetCurrentLayer(self):
view = QgsLayerTreeView() view = QgsLayerTreeView()
view.setModel(self.model) view.setModel(self.model)
current_layer_changed_spy = QSignalSpy(view.currentLayerChanged) current_layer_changed_spy = QSignalSpy(view.currentLayerChanged)
@ -111,6 +114,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveOutOfGroupActionLayer(self): def testMoveOutOfGroupActionLayer(self):
"""Test move out of group action on layer""" """Test move out of group action on layer"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().addGroup("embeddedgroup") group = self.project.layerTreeRoot().addGroup("embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -141,6 +145,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToTopActionLayer(self): def testMoveToTopActionLayer(self):
"""Test move to top action on layer""" """Test move to top action on layer"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
view.setModel(self.model) view.setModel(self.model)
actions = QgsLayerTreeViewDefaultActions(view) actions = QgsLayerTreeViewDefaultActions(view)
@ -152,6 +157,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToTopActionGroup(self): def testMoveToTopActionGroup(self):
"""Test move to top action on group""" """Test move to top action on group"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().addGroup("embeddedgroup") group = self.project.layerTreeRoot().addGroup("embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -168,7 +174,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
groupname + '-' + self.layer5.name(), groupname + '-' + self.layer5.name(),
]) ])
nodeLayerIndex = self.model.node2index(group) nodeLayerIndex = view.node2index(group)
view.setCurrentIndex(nodeLayerIndex) view.setCurrentIndex(nodeLayerIndex)
movetotop = actions.actionMoveToTop() movetotop = actions.actionMoveToTop()
movetotop.trigger() movetotop.trigger()
@ -183,6 +189,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToTopActionEmbeddedGroup(self): def testMoveToTopActionEmbeddedGroup(self):
"""Test move to top action on embeddedgroup layer""" """Test move to top action on embeddedgroup layer"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().addGroup("embeddedgroup") group = self.project.layerTreeRoot().addGroup("embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -213,6 +220,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToTopActionLayerAndGroup(self): def testMoveToTopActionLayerAndGroup(self):
"""Test move to top action for a group and it's layer simultaneously""" """Test move to top action for a group and it's layer simultaneously"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().addGroup("embeddedgroup") group = self.project.layerTreeRoot().addGroup("embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -231,7 +239,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
selectionMode = view.selectionMode() selectionMode = view.selectionMode()
view.setSelectionMode(QgsLayerTreeView.MultiSelection) view.setSelectionMode(QgsLayerTreeView.MultiSelection)
nodeLayerIndex = self.model.node2index(group) nodeLayerIndex = view.node2index(group)
view.setCurrentIndex(nodeLayerIndex) view.setCurrentIndex(nodeLayerIndex)
view.setCurrentLayer(self.layer5) view.setCurrentLayer(self.layer5)
view.setSelectionMode(selectionMode) view.setSelectionMode(selectionMode)
@ -248,6 +256,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToBottomActionLayer(self): def testMoveToBottomActionLayer(self):
"""Test move to bottom action on layer""" """Test move to bottom action on layer"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
view.setModel(self.model) view.setModel(self.model)
actions = QgsLayerTreeViewDefaultActions(view) actions = QgsLayerTreeViewDefaultActions(view)
@ -259,6 +268,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToBottomActionGroup(self): def testMoveToBottomActionGroup(self):
"""Test move to bottom action on group""" """Test move to bottom action on group"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup") group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -275,7 +285,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
self.layer3.name(), self.layer3.name(),
]) ])
nodeLayerIndex = self.model.node2index(group) nodeLayerIndex = view.node2index(group)
view.setCurrentIndex(nodeLayerIndex) view.setCurrentIndex(nodeLayerIndex)
movetobottom = actions.actionMoveToBottom() movetobottom = actions.actionMoveToBottom()
movetobottom.trigger() movetobottom.trigger()
@ -290,6 +300,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToBottomActionEmbeddedGroup(self): def testMoveToBottomActionEmbeddedGroup(self):
"""Test move to bottom action on embeddedgroup layer""" """Test move to bottom action on embeddedgroup layer"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().addGroup("embeddedgroup") group = self.project.layerTreeRoot().addGroup("embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -320,6 +331,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
def testMoveToBottomActionLayerAndGroup(self): def testMoveToBottomActionLayerAndGroup(self):
"""Test move to top action for a group and it's layer simultaneously""" """Test move to top action for a group and it's layer simultaneously"""
view = QgsLayerTreeView() view = QgsLayerTreeView()
group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup") group = self.project.layerTreeRoot().insertGroup(0, "embeddedgroup")
group.addLayer(self.layer4) group.addLayer(self.layer4)
@ -338,7 +350,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
selectionMode = view.selectionMode() selectionMode = view.selectionMode()
view.setSelectionMode(QgsLayerTreeView.MultiSelection) view.setSelectionMode(QgsLayerTreeView.MultiSelection)
nodeLayerIndex = self.model.node2index(group) nodeLayerIndex = view.node2index(group)
view.setCurrentIndex(nodeLayerIndex) view.setCurrentIndex(nodeLayerIndex)
view.setCurrentLayer(self.layer4) view.setCurrentLayer(self.layer4)
view.setSelectionMode(selectionMode) view.setSelectionMode(selectionMode)
@ -354,6 +366,7 @@ class TestQgsLayerTreeView(unittest.TestCase):
]) ])
def testSetLayerVisible(self): def testSetLayerVisible(self):
view = QgsLayerTreeView() view = QgsLayerTreeView()
view.setModel(self.model) view.setModel(self.model)
self.project.layerTreeRoot().findLayer(self.layer).setItemVisibilityChecked(True) self.project.layerTreeRoot().findLayer(self.layer).setItemVisibilityChecked(True)