QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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  setSelectionMode( ExtendedSelection );
47  setDefaultDropAction( Qt::MoveAction );
48 
49  // we need a custom item delegate in order to draw indicators
50  setItemDelegate( new QgsLayerTreeViewItemDelegate( this ) );
51  setStyle( new QgsLayerTreeViewProxyStyle( this ) );
52 
53  connect( this, &QTreeView::collapsed, this, &QgsLayerTreeView::updateExpandedStateToNode );
54  connect( this, &QTreeView::expanded, this, &QgsLayerTreeView::updateExpandedStateToNode );
55 }
56 
58 {
59  delete mMenuProvider;
60 }
61 
62 void QgsLayerTreeView::setModel( QAbstractItemModel *model )
63 {
64  if ( !qobject_cast<QgsLayerTreeModel *>( model ) )
65  return;
66 
67  connect( model, &QAbstractItemModel::rowsInserted, this, &QgsLayerTreeView::modelRowsInserted );
68  connect( model, &QAbstractItemModel::rowsRemoved, this, &QgsLayerTreeView::modelRowsRemoved );
69 
70  QTreeView::setModel( model );
71 
73  connect( layerTreeModel()->rootGroup(), &QgsLayerTreeNode::customPropertyChanged, this, &QgsLayerTreeView::onCustomPropertyChanged );
74 
75  connect( selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsLayerTreeView::onCurrentChanged );
76 
77  connect( layerTreeModel(), &QAbstractItemModel::modelReset, this, &QgsLayerTreeView::onModelReset );
78 
80 }
81 
83 {
84  return qobject_cast<QgsLayerTreeModel *>( model() );
85 }
86 
88 {
89  if ( !mDefaultActions )
91  return mDefaultActions;
92 }
93 
95 {
96  delete mMenuProvider;
98 }
99 
101 {
102  return layerForIndex( currentIndex() );
103 }
104 
106 {
107  if ( !layer )
108  {
109  setCurrentIndex( QModelIndex() );
110  return;
111  }
112 
113  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layer->id() );
114  if ( !nodeLayer )
115  return;
116 
117  setCurrentIndex( layerTreeModel()->node2index( nodeLayer ) );
118 }
119 
120 
121 void QgsLayerTreeView::contextMenuEvent( QContextMenuEvent *event )
122 {
123  if ( !mMenuProvider )
124  return;
125 
126  QModelIndex idx = indexAt( event->pos() );
127  if ( !idx.isValid() )
128  setCurrentIndex( QModelIndex() );
129 
130  QMenu *menu = mMenuProvider->createContextMenu();
131  if ( menu && menu->actions().count() != 0 )
132  menu->exec( mapToGlobal( event->pos() ) );
133  delete menu;
134 }
135 
136 
137 void QgsLayerTreeView::modelRowsInserted( const QModelIndex &index, int start, int end )
138 {
139  QgsLayerTreeNode *parentNode = layerTreeModel()->index2node( index );
140  if ( !parentNode )
141  return;
142 
143  // Embedded widgets - replace placeholders in the model by actual widgets
144  if ( layerTreeModel()->testFlag( QgsLayerTreeModel::UseEmbeddedWidgets ) && QgsLayerTree::isLayer( parentNode ) )
145  {
146  QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( parentNode );
147  if ( QgsMapLayer *layer = nodeLayer->layer() )
148  {
149  int widgetsCount = layer->customProperty( QStringLiteral( "embeddedWidgets/count" ), 0 ).toInt();
150  QList<QgsLayerTreeModelLegendNode *> legendNodes = layerTreeModel()->layerLegendNodes( nodeLayer, true );
151  for ( int i = 0; i < widgetsCount; ++i )
152  {
153  QString providerId = layer->customProperty( QStringLiteral( "embeddedWidgets/%1/id" ).arg( i ) ).toString();
154  if ( QgsLayerTreeEmbeddedWidgetProvider *provider = QgsGui::layerTreeEmbeddedWidgetRegistry()->provider( providerId ) )
155  {
156  QModelIndex index = layerTreeModel()->legendNode2index( legendNodes[i] );
157  setIndexWidget( index, provider->createWidget( layer, i ) );
158  }
159  }
160  }
161  }
162 
163 
164  if ( QgsLayerTree::isLayer( parentNode ) )
165  {
166  // if ShowLegendAsTree flag is enabled in model, we may need to expand some legend nodes
167  QStringList expandedNodeKeys = parentNode->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList();
168  if ( expandedNodeKeys.isEmpty() )
169  return;
170 
171  const auto constLayerLegendNodes = layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( parentNode ), true );
172  for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
173  {
174  QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
175  if ( expandedNodeKeys.contains( ruleKey ) )
176  setExpanded( layerTreeModel()->legendNode2index( legendNode ), true );
177  }
178  return;
179  }
180 
181  QList<QgsLayerTreeNode *> children = parentNode->children();
182  for ( int i = start; i <= end; ++i )
183  {
184  updateExpandedStateFromNode( children[i] );
185  }
186 
187  // make sure we still have correct current layer
189 }
190 
192 {
193  // make sure we still have correct current layer
195 }
196 
197 void QgsLayerTreeView::updateExpandedStateToNode( const QModelIndex &index )
198 {
199  if ( QgsLayerTreeNode *node = layerTreeModel()->index2node( index ) )
200  {
201  node->setExpanded( isExpanded( index ) );
202  }
203  else if ( QgsLayerTreeModelLegendNode *node = layerTreeModel()->index2legendNode( index ) )
204  {
205  QString ruleKey = node->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
206  QStringList lst = node->layerNode()->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList();
207  bool expanded = isExpanded( index );
208  bool isInList = lst.contains( ruleKey );
209  if ( expanded && !isInList )
210  {
211  lst.append( ruleKey );
212  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
213  }
214  else if ( !expanded && isInList )
215  {
216  lst.removeAll( ruleKey );
217  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
218  }
219  }
220 }
221 
223 {
224  QgsMapLayer *layerCurrent = layerForIndex( currentIndex() );
225  QString layerCurrentID = layerCurrent ? layerCurrent->id() : QString();
226  if ( mCurrentLayerID == layerCurrentID )
227  return;
228 
229  // update the current index in model (the item will be underlined)
230  QModelIndex nodeLayerIndex;
231  if ( layerCurrent )
232  {
233  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerCurrentID );
234  if ( nodeLayer )
235  nodeLayerIndex = layerTreeModel()->node2index( nodeLayer );
236  }
237  layerTreeModel()->setCurrentIndex( nodeLayerIndex );
238 
239  mCurrentLayerID = layerCurrentID;
240  emit currentLayerChanged( layerCurrent );
241 }
242 
244 {
245  QModelIndex idx = layerTreeModel()->node2index( node );
246  if ( isExpanded( idx ) != expanded )
247  setExpanded( idx, expanded );
248 }
249 
250 void QgsLayerTreeView::onCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key )
251 {
252  if ( key != QStringLiteral( "expandedLegendNodes" ) || !QgsLayerTree::isLayer( node ) )
253  return;
254 
255  QSet<QString> expandedLegendNodes = node->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList().toSet();
256 
257  const QList<QgsLayerTreeModelLegendNode *> legendNodes = layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( node ), true );
258  for ( QgsLayerTreeModelLegendNode *legendNode : legendNodes )
259  {
260  QString key = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
261  if ( !key.isEmpty() )
262  setExpanded( layerTreeModel()->legendNode2index( legendNode ), expandedLegendNodes.contains( key ) );
263  }
264 }
265 
267 {
269 }
270 
272 {
273  QModelIndex idx = layerTreeModel()->node2index( node );
274  setExpanded( idx, node->isExpanded() );
275 
276  const auto constChildren = node->children();
277  for ( QgsLayerTreeNode *child : constChildren )
279 }
280 
281 QgsMapLayer *QgsLayerTreeView::layerForIndex( const QModelIndex &index ) const
282 {
283  // Check if model has been set and index is valid
284  if ( layerTreeModel() && index.isValid() )
285  {
286  QgsLayerTreeNode *node = layerTreeModel()->index2node( index );
287  if ( node )
288  {
289  if ( QgsLayerTree::isLayer( node ) )
290  return QgsLayerTree::toLayer( node )->layer();
291  }
292  else
293  {
294  // possibly a legend node
296  if ( legendNode )
297  return legendNode->layerNode()->layer();
298  }
299  }
300  return nullptr;
301 }
302 
304 {
305  return layerTreeModel()->index2node( selectionModel()->currentIndex() );
306 }
307 
309 {
310  QgsLayerTreeNode *node = currentNode();
311  if ( QgsLayerTree::isGroup( node ) )
312  return QgsLayerTree::toGroup( node );
313  else if ( QgsLayerTree::isLayer( node ) )
314  {
315  QgsLayerTreeNode *parent = node->parent();
316  if ( QgsLayerTree::isGroup( parent ) )
317  return QgsLayerTree::toGroup( parent );
318  }
319 
320  if ( QgsLayerTreeModelLegendNode *legendNode = layerTreeModel()->index2legendNode( selectionModel()->currentIndex() ) )
321  {
323  if ( QgsLayerTree::isGroup( parent->parent() ) )
324  return QgsLayerTree::toGroup( parent->parent() );
325  }
326 
327  return nullptr;
328 }
329 
331 {
332  return layerTreeModel()->index2legendNode( selectionModel()->currentIndex() );
333 }
334 
335 QList<QgsLayerTreeNode *> QgsLayerTreeView::selectedNodes( bool skipInternal ) const
336 {
337  return layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), skipInternal );
338 }
339 
340 QList<QgsLayerTreeLayer *> QgsLayerTreeView::selectedLayerNodes() const
341 {
342  QList<QgsLayerTreeLayer *> layerNodes;
343  const auto constSelectedNodes = selectedNodes();
344  for ( QgsLayerTreeNode *node : constSelectedNodes )
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  const auto constSelectedLayerNodes = selectedLayerNodes();
356  for ( QgsLayerTreeLayer *node : constSelectedLayerNodes )
357  {
358  if ( node->layer() )
359  list << node->layer();
360  }
361  return list;
362 }
363 
364 QList<QgsMapLayer *> QgsLayerTreeView::selectedLayersRecursive() const
365 {
366  const QList<QgsLayerTreeNode *> nodes = layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), false );
367  QSet<QgsMapLayer *> layersSet = QgsLayerTreeUtils::collectMapLayersRecursive( nodes );
368  return layersSet.toList();
369 }
370 
372 {
373  if ( !mIndicators[node].contains( indicator ) )
374  mIndicators[node].append( indicator );
375 }
376 
378 {
379  mIndicators[node].removeOne( indicator );
380 }
381 
382 QList<QgsLayerTreeViewIndicator *> QgsLayerTreeView::indicators( QgsLayerTreeNode *node ) const
383 {
384  return mIndicators.value( node );
385 }
386 
388 QStringList QgsLayerTreeView::viewOnlyCustomProperties()
389 {
390  return QStringList() << QStringLiteral( "expandedLegendNodes" );
391 }
393 
394 void QgsLayerTreeView::refreshLayerSymbology( const QString &layerId )
395 {
396  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerId );
397  if ( nodeLayer )
398  layerTreeModel()->refreshLayerLegend( nodeLayer );
399 }
400 
401 
402 static void _expandAllLegendNodes( QgsLayerTreeLayer *nodeLayer, bool expanded, QgsLayerTreeModel *model )
403 {
404  // for layers we also need to find out with legend nodes contain some children and make them expanded/collapsed
405  // if we are collapsing, we just write out an empty list
406  QStringList lst;
407  if ( expanded )
408  {
409  const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
410  for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
411  {
412  QString parentKey = legendNode->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString();
413  if ( !parentKey.isEmpty() && !lst.contains( parentKey ) )
414  lst << parentKey;
415  }
416  }
417  nodeLayer->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
418 }
419 
420 
421 static void _expandAllNodes( QgsLayerTreeGroup *parent, bool expanded, QgsLayerTreeModel *model )
422 {
423  const auto constChildren = parent->children();
424  for ( QgsLayerTreeNode *node : constChildren )
425  {
426  node->setExpanded( expanded );
427  if ( QgsLayerTree::isGroup( node ) )
428  _expandAllNodes( QgsLayerTree::toGroup( node ), expanded, model );
429  else if ( QgsLayerTree::isLayer( node ) )
430  _expandAllLegendNodes( QgsLayerTree::toLayer( node ), expanded, model );
431  }
432 }
433 
434 
436 {
437  // unfortunately expandAll() does not emit expanded() signals
438  _expandAllNodes( layerTreeModel()->rootGroup(), true, layerTreeModel() );
439  expandAll();
440 }
441 
443 {
444  // unfortunately collapseAll() does not emit collapsed() signals
445  _expandAllNodes( layerTreeModel()->rootGroup(), false, layerTreeModel() );
446  collapseAll();
447 }
448 
449 void QgsLayerTreeView::mouseReleaseEvent( QMouseEvent *event )
450 {
451  // we need to keep last mouse position in order to know whether to emit an indicator's clicked() signal
452  // (the item delegate needs to know which indicator has been clicked)
453  mLastReleaseMousePos = event->pos();
454 
455  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
456  if ( event->modifiers() & Qt::ControlModifier )
458  else
460  QTreeView::mouseReleaseEvent( event );
461  layerTreeModel()->setFlags( oldFlags );
462 }
463 
464 void QgsLayerTreeView::keyPressEvent( QKeyEvent *event )
465 {
466  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
467  if ( event->modifiers() & Qt::ControlModifier )
469  else
471  QTreeView::keyPressEvent( event );
472  layerTreeModel()->setFlags( oldFlags );
473 }
474 
475 void QgsLayerTreeView::dropEvent( QDropEvent *event )
476 {
477  if ( event->keyboardModifiers() & Qt::AltModifier )
478  {
479  event->accept();
480  }
481  QTreeView::dropEvent( event );
482 }
Layer tree group node serves as a container for layers and further groups.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:75
QList< QgsMapLayer * > selectedLayers() const
Gets list of selected layers.
Base class for all map layer types.
Definition: qgsmaplayer.h:78
Implementation of this interface can be implemented to allow QgsLayerTreeView instance to provide cus...
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.
QList< QgsLayerTreeNode * > indexes2nodes(const QModelIndexList &list, bool skipInternal=false) const
Convert a list of indexes to a list of layer tree nodes.
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.
void refreshLayerSymbology(const QString &layerId)
Force refresh of layer symbology. Normally not needed as the changes of layer&#39;s renderer are monitore...
void contextMenuEvent(QContextMenuEvent *event) override
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
void modelRowsInserted(const QModelIndex &index, int start, int end)
QgsMapLayer * currentLayer() const
Returns the currently selected layer, or nullptr if no layers is selected.
QgsLayerTreeViewDefaultActions * defaultActions()
Gets access to the default actions that may be used with the tree view.
bool isExpanded() const
Returns 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...
virtual QMenu * createContextMenu()=0
Returns a newly created menu instance (or nullptr on error)
void setFlags(QgsLayerTreeModel::Flags f)
Sets OR-ed combination of model flags.
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
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...
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)
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
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:74
Provider interface to be implemented in order to introduce new kinds of embedded widgets for use in l...
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 nullptr, the node is a root node.
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group...
QPoint mLastReleaseMousePos
Used by the item delegate for identification of which indicator has been clicked. ...
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...
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
void collapseAllNodes()
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes...
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
void keyPressEvent(QKeyEvent *event) override
static QSet< QgsMapLayer * > collectMapLayersRecursive(const QList< QgsLayerTreeNode *> &nodes)
Returns map layers from the given list of layer tree nodes.
void currentLayerChanged(QgsMapLayer *layer)
Emitted when a current layer is changed.
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
void refreshLayerLegend(QgsLayerTreeLayer *nodeLayer)
Force a refresh of legend nodes of a layer node.
QgsLayerTreeViewDefaultActions * mDefaultActions
helper class with default actions. Lazily initialized.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Qt::ItemFlags flags(const QModelIndex &index) const override
void updateExpandedStateFromNode(QgsLayerTreeNode *node)
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
void onExpandedChanged(QgsLayerTreeNode *node, bool expanded)
Layer nodes may optionally include extra embedded widgets (if used in QgsLayerTreeView). Added in 2.16.
QgsLayerTreeModelLegendNode * currentLegendNode() const
Gets current legend node.
QgsLayerTreeViewMenuProvider * menuProvider() const
Returns pointer to the context menu provider. May be nullptr.
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
void dropEvent(QDropEvent *event) override
QgsMapLayer * layerForIndex(const QModelIndex &index) const
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 the currently selected layer.
QgsLayerTreeView(QWidget *parent=nullptr)
Constructor for QgsLayerTreeView.
void setMenuProvider(QgsLayerTreeViewMenuProvider *menuProvider)
Sets provider for context menu. Takes ownership of the instance.
~QgsLayerTreeView() override
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
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...
QList< QgsLayerTreeViewIndicator * > indicators(QgsLayerTreeNode *node) const
Returns list of indicators associated with a particular layer tree node.
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.
QgsLayerTreeNode * currentNode() const
Gets current node. May be nullptr.
QList< QgsMapLayer * > selectedLayersRecursive() const
Gets list of selected layers, including those that are not directly selected, but their ancestor grou...