QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgslayertreeviewdefaultactions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreeviewdefaultactions.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 
17 #include "qgsguiutils.h"
18 #include "qgsapplication.h"
19 #include "qgslayertree.h"
20 #include "qgslayertreemodel.h"
21 #include "qgslayertreeview.h"
22 #include "qgsmapcanvas.h"
23 #include "qgsproject.h"
24 #include "qgsvectorlayer.h"
25 
26 #include <QAction>
27 
29  : QObject( view )
30  , mView( view )
31 {
32 }
33 
35 {
36  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddGroup.svg" ) ), tr( "&Add Group" ), parent );
37  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::addGroup );
38  return a;
39 }
40 
42 {
43  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ), tr( "&Remove" ), parent );
44  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupOrLayer );
45  return a;
46 }
47 
49 {
51  if ( !node )
52  return nullptr;
53 
54  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInOverview.svg" ) ), tr( "Show in &Overview" ), parent );
55  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showInOverview );
56  a->setCheckable( true );
57  a->setChecked( node->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
58  return a;
59 }
60 
62 {
64  if ( !node )
65  return nullptr;
66 
67  QString text;
68  if ( QgsLayerTree::isGroup( node ) )
69  text = tr( "Re&name Group" );
70  else
71  text = tr( "Re&name Layer" );
72 
73  QAction *a = new QAction( text, parent );
74  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::renameGroupOrLayer );
75  return a;
76 }
77 
79 {
81  if ( !node )
82  return nullptr;
83 
84  QAction *a = new QAction( tr( "Show Feature &Count" ), parent );
85  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showFeatureCount );
86  a->setCheckable( true );
87  a->setChecked( node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() );
88  return a;
89 }
90 
92 {
93  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
94  tr( "&Zoom to Layer" ), parent );
95  a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
97  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayer ) );
99  return a;
100 }
101 
103 {
104  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
105  tr( "&Zoom to Layer(s)" ), parent );
106  a->setData( QVariant::fromValue( canvas ) );
107  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
108  return a;
109 }
110 
112 {
113  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ),
114  tr( "Zoom to &Selection" ), parent );
115  a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
116  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
117  return a;
118 }
119 
121 {
122  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
123  tr( "&Zoom to Group" ), parent );
124  a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
125  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
126  return a;
127 }
128 
130 {
131  QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
133  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
135  return a;
136 }
137 
139 {
140  QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
141  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
142  return a;
143 }
144 
146 {
147  QAction *a = new QAction( tr( "Move to &Top" ), parent );
148  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
149  return a;
150 }
151 
153 {
154  QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
155  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
156  return a;
157 }
158 
160 {
161  QAction *a = new QAction( tr( "&Group Selected" ), parent );
162  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
163  return a;
164 }
165 
167 {
169  if ( !node || !QgsLayerTree::isGroup( node ) )
170  return nullptr;
171 
172  QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
173  a->setCheckable( true );
174  a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
175  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
176  return a;
177 }
178 
180 {
182  if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
183  return nullptr;
184 #ifdef Q_OS_MACX
185  QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
186 #else
187  QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
188 #endif
189  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
190  return a;
191 }
192 
194 {
196  if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
197  return nullptr;
198 #ifdef Q_OS_MACX
199  QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
200 #else
201  QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
202 #endif
203  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
204  return a;
205 }
206 
208 {
210  if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
211  return nullptr;
212  QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
213  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
214  return a;
215 }
216 
217 void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
218 {
220  if ( !node )
221  return;
222  node->setItemVisibilityCheckedRecursive( true );
223 }
224 
225 void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
226 {
228  if ( !node )
229  return;
230  node->setItemVisibilityCheckedRecursive( false );
231 }
232 
233 void QgsLayerTreeViewDefaultActions::checkAndAllParents()
234 {
236  if ( !node )
237  return;
239 }
240 
242 {
243  int nodeCount = mView->selectedNodes( true ).count();
244  if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
245  {
246  groupSelected();
247  return;
248  }
250  if ( !group )
251  group = mView->layerTreeModel()->rootGroup();
252 
253  QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
254  mView->edit( mView->node2index( newGroup ) );
255 }
256 
258 {
259  const auto constSelectedNodes = mView->selectedNodes( true );
260  for ( QgsLayerTreeNode *node : constSelectedNodes )
261  {
262  // could be more efficient if working directly with ranges instead of individual nodes
263  qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
264  }
265 }
266 
268 {
269  mView->edit( mView->currentIndex() );
270 }
271 
273 {
275  if ( !node )
276  return;
277  int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
278  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
279  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
280  l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
281 }
282 
284 {
286  if ( !QgsLayerTree::isLayer( node ) )
287  return;
288 
289  int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
290  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
291  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
292  l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
293 }
294 
296 {
297  QgsMapLayer *layer = mView->currentLayer();
298  if ( !layer )
299  return;
300 
301  const QList<QgsMapLayer *> layers { layer };
302  zoomToLayers( canvas, layers );
303 }
304 
306 {
307  const QList<QgsMapLayer *> layers = mView->selectedLayers();
308 
309  zoomToLayers( canvas, layers );
310 }
311 
313 {
314  QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( mView->currentLayer() );
315 
316  const QList<QgsMapLayer *> layers = mView->selectedLayers();
317 
318  if ( layers.size() > 1 )
319  canvas->zoomToSelected( layers );
320  else if ( layers.size() <= 1 && layer )
321  canvas->zoomToSelected( layer );
322 
323 }
324 
326 {
327  QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
328  if ( !groupNode )
329  return;
330 
331  QList<QgsMapLayer *> layers;
332  const QStringList findLayerIds = groupNode->findLayerIds();
333  for ( const QString &layerId : findLayerIds )
334  layers << QgsProject::instance()->mapLayer( layerId );
335 
336  zoomToLayers( canvas, layers );
337 }
338 
340 {
342  QAction *s = qobject_cast<QAction *>( sender() );
343  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
344 
345  zoomToLayer( canvas );
347 }
348 
350 {
351  QAction *s = qobject_cast<QAction *>( sender() );
352  QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
353  zoomToLayers( canvas );
354 }
355 
357 {
358  QAction *s = qobject_cast<QAction *>( sender() );
359  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
360  zoomToSelection( canvas );
361 }
362 
364 {
365  QAction *s = qobject_cast<QAction *>( sender() );
366  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
367  zoomToGroup( canvas );
368 }
369 
370 void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
371 {
372  QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
373 
374  QgsRectangle extent;
375  extent.setMinimal();
376 
377  if ( !layers.empty() )
378  {
379  for ( int i = 0; i < layers.size(); ++i )
380  {
381  QgsMapLayer *layer = layers.at( i );
382  QgsRectangle layerExtent = layer->extent();
383 
384  QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
385  if ( vLayer )
386  {
387  if ( vLayer->geometryType() == QgsWkbTypes::NullGeometry )
388  continue;
389 
390  if ( layerExtent.isEmpty() )
391  {
392  vLayer->updateExtents();
393  layerExtent = vLayer->extent();
394  }
395  }
396 
397  if ( layerExtent.isNull() )
398  continue;
399 
400  //transform extent
401  layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
402 
403  extent.combineExtentWith( layerExtent );
404  }
405  }
406 
407  // If no layer is selected, use current layer
408  else if ( mView->currentLayer() )
409  {
410  QgsRectangle layerExtent = mView->currentLayer()->extent();
411  layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
412  extent.combineExtentWith( layerExtent );
413  }
414 
415  if ( extent.isNull() )
416  return;
417 
418  // Increase bounding box with 5%, so that layer is a bit inside the borders
419  extent.scale( 1.05 );
420 
421  //zoom to bounding box
422  canvas->setExtent( extent, true );
423  canvas->refresh();
424 }
425 
426 
428 {
429  QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
430  QString newName = prefix + '1';
431  for ( int i = 2; parentGroup->findGroup( newName ); ++i )
432  newName = prefix + QString::number( i );
433  return newName;
434 }
435 
436 
438 {
439  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
440  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
441  {
442  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
443  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
444  if ( !parentGroup || parentGroup == rootGroup )
445  continue;
446  QgsLayerTreeLayer *clonedLayer = l->clone();
447  rootGroup->addChildNode( clonedLayer );
448  parentGroup->removeChildNode( l );
449  }
450 }
451 
452 
454 {
455  const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
456  for ( QgsLayerTreeLayer *l : selectedLayerNodes )
457  {
458  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
459  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
460  if ( !parentGroup || parentGroup == rootGroup )
461  continue;
462  QgsLayerTreeGroup *tempGroup = parentGroup;
463  while ( tempGroup->parent() != rootGroup )
464  {
465  tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
466  }
467  QgsLayerTreeLayer *clonedLayer = l->clone();
468  int insertIdx = rootGroup->children().indexOf( tempGroup );
469  rootGroup->insertChildNode( insertIdx, clonedLayer );
470  parentGroup->removeChildNode( l );
471  }
472 }
473 
474 
476 {
477  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
478  std::reverse( selectedNodes.begin(), selectedNodes.end() );
479  // sort the nodes by depth first to avoid moving a group before its contents
480  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
481  {
482  return a->depth() > b->depth();
483  } );
484  for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
485  {
486  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
487  QgsLayerTreeNode *clonedNode = n->clone();
488  parentGroup->insertChildNode( 0, clonedNode );
489  parentGroup->removeChildNode( n );
490  }
491 }
492 
493 
495 {
496  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
497  // sort the nodes by depth first to avoid moving a group before its contents
498  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
499  {
500  return a->depth() > b->depth();
501  } );
502  for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
503  {
504  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
505  QgsLayerTreeNode *clonedNode = n->clone();
506  parentGroup->insertChildNode( -1, clonedNode );
507  parentGroup->removeChildNode( n );
508  }
509 }
510 
511 
513 {
514  const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
515  if ( nodes.empty() || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
516  return;
517 
518  QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
519  int insertIdx = parentGroup->children().indexOf( nodes[0] );
520 
521  QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
522  for ( QgsLayerTreeNode *node : nodes )
523  newGroup->addChildNode( node->clone() );
524 
525  parentGroup->insertChildNode( insertIdx, newGroup );
526 
527  for ( QgsLayerTreeNode *node : nodes )
528  {
529  QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
530  if ( group )
531  group->removeChildNode( node );
532  }
533 
534  mView->setCurrentIndex( mView->node2index( newGroup ) );
535  mView->edit( mView->node2index( newGroup ) );
536 }
537 
539 {
541  if ( !node || !QgsLayerTree::isGroup( node ) )
542  return;
543 
544  QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
545 }
QgsLayerTreeView::currentGroupNode
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group....
Definition: qgslayertreeview.cpp:387
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsLayerTreeViewDefaultActions::uniqueGroupName
QString uniqueGroupName(QgsLayerTreeGroup *parentGroup)
Definition: qgslayertreeviewdefaultactions.cpp:427
QgsMapCanvas::refresh
void refresh()
Repaints the canvas map.
Definition: qgsmapcanvas.cpp:643
QgsVectorLayer::updateExtents
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Definition: qgsvectorlayer.cpp:862
QgsLayerTreeViewDefaultActions::actionRemoveGroupOrLayer
QAction * actionRemoveGroupOrLayer(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:41
QgsLayerTreeGroup::removeChildNode
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
Definition: qgslayertreegroup.cpp:150
QgsLayerTreeViewDefaultActions::showFeatureCount
void showFeatureCount()
Definition: qgslayertreeviewdefaultactions.cpp:283
QgsRectangle::combineExtentWith
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:391
QgsLayerTreeViewDefaultActions::moveToBottom
void moveToBottom()
Moves selected layer(s) and/or group(s) to the bottom of the layer panel or the bottom of the group i...
Definition: qgslayertreeviewdefaultactions.cpp:494
qgsmapcanvas.h
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsLayerTreeViewDefaultActions::actionZoomToGroup
QAction * actionZoomToGroup(QgsMapCanvas *canvas, QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:120
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:437
QgsLayerTreeGroup::setIsMutuallyExclusive
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
Definition: qgslayertreegroup.cpp:433
QgsLayerTreeView::layerTreeModel
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
Definition: qgslayertreeview.cpp:123
QgsLayerTreeViewDefaultActions::makeTopLevel
Q_DECL_DEPRECATED void makeTopLevel()
Definition: qgslayertreeviewdefaultactions.cpp:437
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsLayerTreeViewDefaultActions::actionZoomToLayers
QAction * actionZoomToLayers(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to all the selected layer(s) in the layer tree.
Definition: qgslayertreeviewdefaultactions.cpp:102
QgsLayerTreeViewDefaultActions::renameGroupOrLayer
void renameGroupOrLayer()
Definition: qgslayertreeviewdefaultactions.cpp:267
QgsRectangle::setMinimal
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:172
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsLayerTreeViewDefaultActions::actionMoveToBottom
QAction * actionMoveToBottom(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:152
QgsMapSettings::layerExtentToOutputExtent
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:528
QgsLayerTreeView::selectedNodes
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
Definition: qgslayertreeview.cpp:414
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3680
QgsLayerTreeViewDefaultActions::actionCheckAndAllChildren
QAction * actionCheckAndAllChildren(QObject *parent=nullptr)
Action to check a group and all its children.
Definition: qgslayertreeviewdefaultactions.cpp:179
QgsLayerTreeViewDefaultActions::moveOutOfGroup
void moveOutOfGroup()
Moves selected layer(s) out of the group(s) and places this/these above the group(s)
Definition: qgslayertreeviewdefaultactions.cpp:453
QgsLayerTreeNode::setItemVisibilityCheckedParentRecursive
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
Definition: qgslayertreenode.cpp:108
QgsLayerTreeViewDefaultActions::actionShowFeatureCount
QAction * actionShowFeatureCount(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:78
QgsLayerTreeNode::isItemVisibilityCheckedRecursive
bool isItemVisibilityCheckedRecursive() const
Returns whether this node is checked and all its children.
Definition: qgslayertreenode.cpp:126
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsLayerTree::toGroup
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:77
qgsapplication.h
QgsLayerTreeViewDefaultActions::actionAddGroup
QAction * actionAddGroup(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:34
QgsLayerTreeViewDefaultActions::actionGroupSelected
QAction * actionGroupSelected(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:159
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:2820
QgsRectangle::scale
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:256
QgsLayerTreeViewDefaultActions::moveToTop
void moveToTop()
Moves selected layer(s) and/or group(s) to the top of the layer panel or the top of the group if the ...
Definition: qgslayertreeviewdefaultactions.cpp:475
QgsLayerTreeViewDefaultActions::removeGroupOrLayer
void removeGroupOrLayer()
Definition: qgslayertreeviewdefaultactions.cpp:257
QgsLayerTreeViewDefaultActions::zoomToLayers
void zoomToLayers()
Zooms to the combined extent of all the selected layer(s) in the layer tree.
Definition: qgslayertreeviewdefaultactions.cpp:349
QgsLayerTreeViewDefaultActions::zoomToGroup
void zoomToGroup()
Definition: qgslayertreeviewdefaultactions.cpp:363
QgsLayerTreeViewDefaultActions::actionUncheckAndAllChildren
QAction * actionUncheckAndAllChildren(QObject *parent=nullptr)
Action to uncheck a group and all its children.
Definition: qgslayertreeviewdefaultactions.cpp:193
QgsLayerTreeNode::isItemVisibilityUncheckedRecursive
bool isItemVisibilityUncheckedRecursive() const
Returns whether this node is unchecked and all its children.
Definition: qgslayertreenode.cpp:140
QgsMapCanvas::zoomToSelected
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
Definition: qgsmapcanvas.cpp:1597
QgsLayerTreeViewDefaultActions::actionZoomToLayer
Q_DECL_DEPRECATED QAction * actionZoomToLayer(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to the active layer from the layer tree.
Definition: qgslayertreeviewdefaultactions.cpp:91
QgsMapLayer::extent
virtual QgsRectangle extent() const
Returns the extent of the layer.
Definition: qgsmaplayer.cpp:305
QgsLayerTreeViewDefaultActions::actionMakeTopLevel
Q_DECL_DEPRECATED QAction * actionMakeTopLevel(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:129
QgsLayerTreeViewDefaultActions::groupSelected
void groupSelected()
Definition: qgslayertreeviewdefaultactions.cpp:512
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup
void mutuallyExclusiveGroup()
Slot to enable/disable mutually exclusive group flag.
Definition: qgslayertreeviewdefaultactions.cpp:538
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
QgsLayerTreeView::currentNode
QgsLayerTreeNode * currentNode() const
Gets current node. May be nullptr.
Definition: qgslayertreeview.cpp:382
QgsLayerTreeViewDefaultActions::addGroup
void addGroup()
Definition: qgslayertreeviewdefaultactions.cpp:241
QgsLayerTreeView::node2index
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns proxy model index for a given node.
Definition: qgslayertreeview.cpp:703
QgsMapCanvas::setExtent
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
Definition: qgsmapcanvas.cpp:1359
QgsLayerTreeViewDefaultActions::QgsLayerTreeViewDefaultActions
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
Definition: qgslayertreeviewdefaultactions.cpp:28
QgsLayerTreeView::selectedLayers
QList< QgsMapLayer * > selectedLayers() const
Gets list of selected layers.
Definition: qgslayertreeview.cpp:437
qgslayertree.h
QgsLayerTreeViewDefaultActions::actionMoveToTop
QAction * actionMoveToTop(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:145
QgsLayerTreeViewDefaultActions
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
Definition: qgslayertreeviewdefaultactions.h:39
QgsLayerTreeModel::rootGroup
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
Definition: qgslayertreemodel.cpp:492
QgsLayerTreeViewDefaultActions::showInOverview
void showInOverview()
Definition: qgslayertreeviewdefaultactions.cpp:272
QgsVectorLayer::extent
QgsRectangle extent() const FINAL
Returns the extent of the layer.
Definition: qgsvectorlayer.cpp:894
qgsvectorlayer.h
QgsLayerTreeNode::setItemVisibilityCheckedRecursive
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
Definition: qgslayertreenode.cpp:103
QgsLayerTreeViewDefaultActions::actionMoveOutOfGroup
QAction * actionMoveOutOfGroup(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:138
QgsLayerTreeGroup::insertChildNode
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
Definition: qgslayertreegroup.cpp:106
QgsLayerTree::isLayer
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:66
QgsLayerTreeViewDefaultActions::actionCheckAndAllParents
QAction * actionCheckAndAllParents(QObject *parent=nullptr)
Action to check a group and all its parents.
Definition: qgslayertreeviewdefaultactions.cpp:207
qgslayertreeview.h
QgsLayerTreeGroup::findLayerIds
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
Definition: qgslayertreegroup.cpp:498
QgsLayerTreeView::currentLayer
QgsMapLayer * currentLayer() const
Returns the currently selected layer, or nullptr if no layers is selected.
Definition: qgslayertreeview.cpp:141
QgsLayerTreeViewDefaultActions::zoomToSelection
void zoomToSelection()
Zooms to the bounding box of all selected features of a vector layer.
Definition: qgslayertreeviewdefaultactions.cpp:356
QgsLayerTreeViewDefaultActions::actionShowInOverview
QAction * actionShowInOverview(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:48
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsLayerTreeGroup::addChildNode
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
Definition: qgslayertreegroup.cpp:143
QgsLayerTreeNode::customProperty
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.
Definition: qgslayertreenode.cpp:217
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsLayerTreeViewDefaultActions::mView
QgsLayerTreeView * mView
Definition: qgslayertreeviewdefaultactions.h:200
QgsLayerTreeView::selectedLayerNodes
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
Definition: qgslayertreeview.cpp:425
QgsLayerTreeNode::children
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Definition: qgslayertreenode.h:121
QgsLayerTreeLayer::clone
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
Definition: qgslayertreelayer.cpp:188
QgsLayerTreeNode::clone
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
QgsLayerTreeViewDefaultActions::actionMutuallyExclusiveGroup
QAction * actionMutuallyExclusiveGroup(QObject *parent=nullptr)
Action to enable/disable mutually exclusive flag of a group (only one child node may be checked)
Definition: qgslayertreeviewdefaultactions.cpp:166
qgslayertreemodel.h
QgsLayerTreeViewDefaultActions::actionRenameGroupOrLayer
QAction * actionRenameGroupOrLayer(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:61
QgsLayerTreeNode::parent
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
Definition: qgslayertreenode.h:119
QgsLayerTreeView
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
Definition: qgslayertreeview.h:103
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsLayerTreeViewDefaultActions::zoomToLayer
Q_DECL_DEPRECATED void zoomToLayer()
Zooms to the extent of the active layer in the layer tree.
Definition: qgslayertreeviewdefaultactions.cpp:339
qgsguiutils.h
QgsLayerTreeNode::isVisible
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well)
Definition: qgslayertreenode.cpp:115
QgsLayerTreeViewDefaultActions::actionZoomToSelection
QAction * actionZoomToSelection(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to selected features of a vector layer.
Definition: qgslayertreeviewdefaultactions.cpp:111
QgsLayerTreeGroup::addGroup
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
Definition: qgslayertreegroup.cpp:75
QgsLayerTreeGroup::findGroup
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
Definition: qgslayertreegroup.cpp:290
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2819
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
QgsLayerTree::isGroup
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:56
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
qgsproject.h
QgsTemporaryCursorOverride
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:220
qgslayertreeviewdefaultactions.h