QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
18#include "qgsapplication.h"
19#include "qgsguiutils.h"
20#include "qgslayertree.h"
21#include "qgslayertreemodel.h"
22#include "qgslayertreeview.h"
23#include "qgsmapcanvas.h"
24#include "qgsproject.h"
25#include "qgsvectorlayer.h"
26
27#include <QAction>
28
29#include "moc_qgslayertreeviewdefaultactions.cpp"
30
36
38{
39 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddGroup.svg" ) ), tr( "&Add Group" ), parent );
40 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::addGroup );
41 return a;
42}
43
45{
46 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ), tr( "&Remove" ), parent );
47 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupOrLayer );
48 return a;
49}
50
52{
53 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ), tr( "&Remove Group" ), parent );
54 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupPromoteLayers );
55 return a;
56}
57
59{
60 QgsLayerTreeNode *node = mView->currentNode();
61 if ( !node )
62 return nullptr;
63
64 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInOverview.svg" ) ), tr( "Show in &Overview" ), parent );
65 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showInOverview );
66 a->setCheckable( true );
67 a->setChecked( node->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
68 return a;
69}
70
72{
73 QgsLayerTreeNode *node = mView->currentNode();
74 if ( !node )
75 return nullptr;
76
77 QString text;
78 if ( QgsLayerTree::isGroup( node ) )
79 text = tr( "Re&name Group" );
80 else
81 text = tr( "Re&name Layer" );
82
83 QAction *a = new QAction( text, parent );
84 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::renameGroupOrLayer );
85 return a;
86}
87
89{
90 QgsLayerTreeNode *node = mView->currentNode();
91 if ( !node )
92 return nullptr;
93
94 QAction *a = new QAction( tr( "Show Feature &Count" ), parent );
95 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showFeatureCount );
96 a->setCheckable( true );
97 a->setChecked( node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() );
98 return a;
99}
100
102{
103 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ), tr( "&Zoom to Layer" ), parent );
104 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
106 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayer ) );
108 return a;
109}
110
112{
113 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ), tr( "&Zoom to Layer(s)" ), parent );
114 a->setData( QVariant::fromValue( canvas ) );
115 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
116 return a;
117}
118
120{
121 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ), tr( "Zoom to &Selection" ), parent );
122 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
123 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
124 return a;
125}
126
128{
129 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ), tr( "&Zoom to Group" ), parent );
130 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
131 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
132 return a;
133}
134
136{
137 QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
139 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
141 return a;
142}
143
145{
146 QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
147 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
148 return a;
149}
150
152{
153 QAction *a = new QAction( tr( "Move to &Top" ), parent );
154 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
155 return a;
156}
157
159{
160 QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
161 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
162 return a;
163}
164
166{
167 QAction *a = new QAction( tr( "&Group Selected" ), parent );
168 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
169 return a;
170}
171
173{
174 QgsLayerTreeNode *node = mView->currentNode();
175 if ( !node || !QgsLayerTree::isGroup( node ) )
176 return nullptr;
177
178 QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
179 a->setCheckable( true );
180 a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
181 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
182 return a;
183}
184
186{
187 QgsLayerTreeNode *node = mView->currentNode();
188 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
189 return nullptr;
190#ifdef Q_OS_MACOS
191 QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
192#else
193 QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
194#endif
195 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
196 return a;
197}
198
200{
201 QgsLayerTreeNode *node = mView->currentNode();
202 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
203 return nullptr;
204#ifdef Q_OS_MACOS
205 QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
206#else
207 QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
208#endif
209 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
210 return a;
211}
212
214{
215 QgsLayerTreeNode *node = mView->currentNode();
216 if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
217 return nullptr;
218 QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
219 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
220 return a;
221}
222
223void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
224{
226 if ( !node )
227 return;
229}
230
231void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
232{
233 QgsLayerTreeNode *node = mView->currentNode();
234 if ( !node )
235 return;
237}
238
239void QgsLayerTreeViewDefaultActions::checkAndAllParents()
240{
241 QgsLayerTreeNode *node = mView->currentNode();
242 if ( !node )
243 return;
245}
246
248{
249 int nodeCount = mView->selectedNodes( true ).count();
250 if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
251 {
253 return;
254 }
255 QgsLayerTreeGroup *group = mView->currentGroupNode();
256 if ( !group )
257 group = mView->layerTreeModel()->rootGroup();
258
259 QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
260 mView->edit( mView->node2index( newGroup ) );
261}
262
264{
265 const auto constSelectedNodes = mView->selectedNodes( true );
266 for ( QgsLayerTreeNode *node : constSelectedNodes )
267 {
268 // could be more efficient if working directly with ranges instead of individual nodes
269 qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
270 }
271}
272
274{
275 QgsLayerTreeGroup *group = mView->currentGroupNode();
276
277 // can't remove the root group!
278 if ( !group || group == mView->layerTreeModel()->rootGroup() )
279 return;
280
281 QgsLayerTreeGroup *newParentGroup = qobject_cast<QgsLayerTreeGroup *>( group->parent() );
282 if ( !newParentGroup )
283 return;
284
285 const int existingNodePosition = newParentGroup->children().indexOf( group );
286
287 const QList< QgsLayerTreeNode * > childrenToPromote = group->children();
288 if ( !childrenToPromote.isEmpty() )
289 {
290 for ( auto it = childrenToPromote.rbegin(); it != childrenToPromote.rend(); ++it )
291 {
292 newParentGroup->insertChildNode( existingNodePosition, ( *it )->clone() );
293 group->removeChildNode( *it );
294 }
295 }
296
297 newParentGroup->removeChildNode( group );
298}
299
301{
302 mView->edit( mView->currentIndex() );
303}
304
306{
307 QgsLayerTreeNode *node = mView->currentNode();
308 if ( !node )
309 return;
310 int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
311 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
312 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
313 l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
314}
315
317{
318 QgsLayerTreeNode *node = mView->currentNode();
319 if ( !QgsLayerTree::isLayer( node ) )
320 return;
321
322 int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
323 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
324 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
325 l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
326}
327
329{
330 QgsMapLayer *layer = mView->currentLayer();
331 if ( !layer )
332 return;
333
334 const QList<QgsMapLayer *> layers { layer };
335 zoomToLayers( canvas, layers );
336}
337
339{
340 const QList<QgsMapLayer *> layers = mView->selectedLayers();
341
342 zoomToLayers( canvas, layers );
343}
344
346{
347 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );
348
349 const QList<QgsMapLayer *> layers = mView->selectedLayers();
350
351 if ( layers.size() > 1 )
352 canvas->zoomToSelected( layers );
353 else if ( layers.size() <= 1 && layer )
354 canvas->zoomToSelected( layer );
355}
356
358{
359 QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
360 if ( !groupNode )
361 return;
362
363 QList<QgsMapLayer *> layers;
364 const QStringList findLayerIds = groupNode->findLayerIds();
365 for ( const QString &layerId : findLayerIds )
366 layers << QgsProject::instance()->mapLayer( layerId );
367
368 zoomToLayers( canvas, layers );
369}
370
372{
374 QAction *s = qobject_cast<QAction *>( sender() );
375 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
376
377 zoomToLayer( canvas );
379}
380
382{
383 QAction *s = qobject_cast<QAction *>( sender() );
384 QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
385 zoomToLayers( canvas );
386}
387
389{
390 QAction *s = qobject_cast<QAction *>( sender() );
391 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
392 zoomToSelection( canvas );
393}
394
396{
397 QAction *s = qobject_cast<QAction *>( sender() );
398 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
399 zoomToGroup( canvas );
400}
401
402void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
403{
404 QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
405
406 QgsRectangle extent;
407 extent.setNull();
408
409 if ( !layers.empty() )
410 {
411 for ( int i = 0; i < layers.size(); ++i )
412 {
413 QgsMapLayer *layer = layers.at( i );
414 QgsRectangle layerExtent = layer->extent();
415
416 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
417 if ( vLayer )
418 {
419 if ( vLayer->geometryType() == Qgis::GeometryType::Null )
420 continue;
421
422 if ( layerExtent.isEmpty() )
423 {
424 vLayer->updateExtents();
425 layerExtent = vLayer->extent();
426 }
427 }
428
429 if ( layerExtent.isNull() )
430 continue;
431
432 //transform extent
433 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
434
435 extent.combineExtentWith( layerExtent );
436 }
437 }
438
439 // If no layer is selected, use current layer
440 else if ( mView->currentLayer() )
441 {
442 QgsRectangle layerExtent = mView->currentLayer()->extent();
443 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
444 extent.combineExtentWith( layerExtent );
445 }
446
447 if ( extent.isNull() )
448 return;
449
450 // Increase bounding box with 5%, so that layer is a bit inside the borders
451 extent.scale( 1.05 );
452
453 //zoom to bounding box
454 canvas->setExtent( extent, true );
455 canvas->refresh();
456}
457
458
460{
461 QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
462 QString newName = prefix + '1';
463 for ( int i = 2; parentGroup->findGroup( newName ); ++i )
464 newName = prefix + QString::number( i );
465 return newName;
466}
467
468
470{
471 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
472 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
473 {
474 QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
475 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
476 if ( !parentGroup || parentGroup == rootGroup )
477 continue;
478 QgsLayerTreeLayer *clonedLayer = l->clone();
479 rootGroup->addChildNode( clonedLayer );
480 parentGroup->removeChildNode( l );
481 }
482}
483
484
486{
487 const QList<QgsLayerTreeLayer *> selectedLayerNodes = mView->selectedLayerNodes();
488 for ( QgsLayerTreeLayer *l : selectedLayerNodes )
489 {
490 QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
491 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
492 if ( !parentGroup || parentGroup == rootGroup )
493 continue;
494 QgsLayerTreeGroup *tempGroup = parentGroup;
495 while ( tempGroup->parent() != rootGroup )
496 {
497 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
498 }
499 QgsLayerTreeLayer *clonedLayer = l->clone();
500 int insertIdx = rootGroup->children().indexOf( tempGroup );
501 rootGroup->insertChildNode( insertIdx, clonedLayer );
502 parentGroup->removeChildNode( l );
503 }
504}
505
506
508{
509 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
510 std::reverse( selectedNodes.begin(), selectedNodes.end() );
511 // sort the nodes by depth first to avoid moving a group before its contents
512 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
513 return a->depth() > b->depth();
514 } );
515 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
516 {
517 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
518 QgsLayerTreeNode *clonedNode = n->clone();
519 parentGroup->insertChildNode( 0, clonedNode );
520 parentGroup->removeChildNode( n );
521 }
522}
523
524
526{
527 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
528 // sort the nodes by depth first to avoid moving a group before its contents
529 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
530 return a->depth() > b->depth();
531 } );
532 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
533 {
534 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
535 QgsLayerTreeNode *clonedNode = n->clone();
536 parentGroup->insertChildNode( -1, clonedNode );
537 parentGroup->removeChildNode( n );
538 }
539}
540
541
543{
544 const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
545 if ( nodes.empty() || !QgsLayerTree::isGroup( nodes[0]->parent() ) )
546 return;
547
548 QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
549 int insertIdx = parentGroup->children().indexOf( nodes[0] );
550
551 QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
552 for ( QgsLayerTreeNode *node : nodes )
553 newGroup->addChildNode( node->clone() );
554
555 parentGroup->insertChildNode( insertIdx, newGroup );
556
557 for ( QgsLayerTreeNode *node : nodes )
558 {
559 QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
560 if ( group )
561 group->removeChildNode( node );
562 }
563
564 mView->setCurrentIndex( mView->node2index( newGroup ) );
565 mView->edit( mView->node2index( newGroup ) );
566}
567
569{
570 QgsLayerTreeNode *node = mView->currentNode();
571 if ( !node || !QgsLayerTree::isGroup( node ) )
572 return;
573
574 QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
575}
@ Null
No geometry.
Definition qgis.h:363
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.
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.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
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.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules).
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
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.
Base class for QTreeView widgets which display a layer tree.
QgsLayerTreeNode * currentNode() const
Returns the current node.
QAction * actionRemoveGroupOrLayer(QObject *parent=nullptr)
Returns a new action which removes either a group or layer, depending on the selected node.
void zoomToLayers()
Zooms to the combined extent of all the selected layer(s) in the layer tree.
void removeGroupPromoteLayers()
Removes the selected group node, promoting all child nodes up into the removed group's parent node.
void zoomToLayers(QgsMapCanvas *canvas)
Zooms a map canvas to 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)
Returns a new action for toggling whether a layer is shown in the map overview.
QAction * actionRenameGroupOrLayer(QObject *parent=nullptr)
Returns a new action for renaming a group or layer, depending on the selected node.
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...
QAction * actionRemoveGroupPromoteLayers(QObject *parent=nullptr)
Returns a new action which removes a group.
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)
Returns a new action which adds a group.
QAction * actionGroupSelected(QObject *parent=nullptr)
QgsLayerTreeViewDefaultActions(QgsLayerTreeViewBase *view)
Constructor for QgsLayerTreeViewDefaultActions, creating actions for a view.
QAction * actionMoveToBottom(QObject *parent=nullptr)
QAction * actionShowFeatureCount(QObject *parent=nullptr)
Returns a new action for toggling whether the feature count is shown for a layer.
Q_DECL_DEPRECATED void zoomToLayer(QgsMapCanvas *canvas)
Zooms a map canvas to the extent of the active layer in the layer tree.
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.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Map canvas is a class for displaying all GIS data types on a canvas.
void zoomToSelected(QgsMapLayer *layer=nullptr)
Zoom to the extent of the selected features of provided map layer.
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
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:80
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.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Represents a vector layer which manages a vector based dataset.
QgsRectangle extent() const final
Returns the extent of the layer.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7170
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7169