QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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#include <QString>
29
30#include "moc_qgslayertreeviewdefaultactions.cpp"
31
32using namespace Qt::StringLiterals;
33
39
41{
42 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionAddGroup.svg"_s ), tr( "&Add Group" ), parent );
43 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::addGroup );
44 return a;
45}
46
48{
49 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionRemoveLayer.svg"_s ), tr( "&Remove" ), parent );
50 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupOrLayer );
51 return a;
52}
53
55{
56 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionRemoveLayer.svg"_s ), tr( "&Remove Group" ), parent );
57 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupPromoteLayers );
58 return a;
59}
60
62{
63 QgsLayerTreeNode *node = mView->currentNode();
64 if ( !node )
65 return nullptr;
66
67 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionInOverview.svg"_s ), tr( "Show in &Overview" ), parent );
68 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showInOverview );
69 a->setCheckable( true );
70 a->setChecked( node->customProperty( u"overview"_s, 0 ).toInt() );
71 return a;
72}
73
75{
76 QgsLayerTreeNode *node = mView->currentNode();
77 if ( !node )
78 return nullptr;
79
80 QString text;
81 if ( QgsLayerTree::isGroup( node ) )
82 text = tr( "Re&name Group" );
83 else
84 text = tr( "Re&name Layer" );
85
86 QAction *a = new QAction( text, parent );
87 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::renameGroupOrLayer );
88 return a;
89}
90
92{
93 QgsLayerTreeNode *node = mView->currentNode();
94 if ( !node )
95 return nullptr;
96
97 QAction *a = new QAction( tr( "Show Feature &Count" ), parent );
98 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showFeatureCount );
99 a->setCheckable( true );
100 a->setChecked( node->customProperty( u"showFeatureCount"_s, 0 ).toInt() );
101 return a;
102}
103
105{
106 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionZoomToLayer.svg"_s ), tr( "&Zoom to Layer" ), parent );
107 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
109 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayer ) );
111 return a;
112}
113
115{
116 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionZoomToLayer.svg"_s ), tr( "&Zoom to Layer(s)" ), parent );
117 a->setData( QVariant::fromValue( canvas ) );
118 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
119 return a;
120}
121
123{
124 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionZoomToSelected.svg"_s ), tr( "Zoom to &Selection" ), parent );
125 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
126 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
127 return a;
128}
129
131{
132 QAction *a = new QAction( QgsApplication::getThemeIcon( u"/mActionZoomToLayer.svg"_s ), tr( "&Zoom to Group" ), parent );
133 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
134 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
135 return a;
136}
137
139{
140 QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
142 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
144 return a;
145}
146
148{
149 QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
150 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
151 return a;
152}
153
155{
156 QAction *a = new QAction( tr( "Move to &Top" ), parent );
157 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
158 return a;
159}
160
162{
163 QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
164 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
165 return a;
166}
167
169{
170 QAction *a = new QAction( tr( "&Group Selected" ), parent );
171 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
172 return a;
173}
174
176{
177 QgsLayerTreeNode *node = mView->currentNode();
178 if ( !node || !QgsLayerTree::isGroup( node ) )
179 return nullptr;
180
181 QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
182 a->setCheckable( true );
183 a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
184 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
185 return a;
186}
187
189{
190 QgsLayerTreeNode *node = mView->currentNode();
191 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
192 return nullptr;
193#ifdef Q_OS_MACOS
194 QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
195#else
196 QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
197#endif
198 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
199 return a;
200}
201
203{
204 QgsLayerTreeNode *node = mView->currentNode();
205 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
206 return nullptr;
207#ifdef Q_OS_MACOS
208 QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
209#else
210 QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
211#endif
212 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
213 return a;
214}
215
217{
218 QgsLayerTreeNode *node = mView->currentNode();
219 if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
220 return nullptr;
221 QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
222 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
223 return a;
224}
225
226void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
227{
229 if ( !node )
230 return;
232}
233
234void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
235{
236 QgsLayerTreeNode *node = mView->currentNode();
237 if ( !node )
238 return;
240}
241
242void QgsLayerTreeViewDefaultActions::checkAndAllParents()
243{
244 QgsLayerTreeNode *node = mView->currentNode();
245 if ( !node )
246 return;
248}
249
251{
252 int nodeCount = mView->selectedNodes( true ).count();
253 if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
254 {
256 return;
257 }
258 QgsLayerTreeGroup *group = mView->currentGroupNode();
259 if ( !group )
260 group = mView->layerTreeModel()->rootGroup();
261
262 QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
263 mView->edit( mView->node2index( newGroup ) );
264}
265
267{
268 const auto constSelectedNodes = mView->selectedNodes( true );
269 for ( QgsLayerTreeNode *node : constSelectedNodes )
270 {
271 // could be more efficient if working directly with ranges instead of individual nodes
272 qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
273 }
274}
275
277{
278 QgsLayerTreeGroup *group = mView->currentGroupNode();
279
280 // can't remove the root group!
281 if ( !group || group == mView->layerTreeModel()->rootGroup() )
282 return;
283
284 QgsLayerTreeGroup *newParentGroup = qobject_cast<QgsLayerTreeGroup *>( group->parent() );
285 if ( !newParentGroup )
286 return;
287
288 const int existingNodePosition = newParentGroup->children().indexOf( group );
289
290 const QList< QgsLayerTreeNode * > childrenToPromote = group->children();
291 if ( !childrenToPromote.isEmpty() )
292 {
293 for ( auto it = childrenToPromote.rbegin(); it != childrenToPromote.rend(); ++it )
294 {
295 newParentGroup->insertChildNode( existingNodePosition, ( *it )->clone() );
296 group->removeChildNode( *it );
297 }
298 }
299
300 newParentGroup->removeChildNode( group );
301}
302
304{
305 mView->edit( mView->currentIndex() );
306}
307
309{
310 QgsLayerTreeNode *node = mView->currentNode();
311 if ( !node )
312 return;
313 int newValue = node->customProperty( u"overview"_s, 0 ).toInt();
314 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
315 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
316 l->setCustomProperty( u"overview"_s, newValue ? 0 : 1 );
317}
318
320{
321 QgsLayerTreeNode *node = mView->currentNode();
322 if ( !QgsLayerTree::isLayer( node ) )
323 return;
324
325 int newValue = node->customProperty( u"showFeatureCount"_s, 0 ).toInt();
326 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
327 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
328 l->setCustomProperty( u"showFeatureCount"_s, newValue ? 0 : 1 );
329}
330
332{
333 QgsMapLayer *layer = mView->currentLayer();
334 if ( !layer )
335 return;
336
337 const QList<QgsMapLayer *> layers { layer };
338 zoomToLayers( canvas, layers );
339}
340
342{
343 const QList<QgsMapLayer *> layers = mView->selectedLayers();
344
345 zoomToLayers( canvas, layers );
346}
347
349{
350 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );
351
352 const QList<QgsMapLayer *> layers = mView->selectedLayers();
353
354 if ( layers.size() > 1 )
355 canvas->zoomToSelected( layers );
356 else if ( layers.size() <= 1 && layer )
357 canvas->zoomToSelected( layer );
358}
359
361{
362 QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
363 if ( !groupNode )
364 return;
365
366 QList<QgsMapLayer *> layers;
367 const QStringList findLayerIds = groupNode->findLayerIds();
368 for ( const QString &layerId : findLayerIds )
369 layers << QgsProject::instance()->mapLayer( layerId );
370
371 zoomToLayers( canvas, layers );
372}
373
375{
377 QAction *s = qobject_cast<QAction *>( sender() );
378 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
379
380 zoomToLayer( canvas );
382}
383
385{
386 QAction *s = qobject_cast<QAction *>( sender() );
387 QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
388 zoomToLayers( canvas );
389}
390
392{
393 QAction *s = qobject_cast<QAction *>( sender() );
394 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
395 zoomToSelection( canvas );
396}
397
399{
400 QAction *s = qobject_cast<QAction *>( sender() );
401 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
402 zoomToGroup( canvas );
403}
404
405void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
406{
407 QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
408
409 QgsRectangle extent;
410 extent.setNull();
411
412 if ( !layers.empty() )
413 {
414 for ( int i = 0; i < layers.size(); ++i )
415 {
416 QgsMapLayer *layer = layers.at( i );
417 QgsRectangle layerExtent = layer->extent();
418
419 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
420 if ( vLayer )
421 {
422 if ( vLayer->geometryType() == Qgis::GeometryType::Null )
423 continue;
424
425 if ( layerExtent.isEmpty() )
426 {
427 vLayer->updateExtents();
428 layerExtent = vLayer->extent();
429 }
430 }
431
432 if ( layerExtent.isNull() )
433 continue;
434
435 //transform extent
436 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
437
438 extent.combineExtentWith( layerExtent );
439 }
440 }
441
442 // If no layer is selected, use current layer
443 else if ( mView->currentLayer() )
444 {
445 QgsRectangle layerExtent = mView->currentLayer()->extent();
446 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
447 extent.combineExtentWith( layerExtent );
448 }
449
450 if ( extent.isNull() )
451 return;
452
453 // Increase bounding box with 5%, so that layer is a bit inside the borders
454 extent.scale( 1.05 );
455
456 //zoom to bounding box
457 canvas->setExtent( extent, true );
458 canvas->refresh();
459}
460
461
463{
464 QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
465 QString newName = prefix + '1';
466 for ( int i = 2; parentGroup->findGroup( newName ); ++i )
467 newName = prefix + QString::number( i );
468 return newName;
469}
470
471
473{
474 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
475 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
476 {
477 QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
478 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
479 if ( !parentGroup || parentGroup == rootGroup )
480 continue;
481 QgsLayerTreeLayer *clonedLayer = l->clone();
482 rootGroup->addChildNode( clonedLayer );
483 parentGroup->removeChildNode( l );
484 }
485}
486
487
489{
490 const QList<QgsLayerTreeLayer *> selectedLayerNodes = mView->selectedLayerNodes();
491 for ( QgsLayerTreeLayer *l : selectedLayerNodes )
492 {
493 QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
494 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
495 if ( !parentGroup || parentGroup == rootGroup )
496 continue;
497 QgsLayerTreeGroup *tempGroup = parentGroup;
498 while ( tempGroup->parent() != rootGroup )
499 {
500 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
501 }
502 QgsLayerTreeLayer *clonedLayer = l->clone();
503 int insertIdx = rootGroup->children().indexOf( tempGroup );
504 rootGroup->insertChildNode( insertIdx, clonedLayer );
505 parentGroup->removeChildNode( l );
506 }
507}
508
509
511{
512 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
513 std::reverse( selectedNodes.begin(), selectedNodes.end() );
514 // sort the nodes by depth first to avoid moving a group before its contents
515 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
516 return a->depth() > b->depth();
517 } );
518 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
519 {
520 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
521 QgsLayerTreeNode *clonedNode = n->clone();
522 parentGroup->insertChildNode( 0, clonedNode );
523 parentGroup->removeChildNode( n );
524 }
525}
526
527
529{
530 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
531 // sort the nodes by depth first to avoid moving a group before its contents
532 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
533 return a->depth() > b->depth();
534 } );
535 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
536 {
537 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
538 QgsLayerTreeNode *clonedNode = n->clone();
539 parentGroup->insertChildNode( -1, clonedNode );
540 parentGroup->removeChildNode( n );
541 }
542}
543
544
546{
547 const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
548 if ( nodes.empty() || !QgsLayerTree::isGroup( nodes[0]->parent() ) )
549 return;
550
551 QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
552 int insertIdx = parentGroup->children().indexOf( nodes[0] );
553
554 QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
555 for ( QgsLayerTreeNode *node : nodes )
556 newGroup->addChildNode( node->clone() );
557
558 parentGroup->insertChildNode( insertIdx, newGroup );
559
560 for ( QgsLayerTreeNode *node : nodes )
561 {
562 QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
563 if ( group )
564 group->removeChildNode( node );
565 }
566
567 mView->setCurrentIndex( mView->node2index( newGroup ) );
568 mView->edit( mView->node2index( newGroup ) );
569}
570
572{
573 QgsLayerTreeNode *node = mView->currentNode();
574 if ( !node || !QgsLayerTree::isGroup( node ) )
575 return;
576
577 QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
578}
@ Null
No geometry.
Definition qgis.h:370
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:83
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:7475
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7474