QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
|
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with 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. | |
void | refreshLayerSymbology (const QString &layerId) |
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model. | |
void | setHideValidLayers (bool hideValid) |
Sets whether valid layers should be hidden (i.e. | |
void | setLayerMarkWidth (int width) |
Set width of contextual menu mark, at right of layer node items. | |
void | setMessageBar (QgsMessageBar *messageBar) |
Set the message bar to display messages from the layer tree. | |
void | setShowPrivateLayers (bool showPrivate) |
Set the show private layers to showPrivate. | |
Signals | |
void | contextMenuAboutToShow (QMenu *menu) |
Emitted when the context menu is about to show. | |
void | currentLayerChanged (QgsMapLayer *layer) |
Emitted when a current layer is changed. | |
void | datasetsDropped (QDropEvent *event) |
Emitted when datasets are dropped onto the layer tree view. | |
Public Member Functions | |
QgsLayerTreeView (QWidget *parent=nullptr) | |
Constructor for QgsLayerTreeView. | |
~QgsLayerTreeView () override | |
void | addIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator) |
Adds an indicator to the given layer tree node. | |
QgsLayerTreeGroup * | currentGroupNode () const |
Gets current group node. If a layer is current node, the function will return parent group. May be nullptr . | |
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 |
Gets current node. May be nullptr . | |
QgsLayerTreeViewDefaultActions * | defaultActions () |
Gets access to the default actions that may be used with the tree view. | |
bool | hideValidLayers () const |
Returns if valid layers should be hidden (i.e. | |
QgsLayerTreeModelLegendNode * | index2legendNode (const QModelIndex &index) const |
Returns legend node for given proxy model tree index. | |
QgsLayerTreeNode * | index2node (const QModelIndex &index) const |
Returns layer tree node for given proxy model tree index. | |
QList< QgsLayerTreeViewIndicator * > | indicators (QgsLayerTreeNode *node) const |
Returns list of indicators associated with a particular layer tree node. | |
int | layerMarkWidth () const |
Returns width of contextual menu mark, at right of layer node items. | |
QgsLayerTreeModel * | layerTreeModel () const |
Gets access to the model casted to QgsLayerTreeModel. | |
QModelIndex | legendNode2index (QgsLayerTreeModelLegendNode *legendNode) |
Returns proxy model index for a given legend node. | |
QModelIndex | legendNode2sourceIndex (QgsLayerTreeModelLegendNode *legendNode) |
Returns index for a given legend node. | |
QgsLayerTreeViewMenuProvider * | menuProvider () const |
Returns pointer to the context menu provider. May be nullptr . | |
QModelIndex | node2index (QgsLayerTreeNode *node) const |
Returns proxy model index for a given node. | |
QModelIndex | node2sourceIndex (QgsLayerTreeNode *node) const |
Returns source model index for a given node. | |
QgsLayerTreeProxyModel * | proxyModel () const |
Returns the proxy model used by the view. | |
void | removeIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator) |
Removes a previously added indicator to a layer tree 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 | setLayerVisible (QgsMapLayer *layer, bool visible) |
Convenience methods which sets the visible state of the specified map layer. | |
void | setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider) |
Sets provider for context menu. Takes ownership of the instance. | |
void | setModel (QAbstractItemModel *model) override |
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model. | |
bool | showPrivateLayers () const |
Returns the show private layers status. | |
Protected Slots | |
void | modelRowsInserted (const QModelIndex &index, int start, int end) |
void | modelRowsRemoved () |
void | onCurrentChanged () |
void | onExpandedChanged (QgsLayerTreeNode *node, bool expanded) |
void | onModelReset () |
void | updateExpandedStateToNode (const QModelIndex &index) |
Protected Member Functions | |
void | contextMenuEvent (QContextMenuEvent *event) override |
void | dragEnterEvent (QDragEnterEvent *event) override |
void | dragMoveEvent (QDragMoveEvent *event) override |
void | dropEvent (QDropEvent *event) override |
void | keyPressEvent (QKeyEvent *event) override |
QgsMapLayer * | layerForIndex (const QModelIndex &index) const |
void | mouseDoubleClickEvent (QMouseEvent *event) override |
void | mouseReleaseEvent (QMouseEvent *event) override |
void | resizeEvent (QResizeEvent *event) override |
void | updateExpandedStateFromNode (QgsLayerTreeNode *node) |
Protected Attributes | |
QString | mCurrentLayerID |
Keeps track of current layer ID (to check when to emit signal about change of current layer) | |
QgsLayerTreeViewDefaultActions * | mDefaultActions = nullptr |
helper class with default actions. Lazily initialized. | |
QHash< QgsLayerTreeNode *, QList< QgsLayerTreeViewIndicator * > > | mIndicators |
Storage of indicators used with the tree view. | |
QPoint | mLastReleaseMousePos |
Used by the item delegate for identification of which indicator has been clicked. | |
int | mLayerMarkWidth |
Width of contextual menu mark for layer nodes. | |
QgsLayerTreeViewMenuProvider * | mMenuProvider = nullptr |
Context menu provider. Owned by the view. | |
Friends | |
class | QgsLayerTreeViewItemDelegate |
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with a layer tree.
The view updates expanded state of layer tree nodes and also listens to changes to expanded states in the layer tree.
The view keeps track of the current layer and emits a signal when the current layer has changed.
Allows the client to specify a context menu provider with custom actions. Also it comes with a set of default actions that can be used when building context menu.
Definition at line 119 of file qgslayertreeview.h.
|
explicit |
Constructor for QgsLayerTreeView.
Definition at line 44 of file qgslayertreeview.cpp.
|
override |
Definition at line 81 of file qgslayertreeview.cpp.
void QgsLayerTreeView::addIndicator | ( | QgsLayerTreeNode * | node, |
QgsLayerTreeViewIndicator * | indicator | ||
) |
Adds an indicator to the given layer tree node.
Indicators are icons shown next to layer/group names in the layer tree view. They can be used to show extra information with tree nodes and they allow user interaction.
Does not take ownership of the indicator. One indicator object may be used for multiple layer tree nodes.
Definition at line 505 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes.
Definition at line 586 of file qgslayertreeview.cpp.
|
signal |
Emitted when the context menu is about to show.
Allows customization of the menu.
|
overrideprotected |
Definition at line 190 of file qgslayertreeview.cpp.
QgsLayerTreeGroup * QgsLayerTreeView::currentGroupNode | ( | ) | const |
Gets current group node. If a layer is current node, the function will return parent group. May be nullptr
.
Definition at line 411 of file qgslayertreeview.cpp.
QgsMapLayer * QgsLayerTreeView::currentLayer | ( | ) | const |
Returns the currently selected layer, or nullptr
if no layers is selected.
Definition at line 149 of file qgslayertreeview.cpp.
|
signal |
Emitted when a current layer is changed.
QgsLayerTreeModelLegendNode * QgsLayerTreeView::currentLegendNode | ( | ) | const |
Gets current legend node.
May be nullptr
if current node is not a legend node.
Definition at line 433 of file qgslayertreeview.cpp.
QgsLayerTreeNode * QgsLayerTreeView::currentNode | ( | ) | const |
Gets current node. May be nullptr
.
Definition at line 406 of file qgslayertreeview.cpp.
|
signal |
Emitted when datasets are dropped onto the layer tree view.
QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions | ( | ) |
Gets access to the default actions that may be used with the tree view.
Definition at line 136 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 683 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 697 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 711 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes.
Definition at line 579 of file qgslayertreeview.cpp.
bool QgsLayerTreeView::hideValidLayers | ( | ) | const |
Returns if valid layers should be hidden (i.e.
only invalid layers are shown).
Definition at line 627 of file qgslayertreeview.cpp.
QgsLayerTreeModelLegendNode * QgsLayerTreeView::index2legendNode | ( | const QModelIndex & | index | ) | const |
Returns legend node for given proxy model tree 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 821 of file qgslayertreeview.cpp.
QgsLayerTreeNode * QgsLayerTreeView::index2node | ( | const QModelIndex & | index | ) | const |
Returns layer tree node for given proxy model tree index.
Returns root node for invalid index. Returns nullptr
if index does not refer to a layer tree node (e.g. it is a legend node)
Unlike QgsLayerTreeModel::index2Node(), calling this method correctly accounts for mapping the view indexes through the view's proxy model to the source model.
Definition at line 806 of file qgslayertreeview.cpp.
QList< QgsLayerTreeViewIndicator * > QgsLayerTreeView::indicators | ( | QgsLayerTreeNode * | node | ) | const |
Returns list of indicators associated with a particular layer tree node.
Definition at line 526 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 655 of file qgslayertreeview.cpp.
|
protected |
Definition at line 384 of file qgslayertreeview.cpp.
|
inline |
Returns width of contextual menu mark, at right of layer node items.
Definition at line 345 of file qgslayertreeview.h.
QgsLayerTreeModel * QgsLayerTreeView::layerTreeModel | ( | ) | const |
Gets access to the model casted to QgsLayerTreeModel.
Definition at line 131 of file qgslayertreeview.cpp.
QModelIndex QgsLayerTreeView::legendNode2index | ( | QgsLayerTreeModelLegendNode * | legendNode | ) |
Returns proxy 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 is belongs to the tree but it is filtered out, 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 826 of file qgslayertreeview.cpp.
QModelIndex QgsLayerTreeView::legendNode2sourceIndex | ( | QgsLayerTreeModelLegendNode * | legendNode | ) |
Returns 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 is belongs to the tree but it is filtered out, invalid model index is returned.
Definition at line 831 of file qgslayertreeview.cpp.
|
inline |
Returns pointer to the context menu provider. May be nullptr
.
Definition at line 219 of file qgslayertreeview.h.
|
protectedslot |
Definition at line 211 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 282 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 632 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 640 of file qgslayertreeview.cpp.
QModelIndex QgsLayerTreeView::node2index | ( | QgsLayerTreeNode * | node | ) | const |
Returns proxy 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 811 of file qgslayertreeview.cpp.
QModelIndex QgsLayerTreeView::node2sourceIndex | ( | QgsLayerTreeNode * | node | ) | const |
Returns source model index for a given node.
If the node does not belong to the layer tree, the result is undefined
Definition at line 816 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 313 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 345 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 368 of file qgslayertreeview.cpp.
QgsLayerTreeProxyModel * QgsLayerTreeView::proxyModel | ( | ) | const |
Returns the proxy model used by the view.
This can be used to set filters controlling which layers are shown in the view.
Definition at line 801 of file qgslayertreeview.cpp.
|
slot |
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model.
Definition at line 538 of file qgslayertreeview.cpp.
void QgsLayerTreeView::removeIndicator | ( | QgsLayerTreeNode * | node, |
QgsLayerTreeViewIndicator * | indicator | ||
) |
Removes a previously added indicator to a layer tree node.
Does not delete the indicator.
Definition at line 520 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 737 of file qgslayertreeview.cpp.
QList< QgsLayerTreeLayer * > QgsLayerTreeView::selectedLayerNodes | ( | ) | const |
Returns the list of selected nodes filtered to just layer nodes (QgsLayerTreeLayer).
Definition at line 449 of file qgslayertreeview.cpp.
QList< QgsMapLayer * > QgsLayerTreeView::selectedLayers | ( | ) | const |
Returns the list of selected layers.
Definition at line 462 of file qgslayertreeview.cpp.
QList< QgsMapLayer * > QgsLayerTreeView::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 492 of file qgslayertreeview.cpp.
QList< QgsLayerTreeModelLegendNode * > QgsLayerTreeView::selectedLegendNodes | ( | ) | const |
Returns the list of selected legend nodes.
Definition at line 475 of file qgslayertreeview.cpp.
QList< QgsLayerTreeNode * > QgsLayerTreeView::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 438 of file qgslayertreeview.cpp.
void QgsLayerTreeView::setCurrentLayer | ( | QgsMapLayer * | layer | ) |
Sets the currently selected layer.
If layer is nullptr
then all layers will be deselected.
Definition at line 165 of file qgslayertreeview.cpp.
void QgsLayerTreeView::setCurrentNode | ( | QgsLayerTreeNode * | node | ) |
Sets the currently selected node.
If node is nullptr
then all nodes will be deselected.
Definition at line 154 of file qgslayertreeview.cpp.
|
slot |
Sets whether valid layers should be hidden (i.e.
only invalid layers are shown).
Definition at line 616 of file qgslayertreeview.cpp.
|
inlineslot |
Set width of contextual menu mark, at right of layer node items.
Definition at line 395 of file qgslayertreeview.h.
void QgsLayerTreeView::setLayerVisible | ( | QgsMapLayer * | layer, |
bool | visible | ||
) |
Convenience methods which sets the visible state of the specified map layer.
Definition at line 180 of file qgslayertreeview.cpp.
void QgsLayerTreeView::setMenuProvider | ( | QgsLayerTreeViewMenuProvider * | menuProvider | ) |
Sets provider for context menu. Takes ownership of the instance.
Definition at line 143 of file qgslayertreeview.cpp.
|
slot |
Set the message bar to display messages from the layer tree.
Definition at line 593 of file qgslayertreeview.cpp.
|
override |
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
Definition at line 87 of file qgslayertreeview.cpp.
|
slot |
Set the show private layers to showPrivate.
Definition at line 610 of file qgslayertreeview.cpp.
bool QgsLayerTreeView::showPrivateLayers | ( | ) | const |
Returns the show private layers status.
Definition at line 622 of file qgslayertreeview.cpp.
|
protected |
Definition at line 374 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 288 of file qgslayertreeview.cpp.
|
friend |
Definition at line 496 of file qgslayertreeview.h.
|
protected |
Keeps track of current layer ID (to check when to emit signal about change of current layer)
Definition at line 474 of file qgslayertreeview.h.
|
protected |
helper class with default actions. Lazily initialized.
Definition at line 470 of file qgslayertreeview.h.
|
protected |
Storage of indicators used with the tree view.
Definition at line 476 of file qgslayertreeview.h.
|
protected |
Used by the item delegate for identification of which indicator has been clicked.
Definition at line 478 of file qgslayertreeview.h.
|
protected |
Width of contextual menu mark for layer nodes.
Definition at line 481 of file qgslayertreeview.h.
|
protected |
Context menu provider. Owned by the view.
Definition at line 472 of file qgslayertreeview.h.