QGIS API Documentation  3.6.0-Noosa (5873452)
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  Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( parentNode ), true ) )
172  {
173  QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
174  if ( expandedNodeKeys.contains( ruleKey ) )
175  setExpanded( layerTreeModel()->legendNode2index( legendNode ), true );
176  }
177  return;
178  }
179 
180  QList<QgsLayerTreeNode *> children = parentNode->children();
181  for ( int i = start; i <= end; ++i )
182  {
183  updateExpandedStateFromNode( children[i] );
184  }
185 
186  // make sure we still have correct current layer
188 }
189 
191 {
192  // make sure we still have correct current layer
194 }
195 
196 void QgsLayerTreeView::updateExpandedStateToNode( const QModelIndex &index )
197 {
198  if ( QgsLayerTreeNode *node = layerTreeModel()->index2node( index ) )
199  {
200  node->setExpanded( isExpanded( index ) );
201  }
202  else if ( QgsLayerTreeModelLegendNode *node = layerTreeModel()->index2legendNode( index ) )
203  {
204  QString ruleKey = node->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
205  QStringList lst = node->layerNode()->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList();
206  bool expanded = isExpanded( index );
207  bool isInList = lst.contains( ruleKey );
208  if ( expanded && !isInList )
209  {
210  lst.append( ruleKey );
211  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
212  }
213  else if ( !expanded && isInList )
214  {
215  lst.removeAll( ruleKey );
216  node->layerNode()->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
217  }
218  }
219 }
220 
222 {
223  QgsMapLayer *layerCurrent = layerForIndex( currentIndex() );
224  QString layerCurrentID = layerCurrent ? layerCurrent->id() : QString();
225  if ( mCurrentLayerID == layerCurrentID )
226  return;
227 
228  // update the current index in model (the item will be underlined)
229  QModelIndex nodeLayerIndex;
230  if ( layerCurrent )
231  {
232  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerCurrentID );
233  if ( nodeLayer )
234  nodeLayerIndex = layerTreeModel()->node2index( nodeLayer );
235  }
236  layerTreeModel()->setCurrentIndex( nodeLayerIndex );
237 
238  mCurrentLayerID = layerCurrentID;
239  emit currentLayerChanged( layerCurrent );
240 }
241 
243 {
244  QModelIndex idx = layerTreeModel()->node2index( node );
245  if ( isExpanded( idx ) != expanded )
246  setExpanded( idx, expanded );
247 }
248 
249 void QgsLayerTreeView::onCustomPropertyChanged( QgsLayerTreeNode *node, const QString &key )
250 {
251  if ( key != QStringLiteral( "expandedLegendNodes" ) || !QgsLayerTree::isLayer( node ) )
252  return;
253 
254  QSet<QString> expandedLegendNodes = node->customProperty( QStringLiteral( "expandedLegendNodes" ) ).toStringList().toSet();
255 
256  const QList<QgsLayerTreeModelLegendNode *> legendNodes = layerTreeModel()->layerLegendNodes( QgsLayerTree::toLayer( node ), true );
257  for ( QgsLayerTreeModelLegendNode *legendNode : legendNodes )
258  {
259  QString key = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
260  if ( !key.isEmpty() )
261  setExpanded( layerTreeModel()->legendNode2index( legendNode ), expandedLegendNodes.contains( key ) );
262  }
263 }
264 
266 {
268 }
269 
271 {
272  QModelIndex idx = layerTreeModel()->node2index( node );
273  setExpanded( idx, node->isExpanded() );
274 
275  Q_FOREACH ( QgsLayerTreeNode *child, node->children() )
277 }
278 
279 QgsMapLayer *QgsLayerTreeView::layerForIndex( const QModelIndex &index ) const
280 {
281  // Check if model has been set and index is valid
282  if ( layerTreeModel() && index.isValid() )
283  {
284  QgsLayerTreeNode *node = layerTreeModel()->index2node( index );
285  if ( node )
286  {
287  if ( QgsLayerTree::isLayer( node ) )
288  return QgsLayerTree::toLayer( node )->layer();
289  }
290  else
291  {
292  // possibly a legend node
294  if ( legendNode )
295  return legendNode->layerNode()->layer();
296  }
297  }
298  return nullptr;
299 }
300 
302 {
303  return layerTreeModel()->index2node( selectionModel()->currentIndex() );
304 }
305 
307 {
308  QgsLayerTreeNode *node = currentNode();
309  if ( QgsLayerTree::isGroup( node ) )
310  return QgsLayerTree::toGroup( node );
311  else if ( QgsLayerTree::isLayer( node ) )
312  {
313  QgsLayerTreeNode *parent = node->parent();
314  if ( QgsLayerTree::isGroup( parent ) )
315  return QgsLayerTree::toGroup( parent );
316  }
317 
318  if ( QgsLayerTreeModelLegendNode *legendNode = layerTreeModel()->index2legendNode( selectionModel()->currentIndex() ) )
319  {
320  QgsLayerTreeLayer *parent = legendNode->layerNode();
321  if ( QgsLayerTree::isGroup( parent->parent() ) )
322  return QgsLayerTree::toGroup( parent->parent() );
323  }
324 
325  return nullptr;
326 }
327 
329 {
330  return layerTreeModel()->index2legendNode( selectionModel()->currentIndex() );
331 }
332 
333 QList<QgsLayerTreeNode *> QgsLayerTreeView::selectedNodes( bool skipInternal ) const
334 {
335  return layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), skipInternal );
336 }
337 
338 QList<QgsLayerTreeLayer *> QgsLayerTreeView::selectedLayerNodes() const
339 {
340  QList<QgsLayerTreeLayer *> layerNodes;
341  Q_FOREACH ( QgsLayerTreeNode *node, selectedNodes() )
342  {
343  if ( QgsLayerTree::isLayer( node ) )
344  layerNodes << QgsLayerTree::toLayer( node );
345  }
346  return layerNodes;
347 }
348 
349 QList<QgsMapLayer *> QgsLayerTreeView::selectedLayers() const
350 {
351  QList<QgsMapLayer *> list;
352  Q_FOREACH ( QgsLayerTreeLayer *node, selectedLayerNodes() )
353  {
354  if ( node->layer() )
355  list << node->layer();
356  }
357  return list;
358 }
359 
360 QList<QgsMapLayer *> QgsLayerTreeView::selectedLayersRecursive() const
361 {
362  const QList<QgsLayerTreeNode *> nodes = layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), false );
363  QSet<QgsMapLayer *> layersSet = QgsLayerTreeUtils::collectMapLayersRecursive( nodes );
364  return layersSet.toList();
365 }
366 
368 {
369  if ( !mIndicators[node].contains( indicator ) )
370  mIndicators[node].append( indicator );
371 }
372 
374 {
375  mIndicators[node].removeOne( indicator );
376 }
377 
378 QList<QgsLayerTreeViewIndicator *> QgsLayerTreeView::indicators( QgsLayerTreeNode *node ) const
379 {
380  return mIndicators.value( node );
381 }
382 
384 QStringList QgsLayerTreeView::viewOnlyCustomProperties()
385 {
386  return QStringList() << QStringLiteral( "expandedLegendNodes" );
387 }
389 
390 void QgsLayerTreeView::refreshLayerSymbology( const QString &layerId )
391 {
392  QgsLayerTreeLayer *nodeLayer = layerTreeModel()->rootGroup()->findLayer( layerId );
393  if ( nodeLayer )
394  layerTreeModel()->refreshLayerLegend( nodeLayer );
395 }
396 
397 
398 static void _expandAllLegendNodes( QgsLayerTreeLayer *nodeLayer, bool expanded, QgsLayerTreeModel *model )
399 {
400  // for layers we also need to find out with legend nodes contain some children and make them expanded/collapsed
401  // if we are collapsing, we just write out an empty list
402  QStringList lst;
403  if ( expanded )
404  {
405  Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, model->layerLegendNodes( nodeLayer, true ) )
406  {
407  QString parentKey = legendNode->data( QgsLayerTreeModelLegendNode::ParentRuleKeyRole ).toString();
408  if ( !parentKey.isEmpty() && !lst.contains( parentKey ) )
409  lst << parentKey;
410  }
411  }
412  nodeLayer->setCustomProperty( QStringLiteral( "expandedLegendNodes" ), lst );
413 }
414 
415 
416 static void _expandAllNodes( QgsLayerTreeGroup *parent, bool expanded, QgsLayerTreeModel *model )
417 {
418  Q_FOREACH ( QgsLayerTreeNode *node, parent->children() )
419  {
420  node->setExpanded( expanded );
421  if ( QgsLayerTree::isGroup( node ) )
422  _expandAllNodes( QgsLayerTree::toGroup( node ), expanded, model );
423  else if ( QgsLayerTree::isLayer( node ) )
424  _expandAllLegendNodes( QgsLayerTree::toLayer( node ), expanded, model );
425  }
426 }
427 
428 
430 {
431  // unfortunately expandAll() does not emit expanded() signals
432  _expandAllNodes( layerTreeModel()->rootGroup(), true, layerTreeModel() );
433  expandAll();
434 }
435 
437 {
438  // unfortunately collapseAll() does not emit collapsed() signals
439  _expandAllNodes( layerTreeModel()->rootGroup(), false, layerTreeModel() );
440  collapseAll();
441 }
442 
443 void QgsLayerTreeView::mouseReleaseEvent( QMouseEvent *event )
444 {
445  // we need to keep last mouse position in order to know whether to emit an indicator's clicked() signal
446  // (the item delegate needs to know which indicator has been clicked)
447  mLastReleaseMousePos = event->pos();
448 
449  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
450  if ( event->modifiers() & Qt::ControlModifier )
452  else
454  QTreeView::mouseReleaseEvent( event );
455  layerTreeModel()->setFlags( oldFlags );
456 }
457 
458 void QgsLayerTreeView::keyPressEvent( QKeyEvent *event )
459 {
460  const QgsLayerTreeModel::Flags oldFlags = layerTreeModel()->flags();
461  if ( event->modifiers() & Qt::ControlModifier )
463  else
465  QTreeView::keyPressEvent( event );
466  layerTreeModel()->setFlags( oldFlags );
467 }
468 
469 void QgsLayerTreeView::dropEvent( QDropEvent *event )
470 {
471  if ( event->keyboardModifiers() & Qt::AltModifier )
472  {
473  event->accept();
474  }
475  QTreeView::dropEvent( event );
476 }
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:64
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
Gets currently selected layer. May be null.
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 null pointer 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 a null pointer, 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...
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-null pointer.
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 null.
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 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
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 null.
QList< QgsMapLayer * > selectedLayersRecursive() const
Gets list of selected layers, including those that are not directly selected, but their ancestor grou...