QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgslayertreeviewdefaultactions.cpp"
18#include "qgsguiutils.h"
19#include "qgsapplication.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
30 : QObject( view )
31 , mView( view )
32{
33}
34
36{
37 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddGroup.svg" ) ), tr( "&Add Group" ), parent );
38 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::addGroup );
39 return a;
40}
41
43{
44 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ), tr( "&Remove" ), parent );
45 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupOrLayer );
46 return a;
47}
48
50{
52 if ( !node )
53 return nullptr;
54
55 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInOverview.svg" ) ), tr( "Show in &Overview" ), parent );
56 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showInOverview );
57 a->setCheckable( true );
58 a->setChecked( node->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
59 return a;
60}
61
63{
65 if ( !node )
66 return nullptr;
67
68 QString text;
69 if ( QgsLayerTree::isGroup( node ) )
70 text = tr( "Re&name Group" );
71 else
72 text = tr( "Re&name Layer" );
73
74 QAction *a = new QAction( text, parent );
75 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::renameGroupOrLayer );
76 return a;
77}
78
80{
82 if ( !node )
83 return nullptr;
84
85 QAction *a = new QAction( tr( "Show Feature &Count" ), parent );
86 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showFeatureCount );
87 a->setCheckable( true );
88 a->setChecked( node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() );
89 return a;
90}
91
93{
94 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ), 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" ) ), tr( "&Zoom to Layer(s)" ), parent );
105 a->setData( QVariant::fromValue( canvas ) );
106 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
107 return a;
108}
109
111{
112 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ), tr( "Zoom to &Selection" ), parent );
113 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
114 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
115 return a;
116}
117
119{
120 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ), tr( "&Zoom to Group" ), parent );
121 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
122 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
123 return a;
124}
125
127{
128 QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
130 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
132 return a;
133}
134
136{
137 QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
138 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
139 return a;
140}
141
143{
144 QAction *a = new QAction( tr( "Move to &Top" ), parent );
145 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
146 return a;
147}
148
150{
151 QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
152 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
153 return a;
154}
155
157{
158 QAction *a = new QAction( tr( "&Group Selected" ), parent );
159 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
160 return a;
161}
162
164{
166 if ( !node || !QgsLayerTree::isGroup( node ) )
167 return nullptr;
168
169 QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
170 a->setCheckable( true );
171 a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
172 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
173 return a;
174}
175
177{
179 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
180 return nullptr;
181#ifdef Q_OS_MACOS
182 QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
183#else
184 QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
185#endif
186 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
187 return a;
188}
189
191{
193 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
194 return nullptr;
195#ifdef Q_OS_MACOS
196 QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
197#else
198 QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
199#endif
200 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
201 return a;
202}
203
205{
207 if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
208 return nullptr;
209 QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
210 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
211 return a;
212}
213
214void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
215{
217 if ( !node )
218 return;
220}
221
222void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
223{
225 if ( !node )
226 return;
228}
229
230void QgsLayerTreeViewDefaultActions::checkAndAllParents()
231{
233 if ( !node )
234 return;
236}
237
239{
240 int nodeCount = mView->selectedNodes( true ).count();
241 if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
242 {
244 return;
245 }
247 if ( !group )
248 group = mView->layerTreeModel()->rootGroup();
249
250 QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
251 mView->edit( mView->node2index( newGroup ) );
252}
253
255{
256 const auto constSelectedNodes = mView->selectedNodes( true );
257 for ( QgsLayerTreeNode *node : constSelectedNodes )
258 {
259 // could be more efficient if working directly with ranges instead of individual nodes
260 qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
261 }
262}
263
265{
266 mView->edit( mView->currentIndex() );
267}
268
270{
272 if ( !node )
273 return;
274 int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
275 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
276 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
277 l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
278}
279
281{
283 if ( !QgsLayerTree::isLayer( node ) )
284 return;
285
286 int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
287 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
288 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
289 l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
290}
291
293{
294 QgsMapLayer *layer = mView->currentLayer();
295 if ( !layer )
296 return;
297
298 const QList<QgsMapLayer *> layers { layer };
299 zoomToLayers( canvas, layers );
300}
301
303{
304 const QList<QgsMapLayer *> layers = mView->selectedLayers();
305
306 zoomToLayers( canvas, layers );
307}
308
310{
311 QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );
312
313 const QList<QgsMapLayer *> layers = mView->selectedLayers();
314
315 if ( layers.size() > 1 )
316 canvas->zoomToSelected( layers );
317 else if ( layers.size() <= 1 && layer )
318 canvas->zoomToSelected( layer );
319}
320
322{
324 if ( !groupNode )
325 return;
326
327 QList<QgsMapLayer *> layers;
328 const QStringList findLayerIds = groupNode->findLayerIds();
329 for ( const QString &layerId : findLayerIds )
330 layers << QgsProject::instance()->mapLayer( layerId );
331
332 zoomToLayers( canvas, layers );
333}
334
336{
338 QAction *s = qobject_cast<QAction *>( sender() );
339 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
340
341 zoomToLayer( canvas );
343}
344
346{
347 QAction *s = qobject_cast<QAction *>( sender() );
348 QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
349 zoomToLayers( canvas );
350}
351
353{
354 QAction *s = qobject_cast<QAction *>( sender() );
355 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
356 zoomToSelection( canvas );
357}
358
360{
361 QAction *s = qobject_cast<QAction *>( sender() );
362 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
363 zoomToGroup( canvas );
364}
365
366void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
367{
368 QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
369
370 QgsRectangle extent;
371 extent.setNull();
372
373 if ( !layers.empty() )
374 {
375 for ( int i = 0; i < layers.size(); ++i )
376 {
377 QgsMapLayer *layer = layers.at( i );
378 QgsRectangle layerExtent = layer->extent();
379
380 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
381 if ( vLayer )
382 {
383 if ( vLayer->geometryType() == Qgis::GeometryType::Null )
384 continue;
385
386 if ( layerExtent.isEmpty() )
387 {
388 vLayer->updateExtents();
389 layerExtent = vLayer->extent();
390 }
391 }
392
393 if ( layerExtent.isNull() )
394 continue;
395
396 //transform extent
397 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
398
399 extent.combineExtentWith( layerExtent );
400 }
401 }
402
403 // If no layer is selected, use current layer
404 else if ( mView->currentLayer() )
405 {
406 QgsRectangle layerExtent = mView->currentLayer()->extent();
407 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
408 extent.combineExtentWith( layerExtent );
409 }
410
411 if ( extent.isNull() )
412 return;
413
414 // Increase bounding box with 5%, so that layer is a bit inside the borders
415 extent.scale( 1.05 );
416
417 //zoom to bounding box
418 canvas->setExtent( extent, true );
419 canvas->refresh();
420}
421
422
424{
425 QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
426 QString newName = prefix + '1';
427 for ( int i = 2; parentGroup->findGroup( newName ); ++i )
428 newName = prefix + QString::number( i );
429 return newName;
430}
431
432
434{
435 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
436 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
437 {
439 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
440 if ( !parentGroup || parentGroup == rootGroup )
441 continue;
442 QgsLayerTreeLayer *clonedLayer = l->clone();
443 rootGroup->addChildNode( clonedLayer );
444 parentGroup->removeChildNode( l );
445 }
446}
447
448
450{
451 const QList<QgsLayerTreeLayer *> selectedLayerNodes = mView->selectedLayerNodes();
452 for ( QgsLayerTreeLayer *l : selectedLayerNodes )
453 {
455 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
456 if ( !parentGroup || parentGroup == rootGroup )
457 continue;
458 QgsLayerTreeGroup *tempGroup = parentGroup;
459 while ( tempGroup->parent() != rootGroup )
460 {
461 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
462 }
463 QgsLayerTreeLayer *clonedLayer = l->clone();
464 int insertIdx = rootGroup->children().indexOf( tempGroup );
465 rootGroup->insertChildNode( insertIdx, clonedLayer );
466 parentGroup->removeChildNode( l );
467 }
468}
469
470
472{
473 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
474 std::reverse( selectedNodes.begin(), selectedNodes.end() );
475 // sort the nodes by depth first to avoid moving a group before its contents
476 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
477 return a->depth() > b->depth();
478 } );
479 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
480 {
481 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
482 QgsLayerTreeNode *clonedNode = n->clone();
483 parentGroup->insertChildNode( 0, clonedNode );
484 parentGroup->removeChildNode( n );
485 }
486}
487
488
490{
491 QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
492 // sort the nodes by depth first to avoid moving a group before its contents
493 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode *a, const QgsLayerTreeNode *b ) {
494 return a->depth() > b->depth();
495 } );
496 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
497 {
498 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
499 QgsLayerTreeNode *clonedNode = n->clone();
500 parentGroup->insertChildNode( -1, clonedNode );
501 parentGroup->removeChildNode( n );
502 }
503}
504
505
507{
508 const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
509 if ( nodes.empty() || !QgsLayerTree::isGroup( nodes[0]->parent() ) )
510 return;
511
512 QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
513 int insertIdx = parentGroup->children().indexOf( nodes[0] );
514
515 QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
516 for ( QgsLayerTreeNode *node : nodes )
517 newGroup->addChildNode( node->clone() );
518
519 parentGroup->insertChildNode( insertIdx, newGroup );
520
521 for ( QgsLayerTreeNode *node : nodes )
522 {
523 QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
524 if ( group )
525 group->removeChildNode( node );
526 }
527
528 mView->setCurrentIndex( mView->node2index( newGroup ) );
529 mView->edit( mView->node2index( newGroup ) );
530}
531
533{
535 if ( !node || !QgsLayerTree::isGroup( node ) )
536 return;
537
538 QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
539}
@ Null
No geometry.
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.
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.
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)
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 the list of selected nodes filtered to just layer nodes (QgsLayerTreeLayer).
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 the list of selected layer tree 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
Returns the list of selected layers.
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:76
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 data sets.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6601
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6600