QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Friends | List of all members
QgsLayerTreeView Class Reference

The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with a layer tree. More...

#include <qgslayertreeview.h>

Inheritance diagram for QgsLayerTreeView:
Inheritance graph
[legend]

Public Slots

void collapseAllNodes ()
 Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes. More...
 
void expandAllNodes ()
 Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes. More...
 
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. More...
 

Signals

void currentLayerChanged (QgsMapLayer *layer)
 Emitted when a current layer is changed. More...
 

Public Member Functions

 QgsLayerTreeView (QWidget *parent=nullptr)
 Constructor for QgsLayerTreeView. More...
 
 ~QgsLayerTreeView () override
 
void addIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator)
 Adds an indicator to the given layer tree node. More...
 
QgsLayerTreeGroupcurrentGroupNode () const
 Gets current group node. If a layer is current node, the function will return parent group. May be null. More...
 
QgsMapLayercurrentLayer () const
 Gets currently selected layer. May be null. More...
 
QgsLayerTreeModelLegendNodecurrentLegendNode () const
 Gets current legend node. More...
 
QgsLayerTreeNodecurrentNode () const
 Gets current node. May be null. More...
 
QgsLayerTreeViewDefaultActionsdefaultActions ()
 Gets access to the default actions that may be used with the tree view. More...
 
QList< QgsLayerTreeViewIndicator * > indicators (QgsLayerTreeNode *node) const
 Returns list of indicators associated with a particular layer tree node. More...
 
QgsLayerTreeModellayerTreeModel () const
 Gets access to the model casted to QgsLayerTreeModel. More...
 
QgsLayerTreeViewMenuProvidermenuProvider () const
 Returns pointer to the context menu provider. May be null. More...
 
void removeIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator)
 Removes a previously added indicator to a layer tree node. More...
 
QList< QgsLayerTreeLayer * > selectedLayerNodes () const
 Returns list of selected nodes filtered to just layer nodes. More...
 
QList< QgsMapLayer * > selectedLayers () const
 Gets list of selected layers. More...
 
QList< QgsMapLayer * > selectedLayersRecursive () const
 Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected. More...
 
QList< QgsLayerTreeNode * > selectedNodes (bool skipInternal=false) const
 Returns list of selected nodes. More...
 
void setCurrentLayer (QgsMapLayer *layer)
 Sets currently selected layer. Null pointer will deselect any layer. More...
 
void setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider)
 Sets provider for context menu. Takes ownership of the instance. More...
 
