QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 ) ) );
96  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayer ) );
97  return a;
98 }
99 
101 {
102  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ),
103  tr( "&Zoom to Selection" ), parent );
104  a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
105  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
106  return a;
107 }
108 
110 {
111  QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
112  tr( "&Zoom to Group" ), parent );
113  a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
114  connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
115  return a;
116 }
117 
119 {
120  QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
122  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
124  return a;
125 }
126 
128 {
129  QAction *a = new QAction( tr( "Move Out of &Group" ), parent );
130  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
131  return a;
132 }
133 
135 {
136  QAction *a = new QAction( tr( "Move to &Top" ), parent );
137  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
138  return a;
139 }
140 
142 {
143  QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
144  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
145  return a;
146 }
147 
149 {
150  QAction *a = new QAction( tr( "&Group Selected" ), parent );
151  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
152  return a;
153 }
154 
156 {
158  if ( !node || !QgsLayerTree::isGroup( node ) )
159  return nullptr;
160 
161  QAction *a = new QAction( tr( "Mutually Exclusive Group" ), parent );
162  a->setCheckable( true );
163  a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
164  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
165  return a;
166 }
167 
169 {
171  if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
172  return nullptr;
173 #ifdef Q_OS_MACX
174  QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
175 #else
176  QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
177 #endif
178  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
179  return a;
180 }
181 
183 {
185  if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
186  return nullptr;
187 #ifdef Q_OS_MACX
188  QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
189 #else
190  QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
191 #endif
192  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
193  return a;
194 }
195 
197 {
199  if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
200  return nullptr;
201  QAction *a = new QAction( tr( "Check and All its Parents" ), parent );
202  connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
203  return a;
204 }
205 
206 void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
207 {
209  if ( !node )
210  return;
211  node->setItemVisibilityCheckedRecursive( true );
212 }
213 
214 void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
215 {
217  if ( !node )
218  return;
219  node->setItemVisibilityCheckedRecursive( false );
220 }
221 
222 void QgsLayerTreeViewDefaultActions::checkAndAllParents()
223 {
225  if ( !node )
226  return;
228 }
229 
231 {
232  if ( mView->selectedNodes( true ).count() >= 2 )
233  {
234  groupSelected();
235  return;
236  }
238  if ( !group )
239  group = mView->layerTreeModel()->rootGroup();
240 
241  QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
242  mView->edit( mView->layerTreeModel()->node2index( newGroup ) );
243 }
244 
246 {
247  const auto constSelectedNodes = mView->selectedNodes( true );
248  for ( QgsLayerTreeNode *node : constSelectedNodes )
249  {
250  // could be more efficient if working directly with ranges instead of individual nodes
251  qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
252  }
253 }
254 
256 {
257  mView->edit( mView->currentIndex() );
258 }
259 
261 {
263  if ( !node )
264  return;
265  int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
266  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
267  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
268  l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
269 }
270 
272 {
274  if ( !QgsLayerTree::isLayer( node ) )
275  return;
276 
277  int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
278  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
279  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
280  l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
281 }
282 
283 
285 {
286  QgsMapLayer *layer = mView->currentLayer();
287  if ( !layer )
288  return;
289 
290  QList<QgsMapLayer *> layers;
291  layers << layer;
292  zoomToLayers( canvas, layers );
293 }
294 
296 {
297  QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );
298  if ( !layer )
299  return;
300 
301  canvas->zoomToSelected( layer );
302 }
303 
305 {
306  QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
307  if ( !groupNode )
308  return;
309 
310  QList<QgsMapLayer *> layers;
311  const auto constFindLayerIds = groupNode->findLayerIds();
312  for ( const QString &layerId : constFindLayerIds )
313  layers << QgsProject::instance()->mapLayer( layerId );
314 
315  zoomToLayers( canvas, layers );
316 }
317 
319 {
320  QAction *s = qobject_cast<QAction *>( sender() );
321  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
322  QApplication::setOverrideCursor( Qt::WaitCursor );
323  zoomToLayer( canvas );
324  QApplication::restoreOverrideCursor();
325 }
326 
328 {
329  QAction *s = qobject_cast<QAction *>( sender() );
330  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
331  QgsTemporaryCursorOverride waitCursor( Qt::WaitCursor );
332  zoomToSelection( canvas );
333 }
334 
336 {
337  QAction *s = qobject_cast<QAction *>( sender() );
338  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
339  QApplication::setOverrideCursor( Qt::WaitCursor );
340  zoomToGroup( canvas );
341  QApplication::restoreOverrideCursor();
342 }
343 
344 
345 void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
346 {
347  QgsRectangle extent;
348  extent.setMinimal();
349 
350  for ( int i = 0; i < layers.size(); ++i )
351  {
352  QgsMapLayer *layer = layers.at( i );
353  QgsRectangle layerExtent = layer->extent();
354 
355  QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
356  if ( vLayer )
357  {
358  if ( vLayer->geometryType() == QgsWkbTypes::NullGeometry )
359  continue;
360 
361  if ( layerExtent.isEmpty() )
362  {
363  vLayer->updateExtents();
364  layerExtent = vLayer->extent();
365  }
366  }
367 
368  if ( layerExtent.isNull() )
369  continue;
370 
371  //transform extent
372  layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
373 
374  extent.combineExtentWith( layerExtent );
375  }
376 
377  if ( extent.isNull() )
378  return;
379 
380  // Increase bounding box with 5%, so that layer is a bit inside the borders
381  extent.scale( 1.05 );
382 
383  //zoom to bounding box
384  canvas->setExtent( extent, true );
385  canvas->refresh();
386 }
387 
388 
390 {
391  QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
392  QString newName = prefix + '1';
393  for ( int i = 2; parentGroup->findGroup( newName ); ++i )
394  newName = prefix + QString::number( i );
395  return newName;
396 }
397 
398 
400 {
401  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
402  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
403  {
404  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
405  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
406  if ( !parentGroup || parentGroup == rootGroup )
407  continue;
408  QgsLayerTreeLayer *clonedLayer = l->clone();
409  rootGroup->addChildNode( clonedLayer );
410  parentGroup->removeChildNode( l );
411  }
412 }
413 
414 
416 {
417  const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
418  for ( QgsLayerTreeLayer *l : selectedLayerNodes )
419  {
420  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
421  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
422  if ( !parentGroup || parentGroup == rootGroup )
423  continue;
424  QgsLayerTreeGroup *tempGroup = parentGroup;
425  while ( tempGroup->parent() != rootGroup )
426  {
427  tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
428  }
429  QgsLayerTreeLayer *clonedLayer = l->clone();
430  int insertIdx = rootGroup->children().indexOf( tempGroup );
431  rootGroup->insertChildNode( insertIdx, clonedLayer );
432  parentGroup->removeChildNode( l );
433  }
434 }
435 
436 
438 {
439  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
440  std::reverse( selectedNodes.begin(), selectedNodes.end() );
441  // sort the nodes by depth first to avoid moving a group before its contents
442  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
443  {
444  return a->depth() > b->depth();
445  } );
446  for ( QgsLayerTreeNode *n : qgis::as_const( selectedNodes ) )
447  {
448  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
449  QgsLayerTreeNode *clonedNode = n->clone();
450  parentGroup->insertChildNode( 0, clonedNode );
451  parentGroup->removeChildNode( n );
452  }
453 }
454 
455 
457 {
458  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
459  // sort the nodes by depth first to avoid moving a group before its contents
460  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
461  {
462  return a->depth() > b->depth();
463  } );
464  for ( QgsLayerTreeNode *n : qgis::as_const( selectedNodes ) )
465  {
466  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
467  QgsLayerTreeNode *clonedNode = n->clone();
468  parentGroup->insertChildNode( -1, clonedNode );
469  parentGroup->removeChildNode( n );
470  }
471 }
472 
473 
475 {
476  const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
477  if ( nodes.count() < 2 || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
478  return;
479 
480  QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
481  int insertIdx = parentGroup->children().indexOf( nodes[0] );
482 
483  QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
484  for ( QgsLayerTreeNode *node : nodes )
485  newGroup->addChildNode( node->clone() );
486 
487  parentGroup->insertChildNode( insertIdx, newGroup );
488 
489  for ( QgsLayerTreeNode *node : nodes )
490  {
491  QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
492  if ( group )
493  group->removeChildNode( node );
494  }
495 
496  mView->setCurrentIndex( mView->layerTreeModel()->node2index( newGroup ) );
497  mView->edit( mView->layerTreeModel()->node2index( newGroup ) );
498 }
499 
501 {
503  if ( !node || !QgsLayerTree::isGroup( node ) )
504  return;
505 
506  QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
507 }
QgsLayerTreeView::currentGroupNode
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group....
Definition: qgslayertreeview.cpp:355
QgsLayerTreeNode
Definition: qgslayertreenode.h:74
QgsLayerTreeViewDefaultActions::uniqueGroupName
QString uniqueGroupName(QgsLayerTreeGroup *parentGroup)
Definition: qgslayertreeviewdefaultactions.cpp:389
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:605
QgsMapCanvas::refresh
void refresh()
Repaints the canvas map.
Definition: qgsmapcanvas.cpp:524
QgsVectorLayer::updateExtents
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Definition: qgsvectorlayer.cpp:801
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:132
QgsLayerTreeViewDefaultActions::showFeatureCount
void showFeatureCount()
Definition: qgslayertreeviewdefaultactions.cpp:271
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:359
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:456
qgsmapcanvas.h
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:145
QgsLayerTreeViewDefaultActions::actionZoomToGroup
QAction * actionZoomToGroup(QgsMapCanvas *canvas, QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:109
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:390
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:369
QgsLayerTreeView::layerTreeModel
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
Definition: qgslayertreeview.cpp:103
QgsLayerTreeViewDefaultActions::makeTopLevel
Q_DECL_DEPRECATED void makeTopLevel()
Definition: qgslayertreeviewdefaultactions.cpp:399
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsLayerTreeViewDefaultActions::renameGroupOrLayer
void renameGroupOrLayer()
Definition: qgslayertreeviewdefaultactions.cpp:255
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:458
QgsLayerTreeViewDefaultActions::actionMoveToBottom
QAction * actionMoveToBottom(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:141
QgsMapSettings::layerExtentToOutputExtent
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:432
QgsLayerTreeView::selectedNodes
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
Definition: qgslayertreeview.cpp:382
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3124
QgsLayerTreeViewDefaultActions::actionCheckAndAllChildren
QAction * actionCheckAndAllChildren(QObject *parent=nullptr)
Action to check a group and all its children.
Definition: qgslayertreeviewdefaultactions.cpp:168
QgsLayerTreeViewDefaultActions::moveOutOfGroup
void moveOutOfGroup()
Moves selected layer(s) out of the group(s) and places this/these above the group(s)
Definition: qgslayertreeviewdefaultactions.cpp:415
QgsLayerTreeNode::setItemVisibilityCheckedParentRecursive
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
Definition: qgslayertreenode.cpp:91
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:109
QgsRectangle
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:148
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:752
QgsRectangle::scale
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:235
QgsLayerTreeModel::node2index
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...
Definition: qgslayertreemodel.cpp:455
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:437
QgsLayerTreeViewDefaultActions::removeGroupOrLayer
void removeGroupOrLayer()
Definition: qgslayertreeviewdefaultactions.cpp:245
QgsLayerTreeViewDefaultActions::zoomToGroup
void zoomToGroup()
Definition: qgslayertreeviewdefaultactions.cpp:335
QgsLayerTreeViewDefaultActions::actionUncheckAndAllChildren
QAction * actionUncheckAndAllChildren(QObject *parent=nullptr)
Action to uncheck a group and all its children.
Definition: qgslayertreeviewdefaultactions.cpp:182
QgsLayerTreeNode::isItemVisibilityUncheckedRecursive
bool isItemVisibilityUncheckedRecursive() const
Returns whether this node is unchecked and all its children.
Definition: qgslayertreenode.cpp:123
QgsMapCanvas::zoomToSelected
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
Definition: qgsmapcanvas.cpp:1238
QgsLayerTreeViewDefaultActions::actionZoomToLayer
QAction * actionZoomToLayer(QgsMapCanvas *canvas, QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:91
QgsMapLayer::extent
virtual QgsRectangle extent() const
Returns the extent of the layer.
Definition: qgsmaplayer.cpp:197
QgsLayerTreeViewDefaultActions::actionMakeTopLevel
Q_DECL_DEPRECATED QAction * actionMakeTopLevel(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:118
QgsLayerTreeViewDefaultActions::groupSelected
void groupSelected()
Definition: qgslayertreeviewdefaultactions.cpp:474
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup
void mutuallyExclusiveGroup()
Slot to enable/disable mutually exclusive group flag.
Definition: qgslayertreeviewdefaultactions.cpp:500
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsLayerTreeView::currentNode
QgsLayerTreeNode * currentNode() const
Gets current node. May be nullptr.
Definition: qgslayertreeview.cpp:350
QgsLayerTreeViewDefaultActions::addGroup
void addGroup()
Definition: qgslayertreeviewdefaultactions.cpp:230
QgsMapCanvas::setExtent
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
Definition: qgsmapcanvas.cpp:1060
QgsLayerTreeViewDefaultActions::QgsLayerTreeViewDefaultActions
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
Definition: qgslayertreeviewdefaultactions.cpp:28
qgslayertree.h
QgsLayerTreeViewDefaultActions::actionMoveToTop
QAction * actionMoveToTop(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:134
QgsLayerTreeViewDefaultActions
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:518
QgsLayerTreeViewDefaultActions::showInOverview
void showInOverview()
Definition: qgslayertreeviewdefaultactions.cpp:260
QgsVectorLayer::extent
QgsRectangle extent() const FINAL
Returns the extent of the layer.
Definition: qgsvectorlayer.cpp:833
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:86
QgsLayerTreeViewDefaultActions::actionMoveOutOfGroup
QAction * actionMoveOutOfGroup(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:127
QgsLayerTreeGroup::insertChildNode
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
Definition: qgslayertreegroup.cpp:92
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:196
QgsLayerTreeViewDefaultActions::zoomToLayers
void zoomToLayers(QgsMapCanvas *canvas, const QList< QgsMapLayer * > &layers)
Definition: qgslayertreeviewdefaultactions.cpp:345
qgslayertreeview.h
QgsLayerTreeGroup::findLayerIds
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
Definition: qgslayertreegroup.cpp:397
QgsLayerTreeView::currentLayer
QgsMapLayer * currentLayer() const
Returns the currently selected layer, or nullptr if no layers is selected.
Definition: qgslayertreeview.cpp:121
QgsLayerTreeViewDefaultActions::zoomToSelection
void zoomToSelection()
Slot to zoom to selected features of a vector layer.
Definition: qgslayertreeviewdefaultactions.cpp:327
QgsLayerTreeViewDefaultActions::actionShowInOverview
QAction * actionShowInOverview(QObject *parent=nullptr)
Definition: qgslayertreeviewdefaultactions.cpp:48
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsLayerTreeGroup::addChildNode
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
Definition: qgslayertreegroup.cpp:127
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:189
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsLayerTreeViewDefaultActions::mView
QgsLayerTreeView * mView
Definition: qgslayertreeviewdefaultactions.h:168
QgsLayerTreeView::selectedLayerNodes
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
Definition: qgslayertreeview.cpp:387
QgsLayerTreeNode::children
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Definition: qgslayertreenode.h:112
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:155
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:110
QgsLayerTreeView
Definition: qgslayertreeview.h:51
QgsLayerTreeViewDefaultActions::zoomToLayer
void zoomToLayer()
Definition: qgslayertreeviewdefaultactions.cpp:318
QgsRectangle::setMinimal
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:151
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:98
QgsLayerTreeViewDefaultActions::actionZoomToSelection
QAction * actionZoomToSelection(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to selected features of a vector layer.
Definition: qgslayertreeviewdefaultactions.cpp:100
QgsLayerTreeGroup::addGroup
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
Definition: qgslayertreegroup.cpp:65
QgsLayerTreeGroup::findGroup
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
Definition: qgslayertreegroup.cpp:236
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:751
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:437
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:447
qgsproject.h
QgsTemporaryCursorOverride
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:203
qgslayertreeviewdefaultactions.h