def testDefaultActions(self): view = QgsLayerTreeView() view.setModel(self.model) actions = QgsLayerTreeViewDefaultActions(view) # show in overview action view.setCurrentLayer(self.layer) self.assertEqual(view.currentNode().customProperty('overview', 0), False) show_in_overview = actions.actionShowInOverview() show_in_overview.trigger() self.assertEqual(view.currentNode().customProperty('overview', 0), True) show_in_overview.trigger() self.assertEqual(view.currentNode().customProperty('overview', 0), False)
def layerTreeInsertionPoint(tree_view: QgsLayerTreeView) -> tuple: """ Direct copy of the code QgisApp::layerTreeInsertionPoint for QGIS < 3.10 """ insert_group = tree_view.layerTreeModel().rootGroup() current = tree_view.currentIndex() index = 0 if current.isValid(): index = current.row() current_node = tree_view.currentNode() if current_node: # if the insertion point is actually a group, insert new layers into the group if QgsLayerTree.isGroup(current_node): # if the group is embedded go to the first non-embedded group, at worst the top level item insert_group = firstGroupWithoutCustomProperty( current_node, "embedded") return InsertionPoint(insert_group, 0) # otherwise just set the insertion point in front of the current node parent_node = current_node.parent() if QgsLayerTree.isGroup(parent_node): # if the group is embedded go to the first non-embedded group, at worst the top level item insert_group = firstGroupWithoutCustomProperty( parent_node, "embedded") if parent_node != insert_group: index = 0 return InsertionPoint(insert_group, index)
def testDefaultActions(self): view = QgsLayerTreeView() view.setModel(self.model) if USE_MODEL_TESTER: proxy_tester = QAbstractItemModelTester(view.model()) actions = QgsLayerTreeViewDefaultActions(view) # show in overview action view.setCurrentLayer(self.layer) self.assertEqual(view.currentNode().customProperty('overview', 0), False) show_in_overview = actions.actionShowInOverview() show_in_overview.trigger() self.assertEqual(view.currentNode().customProperty('overview', 0), True) show_in_overview.trigger() self.assertEqual(view.currentNode().customProperty('overview', 0), False)