QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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>

Inheritance diagram for QgsLayerTreeView:
Inheritance graph
[legend]

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. More...
 

Signals

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

Public Member Functions

 QgsLayerTreeView (QWidget *parent=0)
 
 ~QgsLayerTreeView ()
 
virtual void setModel (QAbstractItemModel *model)
 Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model. More...
 
QgsLayerTreeModellayerTreeModel () const
 Get access to the model casted to QgsLayerTreeModel. More...
 
QgsLayerTreeViewDefaultActionsdefaultActions ()
 Get access to the default actions that may be used with the tree view. More...
 
void setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider)
 Set provider for context menu. Takes ownership of the instance. More...
 
QgsLayerTreeViewMenuProvidermenuProvider () const
 Return pointer to the context menu provider. May be null. More...
 
QgsMapLayercurrentLayer () const
 Get currently selected layer. May be null. More...
 
void setCurrentLayer (QgsMapLayer *layer)
 Set currently selected layer. Null pointer will deselect any layer. More...
 
QgsLayerTreeNodecurrentNode () const
 Get current node. May be null. More...
 
QgsLayerTreeGroupcurrentGroupNode () const
 Get current group node. If a layer is current node, the function will return parent group. May be null. More...
 
QList< QgsLayerTreeNode * > selectedNodes (bool skipInternal=false) const
 Return list of selected nodes. 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...
 
void setAutoSelectAddedLayers (bool enabled)
 if enabled, current selection will be automatically changed to the newly added layer node. More...
 
bool autoSelectAddedLayers () const
 

Protected Slots

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

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event)
 
void updateExpandedStateFromNode (QgsLayerTreeNode *node)
 
QgsMapLayerlayerForIndex (const QModelIndex &index) const
 

Protected Attributes

QgsLayerTreeViewDefaultActionsmDefaultActions
 helper class with default actions. Lazily initialized. More...
 
QgsLayerTreeViewMenuProvidermMenuProvider
 Context menu provider. Owned by the view. More...
 
QString mCurrentLayerID
 Keeps track of current layer ID (to check when to emit signal about change of current layer) More...
 
bool mAutoSelectAddedLayers
 Indicates whether the view should select newly added layers when they are added to the model. 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
Note
added in 2.4

Constructor & Destructor Documentation

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

Member Function Documentation

bool QgsLayerTreeView::autoSelectAddedLayers ( ) const
inline
Note
added in 2.6
void QgsLayerTreeView::contextMenuEvent ( QContextMenuEvent *  event)
protected
QgsLayerTreeGroup * QgsLayerTreeView::currentGroupNode ( ) const

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

QgsMapLayer * QgsLayerTreeView::currentLayer ( ) const

Get currently selected layer. May be null.

void QgsLayerTreeView::currentLayerChanged ( QgsMapLayer layer)
signal

Emitted when a current layer is changed.

QgsLayerTreeNode * QgsLayerTreeView::currentNode ( ) const

Get current node. May be null.

QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions ( )

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

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

Get access to the model casted to QgsLayerTreeModel.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::menuProvider ( ) const
inline

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

void QgsLayerTreeView::modelRowsInserted ( QModelIndex  index,
int  start,
int  end 
)
protectedslot
void QgsLayerTreeView::modelRowsRemoved ( )
protectedslot
void QgsLayerTreeView::onCurrentChanged ( )
protectedslot
void QgsLayerTreeView::onExpandedChanged ( QgsLayerTreeNode node,
bool  expanded 
)
protectedslot
void QgsLayerTreeView::onModelReset ( )
protectedslot
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.

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

Return list of selected nodes filtered to just layer nodes.

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

Get list of selected layers.

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
void QgsLayerTreeView::setAutoSelectAddedLayers ( bool  enabled)
inline

if enabled, current selection will be automatically changed to the newly added layer node.

This is purely for user's convenience so they do not need to click on the layer explicitly.

Note
added in 2.6
void QgsLayerTreeView::setCurrentLayer ( QgsMapLayer layer)

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

void QgsLayerTreeView::setMenuProvider ( QgsLayerTreeViewMenuProvider menuProvider)

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

void QgsLayerTreeView::setModel ( QAbstractItemModel *  model)
virtual

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

void QgsLayerTreeView::updateExpandedStateFromNode ( QgsLayerTreeNode node)
protected
void QgsLayerTreeView::updateExpandedStateToNode ( QModelIndex  index)
protectedslot

Member Data Documentation

bool QgsLayerTreeView::mAutoSelectAddedLayers
protected

Indicates whether the view should select newly added layers when they are added to the model.

QString QgsLayerTreeView::mCurrentLayerID
protected

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

QgsLayerTreeViewDefaultActions* QgsLayerTreeView::mDefaultActions
protected

helper class with default actions. Lazily initialized.

QgsLayerTreeViewMenuProvider* QgsLayerTreeView::mMenuProvider
protected

Context menu provider. Owned by the view.


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