QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgslayertreeview.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreeview.cpp
3  --------------------------------------
4  Date : May 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgslayertreeview.h"
17 
18 #include "qgslayertree.h"
20 #include "qgslayertreemodel.h"
22 #include "qgslayertreeutils.h"
24 #include "qgsmaplayer.h"
25 #include "qgsgui.h"
26 
27 #include <QMenu>
28 #include <QContextMenuEvent>
29 
32 
33 
35  : QTreeView( parent )
36 
37 {
38  setHeaderHidden( true );
39 
40  setDragEnabled( true );
41  setAcceptDrops( true );
42  setDropIndicatorShown( true );
43  setEditTriggers( EditKeyPressed );
44  setExpandsOnDoubleClick( false ); // normally used for other actions
45 
46  // If vertically scrolling by item, legend graphics can get clipped
47  setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
48 
49  setSelectionMode( ExtendedSelection );
50  setDefaultDropAction( Qt::MoveAction );
51 
52  // we need a custom item delegate in order to draw indicators
53  setItemDelegate( new QgsLayerTreeViewItemDelegate( this ) );
54  setStyle( new QgsLayerTreeViewProxyStyle( this ) );
55 
56  connect( this, &QTreeView::collapsed, this, &QgsLayerTreeView::updateExpandedStateToNode );
57  connect( this, &QTreeView::expanded, this, &QgsLayerTreeView::updateExpandedStateToNode );
58 }
59 
61 {
62  delete mMenuProvider;
63 }
64 
65 void QgsLayerTreeView::setModel( QAbstractItemModel *model )
66 {
67  if ( !qobject_cast<QgsLayerTreeModel *>( model ) )
68  return;
69 
70  connect( model, &QAbstractItemModel::rowsInserted, this, &QgsLayerTreeView::modelRowsInserted );
71  connect( model, &QAbstractItemModel::rowsRemoved, this, &QgsLayerTreeView::modelRowsRemoved );
72 
73  QTreeView::setModel( model );
74 
76  connect( layerTreeModel()->rootGroup(), &QgsLayerTreeNode::customPropertyChanged, this, &QgsLayerTreeView::onCustomPropertyChanged );
77 
78  connect( selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsLayerTreeView::onCurrentChanged );
79 
80  connect( layerTreeModel(), &QAbstractItemModel::modelReset, this, &QgsLayerTreeView::onModelReset );
81 
83 }
84 
86 {
87  return qobject_cast<QgsLayerTreeModel *>( model() );
88 }
89 
91 {
92  if ( !mDefaultActions )
94  return mDefaultActions;
95 }
96 
98 {
99  delete mMenuProvider;
101 }
102 
104 {
105  return layerForIndex( currentIndex() );
106 }
107 
109 {
110  if ( !layer )
111  {
112  setCurrentIndex( QModelIndex() );
113  return;
114  }
115 
116  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layer->id() );
117  if ( !nodeLayer )
118  return;
119 
120  setCurrentIndex( layerTreeModel()->node2index( nodeLayer ) );
121 }
122 
123 
124 void QgsLayerTreeView::contextMenuEvent( QContextMenuEvent *event )
125 {
126  if ( !mMenuProvider )
127  return;
128 
129  QModelIndex idx = indexAt( event->pos() );
130  if ( !idx.isValid() )
131  setCurrentIndex( QModelIndex() );
132 
133  QMenu *menu = mMenuProvider->createContextMenu();
134  if ( menu && menu->actions().count() != 0 )
135  menu->exec( mapToGlobal( event->pos() ) );
136  delete menu;
137 }
138 
139 
140 void QgsLayerTreeView::modelRowsInserted( const QModelIndex &index, int start, int end )
141 {
142  QgsLayerTreeNode *parentNode = layerTreeModel()->index2node( index );
143  if ( !parentNode )
144  return;
145 
146  // Embedded widgets - replace placeholders in the model by actual widgets
147  if ( layerTreeModel()->testFlag( QgsLayerTreeModel::UseEmbeddedWidgets ) && QgsLayerTree::isLayer( parentNode ) )
148  {
149  QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( parentNode );
150  if ( QgsMapLayer *layer = nodeLayer->layer() )
151  {
152  int widgetsCount = layer->customProperty( QStringLiteral( "embeddedWidgets/count" ), 0 ).toInt();
153  QList<QgsLayerTreeModelLegendNode *> legendNodes = layerTreeModel()->layerLegendNodes( nodeLayer, true );
154  for ( int i = 0; i < widgetsCount; ++i )
155  {
156  QString providerId = layer->customProperty( QStringLiteral( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
157  if ( QgsLayerTreeEmbeddedWidgetProvider *provider = QgsGui::layerTreeEmbeddedWidgetRegistry()->provider( providerId ) )
158  {
159  QModelIndex index = layerTreeModel()->legendNode2index( legendNodes[i] );
160  setIndexWidget( index, provider->createWidget( layer, i ) );
161  }
162  }
163  }
164  }
165 
166 
167  if ( QgsLayerTree::isLayer( parentNode ) )
168  {
169  // if ShowLegendAsTree flag is enabled in model, we may need to expand some legend nodes
170  QStringList expandedNodeKeys = parentNode->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList();
171  if ( expandedNodeKeys.isEmpty() )
172  return;
173 
174  Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( parentNode ), true ) )
175  {
176  QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
177  if ( expandedNodeKeys.contains( ruleKey ) )
178  setExpanded( layerTreeModel()->legendNode2index( legendNode ), true );
179  }
180  return;
181  }
182 
183  QList<QgsLayerTreeNode *> children = parentNode->children();
184  for ( int i = start; i <= end; ++i )
185  {
186  updateExpandedStateFromNode( children[i] );
187  }
188 
189  // make sure we still have correct current layer
191 }
192 
194 {
195  // make sure we still have correct current layer
197 }
198 
199 void QgsLayerTreeView::updateExpandedStateToNode( const QModelIndex &index )
200 {
201  if ( QgsLayerTreeNode *node = layerTreeModel()->index2node( index ) )
202  {
203  node->setExpanded( isExpanded( index ) );
204  }
205  else if ( QgsLayerTreeModelLegendNode *node = layerTreeModel()->index2legendNode( index ) )
206  {
207  QString ruleKey = node->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
208  QStringList lst = node->layerNode()->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList();
209  bool expanded = isExpanded( index );
210  bool isInList = lst.contains( ruleKey );
211  if ( expanded && !isInList )
212  {
213  lst.append( ruleKey );
214  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
215  }
216  else if ( !expanded && isInList )
217  {
218  lst.removeAll( ruleKey );
219  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
220  }
221  }
222 }
223 
225 {
226  QgsMapLayer *layerCurrent = layerForIndex( currentIndex() );
227  QString layerCurrentID = layerCurrent ? layerCurrent->id() : QString();
228  if ( mCurrentLayerID == layerCurrentID )
229  return;
230 
231  // update the current index in model (the item will be underlined)
232  QModelIndex nodeLayerIndex;
233  if ( layerCurrent )
234  {
235  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerCurrentID );
236  if ( nodeLayer )
237  nodeLayerIndex = layerTreeModel()->node2index( nodeLayer );
238  }
239  layerTreeModel()->setCurrentIndex( nodeLayerIndex );
240 
241  mCurrentLayerID = layerCurrentID;
242  emit currentLayerChanged( layerCurrent );
243 }
244 
246 {
247  QModelIndex idx = layerTreeModel()->node2index( node );
248  if ( isExpanded( idx ) != expanded )
249  setExpanded( idx, expanded );
250 }
251 
252 void QgsLayerTreeView::onCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key )
253 {
254  if ( key != QStringLiteral( "expandedLegendNodes" ) || !QgsLayerTree::isLayer( node ) )
255  return;
256 
257  QSet<QString> expandedLegendNodes = node->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList().toSet();
258 
259  const QList<QgsLayerTreeModelLegendNode *> legendNodes = layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( node ), true );
260  for ( QgsLayerTreeModelLegendNode *legendNode : legendNodes )
261  {
262  QString key = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
263  if ( !key.isEmpty() )
264  setExpanded( layerTreeModel()->legendNode2index( legendNode ), expandedLegendNodes.contains( key ) );
265  }
266 }
267 
269 {
271 }
272 
274 {
275  QModelIndex idx = layerTreeModel()->node2index( node );
276  setExpanded( idx, node->isExpanded() );
277 
278  Q_FOREACH ( QgsLayerTreeNode *child, node->children() )
280 }
281 
282 QgsMapLayer *QgsLayerTreeView::layerForIndex( const QModelIndex &index ) const
283 {
284  // Check if model has been set and index is valid
285  if ( layerTreeModel() && index.isValid() )
286  {
287  QgsLayerTreeNode *node = layerTreeModel()->index2node( index );
288  if ( node )
289  {
290  if ( QgsLayerTree::isLayer( node ) )
291  return QgsLayerTree::toLayer( node )->layer();
292  }
293  else
294  {
295  // possibly a legend node
297  if ( legendNode )
298  return legendNode->layerNode()->layer();
299  }
300  }
301  return nullptr;
302 }
303 
305 {
306  return layerTreeModel()->index2node( selectionModel()->currentIndex() );
307 }
308 
310 {
311  QgsLayerTreeNode *node = currentNode();
312  if ( QgsLayerTree::isGroup( node ) )
313  return QgsLayerTree::toGroup( node );
314  else if ( QgsLayerTree::isLayer( node ) )
315  {
316  QgsLayerTreeNode *parent = node->parent();
317  if ( QgsLayerTree::isGroup( parent ) )
318  return QgsLayerTree::toGroup( parent );
319  }
320 
321  if ( QgsLayerTreeModelLegendNode *legendNode = layerTreeModel()->index2legendNode( selectionModel()->currentIndex() ) )
322  {
323  QgsLayerTreeLayer *parent = legendNode->layerNode();
324  if ( QgsLayerTree::isGroup( parent->parent() ) )
325  return QgsLayerTree::toGroup( parent->parent() );
326  }
327 
328  return nullptr;
329 }
330 
332 {
333  return layerTreeModel()->index2legendNode( selectionModel()->currentIndex() );
334 }
335 
336 QList<QgsLayerTreeNode *> QgsLayerTreeView::selectedNodes( bool skipInternal ) const
337 {
338  return layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), skipInternal );
339 }
340 
341 QList<QgsLayerTreeLayer *> QgsLayerTreeView::selectedLayerNodes() const
342 {
343  QList<QgsLayerTreeLayer *> layerNodes;
344  Q_FOREACH ( QgsLayerTreeNode *node, selectedNodes() )
345  {
346  if ( QgsLayerTree::isLayer( node ) )
347  layerNodes << QgsLayerTree::toLayer( node );
348  }
349  return layerNodes;
350 }
351 
352 QList<QgsMapLayer *> QgsLayerTreeView::selectedLayers() const
353 {
354  QList<QgsMapLayer *> list;
355  Q_FOREACH ( QgsLayerTreeLayer *node, selectedLayerNodes() )
356  {
357  if ( node->layer() )
358  list << node->layer();
359  }
360  return list;
361 }
362 
363 QList<QgsMapLayer *> QgsLayerTreeView::selectedLayersRecursive() const
364 {
365  const QList<QgsLayerTreeNode *> nodes = layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), false );
366  QSet<QgsMapLayer *> layersSet = QgsLayerTreeUtils::collectMapLayersRecursive( nodes );
367  return layersSet.toList();
368 }
369 
371 {
372  if ( !mIndicators[node].contains( indicator ) )
373  mIndicators[node].append( indicator );
374 }
375 
377 {
378  mIndicators[node].removeOne( indicator );
379 }
380 
381 QList<QgsLayerTreeViewIndicator *> QgsLayerTreeView::indicators( QgsLayerTreeNode *node ) const
382 {
383  return mIndicators.value( node );
384 }
385 
387 QStringList QgsLayerTreeView::viewOnlyCustomProperties()
388 {
389  return QStringList() << QStringLiteral( "expandedLegendNodes" );
390 }
392 
393 void QgsLayerTreeView::refreshLayerSymbology( const QString &layerId )
394 {
395  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerId );
396  if ( nodeLayer )
397  layerTreeModel()->refreshLayerLegend( nodeLayer );
398 }
399 
400 
401 static void _expandAllLegendNodes( QgsLayerTreeLayer *nodeLayer, bool expanded, QgsLayerTreeModel *model )
402 {
403  // for layers we also need to find out with legend nodes contain some children and make them expanded/collapsed
404  // if we are collapsing, we just write out an empty list
405  QStringList lst;
406  if ( expanded )
407  {
408  Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, model->layerLegendNodes( nodeLayer, true ) )
409  {
410  QString parentKey = legendNode->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString();
411  if ( !parentKey.isEmpty() && !lst.contains( parentKey ) )
412  lst << parentKey;
413  }
414  }
415  nodeLayer->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
416 }
417 
418 
419 static void _expandAllNodes( QgsLayerTreeGroup *parent, bool expanded, QgsLayerTreeModel *model )
420 {
421  Q_FOREACH ( QgsLayerTreeNode *node, parent->children() )
422  {
423  node->setExpanded( expanded );
424  if ( QgsLayerTree::isGroup( node ) )
425  _expandAllNodes( QgsLayerTree::toGroup( node ), expanded, model );
426  else if ( QgsLayerTree::isLayer( node ) )
427  _expandAllLegendNodes( QgsLayerTree::toLayer( node ), expanded, model );
428  }
429 }
430 
431 
433 {
434  // unfortunately expandAll() does not emit expanded() signals
435  _expandAllNodes( layerTreeModel()->rootGroup(), true, layerTreeModel() );
436  expandAll();
437 }
438 
440 {
441  // unfortunately collapseAll() does not emit collapsed() signals
442  _expandAllNodes( layerTreeModel()->rootGroup(), false, layerTreeModel() );
443  collapseAll();
444 }
445 
446 void QgsLayerTreeView::mouseReleaseEvent( QMouseEvent *event )
447 {
448  // we need to keep last mouse position in order to know whether to emit an indicator's clicked() signal
449  // (the item delegate needs to know which indicator has been clicked)
450  mLastReleaseMousePos = event->pos();
451 
452  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
453  if ( event->modifiers() & Qt::ControlModifier )
455  else
457  QTreeView::mouseReleaseEvent( event );
458  layerTreeModel()->setFlags( oldFlags );
459 }
460 
461 void QgsLayerTreeView::keyPressEvent( QKeyEvent *event )
462 {
463  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
464  if ( event->modifiers() & Qt::ControlModifier )
466  else
468  QTreeView::keyPressEvent( event );
469  layerTreeModel()->setFlags( oldFlags );
470 }
471 
472 void QgsLayerTreeView::dropEvent( QDropEvent *event )
473 {
474  if ( event->keyboardModifiers() & Qt::AltModifier )
475  {
476  event->accept();
477  }
478  QTreeView::dropEvent( event );
479 }
Layer tree group node serves as a container for layers and further groups.
QgsLayerTreeModelLegendNode * currentLegendNode() const
Gets current legend node.
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:75
Base class for all map layer types.
Definition: qgsmaplayer.h:63
Implementation of this interface can be implemented to allow QgsLayerTreeView instance to provide cus...
QgsMapLayer * currentLayer() const
Gets currently selected layer. May be null.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:43
void setCurrentIndex(const QModelIndex &currentIndex)
Sets index of the current item. May be used by view. Item marked as current is underlined.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non-null pointer.
QgsLayerTreeViewMenuProvider * mMenuProvider
Context menu provider. Owned by the view.
void removeIndicator(QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator)
Removes a previously added indicator to a layer tree node.
QList< QgsLayerTreeNode * > indexes2nodes(const QModelIndexList &list, bool skipInternal=false) const
Convert a list of indexes to a list of layer tree nodes.
QList< QgsMapLayer * > selectedLayersRecursive() const
Gets list of selected layers, including those that are not directly selected, but their ancestor grou...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file...
void refreshLayerSymbology(const QString &layerId)
Force refresh of layer symbology. Normally not needed as the changes of layer&#39;s renderer are monitore...
QgsMapLayer * layer() const
Returns the map layer associated with this node.
void contextMenuEvent(QContextMenuEvent *event) override
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
QgsLayerTreeViewMenuProvider * menuProvider() const
Returns pointer to the context menu provider. May be null.
QgsLayerTreeNode * currentNode() const
Gets current node. May be null.
QList< QgsMapLayer * > selectedLayers() const
Gets list of selected layers.
void modelRowsInserted(const QModelIndex &index, int start, int end)
QgsLayerTreeViewDefaultActions * defaultActions()
Gets access to the default actions that may be used with the tree view.
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
virtual QMenu * createContextMenu()=0
Returns a newly created menu instance (or null pointer on error)
void setFlags(QgsLayerTreeModel::Flags f)
Sets OR-ed combination of model flags.
void mouseReleaseEvent(QMouseEvent *event) override
QString mCurrentLayerID
Keeps track of current layer ID (to check when to emit signal about change of current layer) ...
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
QList< QgsLayerTreeViewIndicator * > indicators(QgsLayerTreeNode *node) const
Returns list of indicators associated with a particular layer tree node.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2...
void updateExpandedStateToNode(const QModelIndex &index)
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
void expandedChanged(QgsLayerTreeNode *node, bool expanded)
Emitted when the collapsed/expanded state of a node within the tree has been changed.
QModelIndex legendNode2index(QgsLayerTreeModelLegendNode *legendNode)
Returns index for a given legend node.
static QgsLayerTreeEmbeddedWidgetRegistry * layerTreeEmbeddedWidgetRegistry()
Returns the global layer tree embedded widget registry, used for registering widgets that may be embe...
Definition: qgsgui.cpp:73
Provider interface to be implemented in order to introduce new kinds of embedded widgets for use in l...
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group...
void addIndicator(QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator)
Adds an indicator to the given layer tree node.
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Returns legend node for given index.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is a null pointer, the node is a root node. ...
QPoint mLastReleaseMousePos
Used by the item delegate for identification of which indicator has been clicked. ...
static QSet< QgsMapLayer * > collectMapLayersRecursive(const QList< QgsLayerTreeNode * > &nodes)
Returns map layers from the given list of layer tree nodes.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
QHash< QgsLayerTreeNode *, QList< QgsLayerTreeViewIndicator * > > mIndicators
Storage of indicators used with the tree view.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:53
This class is a base class for nodes in a layer tree.
friend class QgsLayerTreeViewItemDelegate
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
void collapseAllNodes()
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes...
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
void keyPressEvent(QKeyEvent *event) override
void currentLayerChanged(QgsMapLayer *layer)
Emitted when a current layer is changed.
void refreshLayerLegend(QgsLayerTreeLayer *nodeLayer)
Force a refresh of legend nodes of a layer node.
QgsLayerTreeViewDefaultActions * mDefaultActions
helper class with default actions. Lazily initialized.
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns index for a given node. If the node does not belong to the layer tree, the result is undefine...
Qt::ItemFlags flags(const QModelIndex &index) const override
void updateExpandedStateFromNode(QgsLayerTreeNode *node)
void onExpandedChanged(QgsLayerTreeNode *node, bool expanded)
Layer nodes may optionally include extra embedded widgets (if used in QgsLayerTreeView). Added in 2.16.
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
void dropEvent(QDropEvent *event) override
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Check/uncheck action has consequences on children (or parents for leaf node)
void setModel(QAbstractItemModel *model) override
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false)
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
void setCurrentLayer(QgsMapLayer *layer)
Sets currently selected layer. Null pointer will deselect any layer.
QgsLayerTreeView(QWidget *parent=nullptr)
Constructor for QgsLayerTreeView.
void setMenuProvider(QgsLayerTreeViewMenuProvider *menuProvider)
Sets provider for context menu. Takes ownership of the instance.
~QgsLayerTreeView() override
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
void expandAllNodes()
Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes...
Indicator that can be used in a layer tree view to display icons next to items of the layer tree...
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
QgsMapLayer * layerForIndex(const QModelIndex &index) const
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file...
Layer tree node points to a map layer.