|
QGIS API Documentation 3.99.0-Master (26c88405ac0)
|
Base class for QTreeView widgets which display a layer tree. More...
#include <qgslayertreeview.h>

Public Slots | |
| void | collapseAllNodes () |
| Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes. | |
| void | expandAllNodes () |
| Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes. | |
Public Member Functions | |
| QgsLayerTreeViewBase (QWidget *parent=nullptr) | |
| Constructor for QgsLayerTreeViewBase. | |
| ~QgsLayerTreeViewBase () override | |
| QgsLayerTreeGroup * | currentGroupNode () const |
| Returns the current group node. | |
| QgsMapLayer * | currentLayer () const |
Returns the currently selected layer, or nullptr if no layers is selected. | |
| QgsLayerTreeModelLegendNode * | currentLegendNode () const |
| Gets current legend node. | |
| QgsLayerTreeNode * | currentNode () const |
| Returns the current node. | |
| QgsLayerTreeViewDefaultActions * | defaultActions () |
| Gets access to the default actions that may be used with the tree view. | |
| QgsLayerTreeModelLegendNode * | index2legendNode (const QModelIndex &index) const |
| Returns legend node for given view index. | |
| QgsLayerTreeNode * | index2node (const QModelIndex &index) const |
| Returns the layer tree node for given view index. | |
| QgsMapLayer * | layerForIndex (const QModelIndex &index) const |
| Returns the map layer corresponding to a view index. | |
| QgsLayerTreeModel * | layerTreeModel () const |
| Returns the associated layer tree model. | |
| QModelIndex | legendNode2index (QgsLayerTreeModelLegendNode *legendNode) |
| Returns the view index for a given legend node. | |
| QModelIndex | legendNode2sourceIndex (QgsLayerTreeModelLegendNode *legendNode) |
| Returns the layer tree source model index for a given legend node. | |
| void | mouseDoubleClickEvent (QMouseEvent *event) override |
| QModelIndex | node2index (QgsLayerTreeNode *node) const |
| Returns the view model index for a given node. | |
| QModelIndex | node2sourceIndex (QgsLayerTreeNode *node) const |
| Returns the layer tree source model index for a given node. | |
| QList< QgsLayerTreeLayer * > | selectedLayerNodes () const |
| Returns the list of selected nodes filtered to just layer nodes (QgsLayerTreeLayer). | |
| QList< QgsMapLayer * > | selectedLayers () const |
| Returns the list of selected layers. | |
| QList< QgsMapLayer * > | selectedLayersRecursive () const |
| Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected. | |
| QList< QgsLayerTreeModelLegendNode * > | selectedLegendNodes () const |
| Returns the list of selected legend nodes. | |
| QList< QgsLayerTreeNode * > | selectedNodes (bool skipInternal=false) const |
| Returns the list of selected layer tree nodes. | |
| void | setCurrentLayer (QgsMapLayer *layer) |
| Sets the currently selected layer. | |
| void | setCurrentNode (QgsLayerTreeNode *node) |
| Sets the currently selected node. | |
| void | setLayerTreeModel (QgsLayerTreeModel *model) |
| Associates a layer tree model with the view. | |
Protected Slots | |
| void | onExpandedChanged (QgsLayerTreeNode *node, bool expanded) |
| Called when the expanded state changes for a node. | |
| void | onModelReset () |
| Called when the model is reset. | |
| void | updateExpandedStateToNode (const QModelIndex &index) |
| Stores the expanded state to a node with matching index. | |
Protected Member Functions | |
| QModelIndex | layerTreeModelIndexToViewIndex (const QModelIndex &index) const |
| Returns the layer tree model index corresponding with a view index. | |
| void | updateExpandedStateFromNode (QgsLayerTreeNode *node) |
| Updates the expanded state from a node. | |
| QModelIndex | viewIndexToLayerTreeModelIndex (const QModelIndex &index) const |
| Returns the view index corresponding with a layer tree model index. | |
Protected Attributes | |
| QgsLayerTreeViewDefaultActions * | mDefaultActions = nullptr |
| helper class with default actions. Lazily initialized. | |
Base class for QTreeView widgets which display a layer tree.
The view updates expanded state of layer tree nodes and also listens to changes to expanded states in the layer tree.
Definition at line 130 of file qgslayertreeview.h.
|
explicit |
Constructor for QgsLayerTreeViewBase.
Definition at line 45 of file qgslayertreeview.cpp.
|
override |
Definition at line 74 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes.
Definition at line 445 of file qgslayertreeview.cpp.
| QgsLayerTreeGroup * QgsLayerTreeViewBase::currentGroupNode | ( | ) | const |
Returns the current group node.
If a layer is the current node, the function will return the layer's parent group.
May be nullptr.
Definition at line 267 of file qgslayertreeview.cpp.
| QgsMapLayer * QgsLayerTreeViewBase::currentLayer | ( | ) | const |
Returns the currently selected layer, or nullptr if no layers is selected.
Definition at line 241 of file qgslayertreeview.cpp.
| QgsLayerTreeModelLegendNode * QgsLayerTreeViewBase::currentLegendNode | ( | ) | const |
Gets current legend node.
May be nullptr if current node is not a legend node.
Definition at line 356 of file qgslayertreeview.cpp.
| QgsLayerTreeNode * QgsLayerTreeViewBase::currentNode | ( | ) | const |
| QgsLayerTreeViewDefaultActions * QgsLayerTreeViewBase::defaultActions | ( | ) |
Gets access to the default actions that may be used with the tree view.
Definition at line 455 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes.
Definition at line 435 of file qgslayertreeview.cpp.
| QgsLayerTreeModelLegendNode * QgsLayerTreeViewBase::index2legendNode | ( | const QModelIndex & | index | ) | const |
Returns legend node for given view index.
Returns nullptr for invalid index.
Unlike QgsLayerTreeModel::index2legendNode(), calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model.
Definition at line 210 of file qgslayertreeview.cpp.
| QgsLayerTreeNode * QgsLayerTreeViewBase::index2node | ( | const QModelIndex & | index | ) | const |
Returns the layer tree node for given view index.
Returns root node for an invalid index.
Returns nullptr if index does not refer to a layer tree node (e.g. it is a legend node).
Unlike QgsLayerTreeViewBase::index2Node(), calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model.
Definition at line 189 of file qgslayertreeview.cpp.
| QgsMapLayer * QgsLayerTreeViewBase::layerForIndex | ( | const QModelIndex & | index | ) | const |
Returns the map layer corresponding to a view index.
This method correctly accounts for proxy models set on the tree view.
Returns nullptr if the index does not correspond to a map layer.
Definition at line 246 of file qgslayertreeview.cpp.
| QgsLayerTreeModel * QgsLayerTreeViewBase::layerTreeModel | ( | ) | const |
Returns the associated layer tree model.
Definition at line 101 of file qgslayertreeview.cpp.
|
protected |
Returns the layer tree model index corresponding with a view index.
This method correctly accounts for proxy models set on the tree view.
Definition at line 130 of file qgslayertreeview.cpp.
| QModelIndex QgsLayerTreeViewBase::legendNode2index | ( | QgsLayerTreeModelLegendNode * | legendNode | ) |
Returns the view index for a given legend node.
If the legend node does not belong to the layer tree, the result is undefined.
If the legend node belongs to the tree but it is filtered out, an invalid model index is returned.
Unlike QgsLayerTreeModel::legendNode2index(), calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model.
Definition at line 318 of file qgslayertreeview.cpp.
| QModelIndex QgsLayerTreeViewBase::legendNode2sourceIndex | ( | QgsLayerTreeModelLegendNode * | legendNode | ) |
Returns the layer tree source model index for a given legend node.
If the legend node does not belong to the layer tree, the result is undefined.
If the legend node belongs to the tree but it is filtered out, an invalid model index is returned.
Definition at line 323 of file qgslayertreeview.cpp.
|
override |
Definition at line 79 of file qgslayertreeview.cpp.
| QModelIndex QgsLayerTreeViewBase::node2index | ( | QgsLayerTreeNode * | node | ) | const |
Returns the view model index for a given node.
If the node does not belong to the layer tree, the result is undefined.
Unlike QgsLayerTreeModel::node2index(), calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model.
Definition at line 197 of file qgslayertreeview.cpp.
| QModelIndex QgsLayerTreeViewBase::node2sourceIndex | ( | QgsLayerTreeNode * | node | ) | const |
Returns the layer tree source model index for a given node.
If the node does not belong to the layer tree, the result is undefined.
Definition at line 202 of file qgslayertreeview.cpp.
|
protectedslot |
Called when the expanded state changes for a node.
Definition at line 169 of file qgslayertreeview.cpp.
|
protectedslot |
Called when the model is reset.
Definition at line 176 of file qgslayertreeview.cpp.
| QList< QgsLayerTreeLayer * > QgsLayerTreeViewBase::selectedLayerNodes | ( | ) | const |
Returns the list of selected nodes filtered to just layer nodes (QgsLayerTreeLayer).
Definition at line 292 of file qgslayertreeview.cpp.
| QList< QgsMapLayer * > QgsLayerTreeViewBase::selectedLayers | ( | ) | const |
Returns the list of selected layers.
Definition at line 305 of file qgslayertreeview.cpp.
| QList< QgsMapLayer * > QgsLayerTreeViewBase::selectedLayersRecursive | ( | ) | const |
Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected.
If we have a group with two layers L1, L2 and just the group node is selected, this method returns L1 and L2, while selectedLayers() returns an empty list.
Definition at line 385 of file qgslayertreeview.cpp.
| QList< QgsLayerTreeModelLegendNode * > QgsLayerTreeViewBase::selectedLegendNodes | ( | ) | const |
Returns the list of selected legend nodes.
Definition at line 364 of file qgslayertreeview.cpp.
| QList< QgsLayerTreeNode * > QgsLayerTreeViewBase::selectedNodes | ( | bool | skipInternal = false | ) | const |
Returns the list of selected layer tree nodes.
| skipInternal | If true, will ignore nodes which have an ancestor in the selection |
Definition at line 223 of file qgslayertreeview.cpp.
| void QgsLayerTreeViewBase::setCurrentLayer | ( | QgsMapLayer * | layer | ) |
Sets the currently selected layer.
If layer is nullptr then all layers will be deselected.
Definition at line 341 of file qgslayertreeview.cpp.
| void QgsLayerTreeViewBase::setCurrentNode | ( | QgsLayerTreeNode * | node | ) |
Sets the currently selected node.
If node is nullptr then all nodes will be deselected.
Definition at line 330 of file qgslayertreeview.cpp.
| void QgsLayerTreeViewBase::setLayerTreeModel | ( | QgsLayerTreeModel * | model | ) |
Associates a layer tree model with the view.
Definition at line 87 of file qgslayertreeview.cpp.
|
protected |
Updates the expanded state from a node.
Definition at line 106 of file qgslayertreeview.cpp.
|
protectedslot |
Stores the expanded state to a node with matching index.
Definition at line 144 of file qgslayertreeview.cpp.
|
protected |
Returns the view index corresponding with a layer tree model index.
This method correctly accounts for proxy models set on the tree view.
Definition at line 116 of file qgslayertreeview.cpp.
|
protected |
helper class with default actions. Lazily initialized.
Definition at line 385 of file qgslayertreeview.h.