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