QGIS API Documentation  3.0.2-Girona (307d082)
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | 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
 
QgsLayerTreeGroupcurrentGroupNode () const
 Get current group node. If a layer is current node, the function will return parent group. May be null. More...
 
QgsMapLayercurrentLayer () const
 Get currently selected layer. May be null. More...
 
QgsLayerTreeModelLegendNodecurrentLegendNode () const
 Get current legend node. More...
 
QgsLayerTreeNodecurrentNode () const
 Get current node. May be null. More...
 
QgsLayerTreeViewDefaultActionsdefaultActions ()
 Get access to the default actions that may be used with the tree view. More...
 
QgsLayerTreeModellayerTreeModel () const
 Get access to the model casted to QgsLayerTreeModel. More...
 
QgsLayerTreeViewMenuProvidermenuProvider () const
 Return pointer to the context menu provider. May be null. More...
 
QList< QgsLayerTreeLayer * > selectedLayerNodes () const
 Return list of selected nodes filtered to just layer nodes. More...
 
QList< QgsMapLayer * > selectedLayers () const
 Get list of selected layers. More...
 
QList< QgsLayerTreeNode * > selectedNodes (bool skipInternal=false) const
 Return list of selected nodes. More...
 
void setCurrentLayer (QgsMapLayer *layer)
 Set currently selected layer. Null pointer will deselect any layer. More...
 
void setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider)
 Set 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...
 
QgsLayerTreeViewMenuProvidermMenuProvider = nullptr
 Context menu provider. Owned by the view. More...
 

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 48 of file qgslayertreeview.h.

Constructor & Destructor Documentation

◆ QgsLayerTreeView()

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

Constructor for QgsLayerTreeView.

Definition at line 30 of file qgslayertreeview.cpp.

◆ ~QgsLayerTreeView()

QgsLayerTreeView::~QgsLayerTreeView ( )
override

Definition at line 49 of file qgslayertreeview.cpp.

Member Function Documentation

◆ collapseAllNodes

void QgsLayerTreeView::collapseAllNodes ( )
slot

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

Since
QGIS 2.18

Definition at line 382 of file qgslayertreeview.cpp.

◆ contextMenuEvent()

void QgsLayerTreeView::contextMenuEvent ( QContextMenuEvent *  event)
overrideprotected

Definition at line 112 of file qgslayertreeview.cpp.

◆ currentGroupNode()

QgsLayerTreeGroup * QgsLayerTreeView::currentGroupNode ( ) const

Get current group node. If a layer is current node, the function will return parent group. May be null.

Definition at line 281 of file qgslayertreeview.cpp.

◆ currentLayer()

QgsMapLayer * QgsLayerTreeView::currentLayer ( ) const

Get currently selected layer. May be null.

Definition at line 91 of file qgslayertreeview.cpp.

◆ currentLayerChanged

void QgsLayerTreeView::currentLayerChanged ( QgsMapLayer layer)
signal

Emitted when a current layer is changed.

◆ currentLegendNode()

QgsLayerTreeModelLegendNode * QgsLayerTreeView::currentLegendNode ( ) const

Get current legend node.

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

Since
QGIS 2.14

Definition at line 303 of file qgslayertreeview.cpp.

◆ currentNode()

QgsLayerTreeNode * QgsLayerTreeView::currentNode ( ) const

Get current node. May be null.

Definition at line 276 of file qgslayertreeview.cpp.

◆ defaultActions()

QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions ( )

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

Definition at line 78 of file qgslayertreeview.cpp.

◆ dropEvent()

void QgsLayerTreeView::dropEvent ( QDropEvent *  event)
overrideprotected

Definition at line 411 of file qgslayertreeview.cpp.

◆ expandAllNodes

void QgsLayerTreeView::expandAllNodes ( )
slot

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

Since
QGIS 2.18

Definition at line 375 of file qgslayertreeview.cpp.

◆ keyPressEvent()

void QgsLayerTreeView::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 400 of file qgslayertreeview.cpp.

◆ layerForIndex()

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

Definition at line 254 of file qgslayertreeview.cpp.

◆ layerTreeModel()

QgsLayerTreeModel * QgsLayerTreeView::layerTreeModel ( ) const

Get access to the model casted to QgsLayerTreeModel.

Definition at line 73 of file qgslayertreeview.cpp.

◆ menuProvider()

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::menuProvider ( ) const
inline

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

Definition at line 80 of file qgslayertreeview.h.

◆ modelRowsInserted

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

Definition at line 128 of file qgslayertreeview.cpp.

◆ modelRowsRemoved

void QgsLayerTreeView::modelRowsRemoved ( )
protectedslot

Definition at line 181 of file qgslayertreeview.cpp.

◆ mouseReleaseEvent()

void QgsLayerTreeView::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 389 of file qgslayertreeview.cpp.

◆ onCurrentChanged

void QgsLayerTreeView::onCurrentChanged ( )
protectedslot

Definition at line 212 of file qgslayertreeview.cpp.

◆ onExpandedChanged

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

Definition at line 233 of file qgslayertreeview.cpp.

◆ onModelReset

void QgsLayerTreeView::onModelReset ( )
protectedslot

Definition at line 240 of file qgslayertreeview.cpp.

◆ refreshLayerSymbology

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 336 of file qgslayertreeview.cpp.

◆ selectedLayerNodes()

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

Return list of selected nodes filtered to just layer nodes.

Definition at line 313 of file qgslayertreeview.cpp.

◆ selectedLayers()

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

Get list of selected layers.

Definition at line 324 of file qgslayertreeview.cpp.

◆ selectedNodes()

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

Return list of selected nodes.

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

Definition at line 308 of file qgslayertreeview.cpp.

◆ setCurrentLayer()

void QgsLayerTreeView::setCurrentLayer ( QgsMapLayer layer)

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

Definition at line 96 of file qgslayertreeview.cpp.

◆ setMenuProvider()

void QgsLayerTreeView::setMenuProvider ( QgsLayerTreeViewMenuProvider menuProvider)

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

Definition at line 85 of file qgslayertreeview.cpp.

◆ setModel()

void QgsLayerTreeView::setModel ( QAbstractItemModel *  model)
override

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

Definition at line 54 of file qgslayertreeview.cpp.

◆ updateExpandedStateFromNode()

void QgsLayerTreeView::updateExpandedStateFromNode ( QgsLayerTreeNode node)
protected

Definition at line 245 of file qgslayertreeview.cpp.

◆ updateExpandedStateToNode

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

Definition at line 187 of file qgslayertreeview.cpp.

Member Data Documentation

◆ mCurrentLayerID

QString QgsLayerTreeView::mCurrentLayerID
protected

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

Definition at line 159 of file qgslayertreeview.h.

◆ mDefaultActions

QgsLayerTreeViewDefaultActions* QgsLayerTreeView::mDefaultActions = nullptr
protected

helper class with default actions. Lazily initialized.

Definition at line 155 of file qgslayertreeview.h.

◆ mMenuProvider

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::mMenuProvider = nullptr
protected

Context menu provider. Owned by the view.

Definition at line 157 of file qgslayertreeview.h.


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