QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  if ( mView->selectedNodes( true ).count() >= 2 )
244  {
245  groupSelected();
246  return;
247  }
249  if ( !group )
250  group = mView->layerTreeModel()->rootGroup();
251 
252  QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
253  mView->edit( mView->node2index( newGroup ) );
254 }
255 
257 {
258  const auto constSelectedNodes = mView->selectedNodes( true );
259  for ( QgsLayerTreeNode *node : constSelectedNodes )
260  {
261  // could be more efficient if working directly with ranges instead of individual nodes
262  qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
263  }
264 }
265 
267 {
268  mView->edit( mView->currentIndex() );
269 }
270 
272 {
274  if ( !node )
275  return;
276  int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
277  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
278  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
279  l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
280 }
281 
283 {
285  if ( !QgsLayerTree::isLayer( node ) )
286  return;
287 
288  int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
289  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
290  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
291  l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
292 }
293 
295 {
296  QgsMapLayer *layer = mView->currentLayer();
297  if ( !layer )
298  return;
299 
300  const QList<QgsMapLayer *> layers { layer };
301  zoomToLayers( canvas, layers );
302 }
303 
305 {
306  const QList<QgsMapLayer *> layers = mView->selectedLayers();
307 
308  zoomToLayers( canvas, layers );
309 }
310 
312 {
313  QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( mView->currentLayer() );
314 
315  const QList<QgsMapLayer *> layers = mView->selectedLayers();
316 
317  if ( layers.size() > 1 )
318  canvas->zoomToSelected( layers );
319  else if ( layers.size() <= 1 && layer )
320  canvas->zoomToSelected( layer );
321 
322 }
323 
325 {
326  QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
327  if ( !groupNode )
328  return;
329 
330  QList<QgsMapLayer *> layers;
331  const QStringList findLayerIds = groupNode->findLayerIds();
332  for ( const QString &layerId : findLayerIds )
333  layers << QgsProject::instance()->mapLayer( layerId );
334 
335  zoomToLayers( canvas, layers );
336 }
337 
339 {
341  QAction *s = qobject_cast<QAction *>( sender() );
342  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
343 
344  zoomToLayer( canvas );
346 }
347 
349 {
350  QAction *s = qobject_cast<QAction *>( sender() );
351  QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
352  zoomToLayers( canvas );
353 }
354 
356 {
357  QAction *s = qobject_cast<QAction *>( sender() );
358  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
359  zoomToSelection( canvas );
360 }
361 
363 {
364  QAction *s = qobject_cast<QAction *>( sender() );
365  QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
366  zoomToGroup( canvas );
367 }
368 
369 void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
370 {
371  QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
372 
373  QgsRectangle extent;
374  extent.setMinimal();
375 
376  if ( !layers.empty() )
377  {
378  for ( int i = 0; i < layers.size(); ++i )
379  {
380  QgsMapLayer *layer = layers.at( i );
381  QgsRectangle layerExtent = layer->extent();
382 
383  QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
384  if ( vLayer )
385  {
386  if ( vLayer->geometryType() == QgsWkbTypes::NullGeometry )
387  continue;
388 
389  if ( layerExtent.isEmpty() )
390  {
391  vLayer->updateExtents();
392  layerExtent = vLayer->extent();
393  }
394  }
395 
396  if ( layerExtent.isNull() )
397  continue;
398 
399  //transform extent
400  layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
401 
402  extent.combineExtentWith( layerExtent );
403  }
404  }
405 
406  // If no layer is selected, use current layer
407  else if ( mView->currentLayer() )
408  {
409  QgsRectangle layerExtent = mView->currentLayer()->extent();
410  layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
411  extent.combineExtentWith( layerExtent );
412  }
413 
414  if ( extent.isNull() )
415  return;
416 
417  // Increase bounding box with 5%, so that layer is a bit inside the borders
418  extent.scale( 1.05 );
419 
420  //zoom to bounding box
421  canvas->setExtent( extent, true );
422  canvas->refresh();
423 }
424 
425 
427 {
428  QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
429  QString newName = prefix + '1';
430  for ( int i = 2; parentGroup->findGroup( newName ); ++i )
431  newName = prefix + QString::number( i );
432  return newName;
433 }
434 
435 
437 {
438  const auto constSelectedLayerNodes = mView->selectedLayerNodes();
439  for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
440  {
441  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
442  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
443  if ( !parentGroup || parentGroup == rootGroup )
444  continue;
445  QgsLayerTreeLayer *clonedLayer = l->clone();
446  rootGroup->addChildNode( clonedLayer );
447  parentGroup->removeChildNode( l );
448  }
449 }
450 
451 
453 {
454  const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
455  for ( QgsLayerTreeLayer *l : selectedLayerNodes )
456  {
457  QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
458  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
459  if ( !parentGroup || parentGroup == rootGroup )
460  continue;
461  QgsLayerTreeGroup *tempGroup = parentGroup;
462  while ( tempGroup->parent() != rootGroup )
463  {
464  tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
465  }
466  QgsLayerTreeLayer *clonedLayer = l->clone();
467  int insertIdx = rootGroup->children().indexOf( tempGroup );
468  rootGroup->insertChildNode( insertIdx, clonedLayer );
469  parentGroup->removeChildNode( l );
470  }
471 }
472 
473 
475 {
476  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
477  std::reverse( selectedNodes.begin(), selectedNodes.end() );
478  // sort the nodes by depth first to avoid moving a group before its contents
479  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
480  {
481  return a->depth() > b->depth();
482  } );
483  for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
484  {
485  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
486  QgsLayerTreeNode *clonedNode = n->clone();
487  parentGroup->insertChildNode( 0, clonedNode );
488  parentGroup->removeChildNode( n );
489  }
490 }
491 
492 
494 {
495  QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
496  // sort the nodes by depth first to avoid moving a group before its contents
497  std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
498  {
499  return a->depth() > b->depth();
500  } );
501  for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
502  {
503  QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
504  QgsLayerTreeNode *clonedNode = n->clone();
505  parentGroup->insertChildNode( -1, clonedNode );
506  parentGroup->removeChildNode( n );
507  }
508 }
509 
510 
512 {
513  const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
514  if ( nodes.count() < 2 || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
515  return;
516 
517  QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
518  int insertIdx = parentGroup->children().indexOf( nodes[0] );
519 
520  QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
521  for ( QgsLayerTreeNode *node : nodes )
522  newGroup->addChildNode( node->clone() );
523 
524  parentGroup->insertChildNode( insertIdx, newGroup );
525 
526  for ( QgsLayerTreeNode *node : nodes )
527  {
528  QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
529  if ( group )
530  group->removeChildNode( node );
531  }
532 
533  mView->setCurrentIndex( mView->node2index( newGroup ) );
534  mView->edit( mView->node2index( newGroup ) );
535 }
536 
538 {
540  if ( !node || !QgsLayerTree::isGroup( node ) )
541  return;
542 
543  QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
544 }
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Layer tree group node serves as a container for layers and further groups.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
Layer tree node points to a map layer.
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
This class is a base class for nodes in a layer tree.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well)
bool isItemVisibilityUncheckedRecursive() const
Returns whether this node is unchecked and all its children.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
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.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
bool isItemVisibilityCheckedRecursive() const
Returns whether this node is checked and all its children.
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
QAction * actionRemoveGroupOrLayer(QObject *parent=nullptr)
void zoomToLayers()
Zooms to the combined extent of all the selected layer(s) in the layer tree.
QAction * actionZoomToLayers(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to all the selected layer(s) in the layer tree.
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 ...
QAction * actionMoveToTop(QObject *parent=nullptr)
QAction * actionShowInOverview(QObject *parent=nullptr)
QAction * actionRenameGroupOrLayer(QObject *parent=nullptr)
QAction * actionCheckAndAllChildren(QObject *parent=nullptr)
Action to check a group and all its children.
QAction * actionCheckAndAllParents(QObject *parent=nullptr)
Action to check a group and all its parents.
void moveToBottom()
Moves selected layer(s) and/or group(s) to the bottom of the layer panel or the bottom of the group i...
Q_DECL_DEPRECATED QAction * actionZoomToLayer(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to the active layer from the layer tree.
QAction * actionAddGroup(QObject *parent=nullptr)
QAction * actionGroupSelected(QObject *parent=nullptr)
QAction * actionMoveToBottom(QObject *parent=nullptr)
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
QAction * actionShowFeatureCount(QObject *parent=nullptr)
QAction * actionMutuallyExclusiveGroup(QObject *parent=nullptr)
Action to enable/disable mutually exclusive flag of a group (only one child node may be checked)
Q_DECL_DEPRECATED QAction * actionMakeTopLevel(QObject *parent=nullptr)
QString uniqueGroupName(QgsLayerTreeGroup *parentGroup)
QAction * actionUncheckAndAllChildren(QObject *parent=nullptr)
Action to uncheck a group and all its children.
void mutuallyExclusiveGroup()
Slot to enable/disable mutually exclusive group flag.
void zoomToSelection()
Zooms to the bounding box of all selected features of a vector layer.
void moveOutOfGroup()
Moves selected layer(s) out of the group(s) and places this/these above the group(s)
QAction * actionZoomToSelection(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to selected features of a vector layer.
QAction * actionMoveOutOfGroup(QObject *parent=nullptr)
QAction * actionZoomToGroup(QgsMapCanvas *canvas, QObject *parent=nullptr)
Q_DECL_DEPRECATED void zoomToLayer()
Zooms to the extent of the active layer in the layer tree.
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
QgsMapLayer * currentLayer() const
Returns the currently selected layer, or nullptr if no layers is selected.
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns proxy model index for a given node.
QgsLayerTreeNode * currentNode() const
Gets current node. May be nullptr.
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group....
QList< QgsMapLayer * > selectedLayers() const
Gets list of selected layers.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:53
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:43
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void refresh()
Repaints the canvas map.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:467
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:256
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:172
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:391
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:221
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:1742
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:1741