QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>

Public Slots

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.

Signals

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

Public Member Functions

 QgsLayerTreeView (QWidget *parent=0)
 ~QgsLayerTreeView ()
QgsLayerTreeGroupcurrentGroupNode () const
 Get current group node. If a layer is current node, the function will return parent group. May be null.
QgsMapLayercurrentLayer () const
 Get currently selected layer. May be null.
QgsLayerTreeNodecurrentNode () const
 Get current node. May be null.
QgsLayerTreeViewDefaultActionsdefaultActions ()
 Get access to the default actions that may be used with the tree view.
QgsLayerTreeModellayerTreeModel () const
 Get access to the model casted to QgsLayerTreeModel.
QgsLayerTreeViewMenuProvidermenuProvider () const
 Return pointer to the context menu provider. May be null.
QList< QgsLayerTreeLayer * > selectedLayerNodes () const
 Return list of selected nodes filtered to just layer nodes.
QList< QgsMapLayer * > selectedLayers () const
 Get list of selected layers.
QList< QgsLayerTreeNode * > selectedNodes (bool skipInternal=false) const
 Return list of selected nodes.
void setCurrentLayer (QgsMapLayer *layer)
 Set currently selected layer. Null pointer will deselect any layer.
void setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider)
 Set provider for context menu. Takes ownership of the instance.
virtual void setModel (QAbstractItemModel *model) override
 Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.

Protected Slots

void modelRowsInserted (QModelIndex index, int start, int end)
void modelRowsRemoved ()
void onCurrentChanged ()
void onExpandedChanged (QgsLayerTreeNode *node, bool expanded)
void onModelReset ()
void updateExpandedStateToNode (QModelIndex index)

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event) override
QgsMapLayerlayerForIndex (const QModelIndex &index) const
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)
QgsLayerTreeViewDefaultActionsmDefaultActions
 helper class with default actions. Lazily initialized.
QgsLayerTreeViewMenuProvidermMenuProvider
 Context menu provider. Owned by the view.

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
Note
added in 2.4

Definition at line 44 of file qgslayertreeview.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file qgslayertreeview.cpp.

QgsLayerTreeView::~QgsLayerTreeView ( )

Definition at line 46 of file qgslayertreeview.cpp.

Member Function Documentation

void QgsLayerTreeView::contextMenuEvent ( QContextMenuEvent *  event)
overrideprotected

Definition at line 109 of file qgslayertreeview.cpp.

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

QgsMapLayer * QgsLayerTreeView::currentLayer ( ) const

Get currently selected layer. May be null.

Definition at line 88 of file qgslayertreeview.cpp.

void QgsLayerTreeView::currentLayerChanged ( QgsMapLayer layer)
signal

Emitted when a current layer is changed.

QgsLayerTreeNode * QgsLayerTreeView::currentNode ( ) const

Get current node. May be null.

Definition at line 249 of file qgslayertreeview.cpp.

QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions ( )

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

Definition at line 75 of file qgslayertreeview.cpp.

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

Definition at line 230 of file qgslayertreeview.cpp.

QgsLayerTreeModel * QgsLayerTreeView::layerTreeModel ( ) const

Get access to the model casted to QgsLayerTreeModel.

Definition at line 70 of file qgslayertreeview.cpp.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::menuProvider ( ) const
inline

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

Definition at line 63 of file qgslayertreeview.h.

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

Definition at line 125 of file qgslayertreeview.cpp.

void QgsLayerTreeView::modelRowsRemoved ( )
protectedslot

Definition at line 157 of file qgslayertreeview.cpp.

void QgsLayerTreeView::onCurrentChanged ( )
protectedslot

Definition at line 188 of file qgslayertreeview.cpp.

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

Definition at line 209 of file qgslayertreeview.cpp.

void QgsLayerTreeView::onModelReset ( )
protectedslot

Definition at line 216 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 304 of file qgslayertreeview.cpp.

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

Return list of selected nodes filtered to just layer nodes.

Definition at line 281 of file qgslayertreeview.cpp.

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

Get list of selected layers.

Definition at line 292 of file qgslayertreeview.cpp.

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

Return list of selected nodes.

  • skipInternal If true, will ignore nodes which have an ancestor in the selection

Definition at line 276 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setCurrentLayer ( QgsMapLayer layer)

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

Definition at line 93 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setMenuProvider ( QgsLayerTreeViewMenuProvider menuProvider)

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

Definition at line 82 of file qgslayertreeview.cpp.

void QgsLayerTreeView::setModel ( QAbstractItemModel *  model)
overridevirtual

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

Definition at line 51 of file qgslayertreeview.cpp.

void QgsLayerTreeView::updateExpandedStateFromNode ( QgsLayerTreeNode node)
protected

Definition at line 221 of file qgslayertreeview.cpp.

void QgsLayerTreeView::updateExpandedStateToNode ( QModelIndex  index)
protectedslot

Definition at line 163 of file qgslayertreeview.cpp.

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

QgsLayerTreeViewDefaultActions* QgsLayerTreeView::mDefaultActions
protected

helper class with default actions. Lazily initialized.

Definition at line 112 of file qgslayertreeview.h.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::mMenuProvider
protected

Context menu provider. Owned by the view.

Definition at line 114 of file qgslayertreeview.h.


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