void setModel (QAbstractItemModel *model) override
 Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model. More...
 

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 dropEvent (QDropEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
QgsMapLayerlayerForIndex (const QModelIndex &index) const
 
void mouseReleaseEvent (QMouseEvent *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) More...
 
QgsLayerTreeViewDefaultActionsmDefaultActions = nullptr
 helper class with default actions. Lazily initialized. More...
 
QHash< QgsLayerTreeNode *, QList< QgsLayerTreeViewIndicator * > > mIndicators
 Storage of indicators used with the tree view. More...
 
QPoint mLastReleaseMousePos
 Used by the item delegate for identification of which indicator has been clicked. More...
 
QgsLayerTreeViewMenuProvidermMenuProvider = nullptr
 Context menu provider. Owned by the view. More...
 

Friends

class QgsLayerTreeViewItemDelegate
 

Detailed Description

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.

See also
QgsLayerTreeModel
Since
QGIS 2.4

Definition at line 49 of file qgslayertreeview.h.

Constructor & Destructor Documentation

QgsLayerTreeView::QgsLayerTreeView ( QWidget *  parent = nullptr)
explicit

Constructor for QgsLayerTreeView.

Definition at line 34 of file qgslayertreeview.cpp.

QgsLayerTreeView::~QgsLayerTreeView ( )
override

Definition at line 60 of file qgslayertreeview.cpp.

Member Function Documentation

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.

See also
removeIndicator
indicators
Since
QGIS 3.2

Definition at line 370 of file qgslayertreeview.cpp.

void QgsLayerTreeView::collapseAllNodes ( )
slot

Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes.

Since
QGIS 2.18

Definition at line 439 of file qgslayertreeview.cpp.

void QgsLayerTreeView::contextMenuEvent ( QContextMenuEvent *  event)
overrideprotected

Definition at line 124 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 null.

Definition at line 309 of file qgslayertreeview.cpp.

QgsMapLayer * QgsLayerTreeView::currentLayer ( ) const

Gets currently selected layer. May be null.

Definition at line 103 of file qgslayertreeview.cpp.

void QgsLayerTreeView::currentLayerChanged ( QgsMapLayer layer)
signal

Emitted when a current layer is changed.

QgsLayerTreeModelLegendNode * QgsLayerTreeView::currentLegendNode ( ) const

Gets current legend node.

May be null if current node is not a legend node.

Since
QGIS 2.14

Definition at line 331 of file qgslayertreeview.cpp.

QgsLayerTreeNode * QgsLayerTreeView::currentNode ( ) const

Gets current node. May be null.

Definition at line 304 of file qgslayertreeview.cpp.

QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions ( )

Gets access to the default actions that may be used with the tree view.

Definition at line 90 of file qgslayertreeview.cpp.

void QgsLayerTreeView::dropEvent ( QDropEvent *  event)
overrideprotected

Definition at line 472 of file qgslayertreeview.cpp.

void QgsLayerTreeView::expandAllNodes ( )
slot

Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes.

Since
QGIS 2.18

Definition at line 432 of file qgslayertreeview.cpp.

QList< QgsLayerTreeViewIndicator * > QgsLayerTreeView::indicators ( QgsLayerTreeNode node) const

Returns list of indicators associated with a particular layer tree node.

See also
addIndicator
removeIndicator
Since
QGIS 3.2

Definition at line 381 of file qgslayertreeview.cpp.

void QgsLayerTreeView::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 461 of file qgslayertreeview.cpp.

QgsMapLayer * QgsLayerTreeView::layerForIndex ( const QModelIndex &  index) const
protected

Definition at line 282 of file qgslayertreeview.cpp.

QgsLayerTreeModel * QgsLayerTreeView::layerTreeModel ( ) const

Gets access to the model casted to QgsLayerTreeModel.

Definition at line 85 of file qgslayertreeview.cpp.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::menuProvider ( ) const
inline

Returns pointer to the context menu provider. May be null.

Definition at line 81 of file qgslayertreeview.h.

void QgsLayerTreeView::modelRowsInserted ( const QModelIndex &  index,
int  start,
int  end 
)
protectedslot

Definition at line 140 of file qgslayertreeview.cpp.

void QgsLayerTreeView::modelRowsRemoved ( )
protectedslot

Definition at line 193 of file qgslayertreeview.cpp.

void QgsLayerTreeView::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 446 of file qgslayertreeview.cpp.

void QgsLayerTreeView::onCurrentChanged ( )
protectedslot

Definition at line 224 of file qgslayertreeview.cpp.

void QgsLayerTreeView::onExpandedChanged ( QgsLayerTreeNode node,
bool  expanded 
)
protectedslot

Definition at line 245 of file qgslayertreeview.cpp.

void QgsLayerTreeView::onModelReset ( )
protectedslot

Definition at line 268 of file qgslayertreeview.cpp.

void QgsLayerTreeView::refreshLayerSymbology ( const QString &  layerId)
slot

Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model.

Definition at line 393 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.

See also
addIndicator
indicators
Since
QGIS 3.2

Definition at line 376 of file qgslayertreeview.cpp.

QList< QgsLayerTreeLayer * > QgsLayerTreeView::selectedLayerNodes ( ) const

Returns list of selected nodes filtered to just layer nodes.

Definition at line 341 of file qgslayertreeview.cpp.

QList< QgsMapLayer * > QgsLayerTreeView::selectedLayers ( ) const

Gets list of selected layers.

Definition at line 352 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.

Since
QGIS 3.4

Definition at line 363 of file qgslayertreeview.cpp.

QList< QgsLayerTreeNode * > QgsLayerTreeView::selectedNodes ( bool  skipInternal = false) const

Returns list of selected nodes.

Parameters
skipInternalIf true, will ignore nodes which have an ancestor in the selection

Definition at line 336 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setCurrentLayer ( QgsMapLayer layer)

Sets currently selected layer. Null pointer will deselect any layer.

Definition at line 108 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setMenuProvider ( QgsLayerTreeViewMenuProvider menuProvider)

Sets provider for context menu. Takes ownership of the instance.

Definition at line 97 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setModel ( QAbstractItemModel *  model)
override

Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.

Definition at line 65 of file qgslayertreeview.cpp.

void QgsLayerTreeView::updateExpandedStateFromNode ( QgsLayerTreeNode node)
protected

Definition at line 273 of file qgslayertreeview.cpp.

void QgsLayerTreeView::updateExpandedStateToNode ( const QModelIndex &  index)
protectedslot

Definition at line 199 of file qgslayertreeview.cpp.

Friends And Related Function Documentation

friend class QgsLayerTreeViewItemDelegate
friend

Definition at line 219 of file qgslayertreeview.h.

Member Data Documentation

QString QgsLayerTreeView::mCurrentLayerID
protected

Keeps track of current layer ID (to check when to emit signal about change of current layer)

Definition at line 212 of file qgslayertreeview.h.

QgsLayerTreeViewDefaultActions* QgsLayerTreeView::mDefaultActions = nullptr
protected

helper class with default actions. Lazily initialized.

Definition at line 208 of file qgslayertreeview.h.

QHash< QgsLayerTreeNode *, QList<QgsLayerTreeViewIndicator *> > QgsLayerTreeView::mIndicators
protected

Storage of indicators used with the tree view.

Definition at line 214 of file qgslayertreeview.h.

QPoint QgsLayerTreeView::mLastReleaseMousePos
protected

Used by the item delegate for identification of which indicator has been clicked.

Definition at line 216 of file qgslayertreeview.h.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::mMenuProvider = nullptr
protected

Context menu provider. Owned by the view.

Definition at line 210 of file qgslayertreeview.h.


The documentation for this class was generated from the following files: