QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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" ) ),
95 tr( "&Zoom to Layer" ), parent );
96 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
98 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayer ) );
100 return a;
101}
102
104{
105 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
106 tr( "&Zoom to Layer(s)" ), parent );
107 a->setData( QVariant::fromValue( canvas ) );
108 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
109 return a;
110}
111
113{
114 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ),
115 tr( "Zoom to &Selection" ), parent );
116 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
117 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
118 return a;
119}
120
122{
123 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
124 tr( "&Zoom to Group" ), parent );
125 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
126 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
127 return a;
128}
129
131{
132 QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
134 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
136 return a;
137}
138
140{
141 QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
142 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
143 return a;
144}
145
147{
148 QAction *a = new QAction( tr( "Move to &Top" ), parent );
149 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
150 return a;
151}
152
154{
155 QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
156 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
157 return a;
158}
159
161{
162 QAction *a = new QAction( tr( "&Group Selected" ), parent );
163 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
164 return a;
165}
166
168{
170 if ( !node || !QgsLayerTree::isGroup( node ) )
171 return nullptr;
172
173 QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
174 a->setCheckable( true );
175 a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
176 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
177 return a;
178}
179
181{
183 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
184 return nullptr;
185#ifdef Q_OS_MACOS
186 QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
187#else
188 QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
189#endif
190 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
191 return a;
192}
193
195{
197 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
198 return nullptr;
199#ifdef Q_OS_MACOS
200 QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
201#else
202 QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
203#endif
204 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
205 return a;
206}
207
209{
211 if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
212 return nullptr;
213 QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
214 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
215 return a;
216}
217
218void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
219{
221 if ( !node )
222 return;
224}
225
226void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
227{
229 if ( !node )
230 return;
232}
233
234void QgsLayerTreeViewDefaultActions::checkAndAllParents()
235{
237 if ( !node )
238 return;
240}
241
243{
244 int nodeCount = mView->selectedNodes( true ).count();
245 if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
246 {
248 return;
249 }
251 if ( !group )
252 group = mView->layerTreeModel()->rootGroup();
253
254 QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
255 mView->edit( mView->node2index( newGroup ) );
256}
257
259{
260 const auto constSelectedNodes = mView->selectedNodes( true );
261 for ( QgsLayerTreeNode *node : constSelectedNodes )
262 {
263 // could be more efficient if working directly with ranges instead of individual nodes
264 qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
265 }
266}
267
269{
270 mView->edit( mView->currentIndex() );
271}
272
274{
276 if ( !node )
277 return;
278 int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
279 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
280 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
281 l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
282}
283
285{
287 if ( !QgsLayerTree::isLayer( node ) )
288 return;
289
290 int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
291 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
292 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
293 l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
294}
295
297{
298 QgsMapLayer *layer = mView->currentLayer();
299 if ( !layer )
300 return;
301
302 const QList<QgsMapLayer *> layers { layer };
303 zoomToLayers( canvas, layers );
304}
305
307{
308 const QList<QgsMapLayer *> layers = mView->selectedLayers();
309
310 zoomToLayers( canvas, layers );
311}
312
314{
315 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( mView->currentLayer() );
316
317 const QList<QgsMapLayer *> layers = mView->selectedLayers();
318
319 if ( layers.size() > 1 )
320 canvas->zoomToSelected( layers );
321 else if ( layers.size() <= 1 && layer )
322 canvas->zoomToSelected( layer );
323
324}
325
327{
329 if ( !groupNode )
330 return;
331
332 QList<QgsMapLayer *> layers;
333 const QStringList findLayerIds = groupNode->findLayerIds();
334 for ( const QString &layerId : findLayerIds )
335 layers << QgsProject::instance()->mapLayer( layerId );
336
337 zoomToLayers( canvas, layers );
338}
339
341{
343 QAction *s = qobject_cast<QAction *>( sender() );
344 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
345
346 zoomToLayer( canvas );
348}
349
351{
352 QAction *s = qobject_cast<QAction *>( sender() );
353 QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
354 zoomToLayers( canvas );
355}
356
358{
359 QAction *s = qobject_cast<QAction *>( sender() );
360 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
361 zoomToSelection( canvas );
362}
363
365{
366 QAction *s = qobject_cast<QAction *>( sender() );
367 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
368 zoomToGroup( canvas );
369}
370
371void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
372{
373 QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
374
375 QgsRectangle extent;
376 extent.setNull();
377
378 if ( !layers.empty() )
379 {
380 for ( int i = 0; i < layers.size(); ++i )
381 {
382 QgsMapLayer *layer = layers.at( i );
383 QgsRectangle layerExtent = layer->extent();
384
385 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
386 if ( vLayer )
387 {
388 if ( vLayer->geometryType() == Qgis::GeometryType::Null )
389 continue;
390
391 if ( layerExtent.isEmpty() )
392 {
393 vLayer->updateExtents();
394 layerExtent = vLayer->extent();
395 }
396 }
397
398 if ( layerExtent.isNull() )
399 continue;
400
401 //transform extent
402 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
403
404 extent.combineExtentWith( layerExtent );
405 }
406 }
407
408 // If no layer is selected, use current layer
409 else if ( mView->currentLayer() )
410 {
411 QgsRectangle layerExtent = mView->currentLayer()->extent();
412 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
413 extent.combineExtentWith( layerExtent );
414 }
415
416 if ( extent.isNull() )
417 return;
418
419 // Increase bounding box with 5%, so that layer is a bit inside the borders
420 extent.scale( 1.05 );
421
422 //zoom to bounding box
423 canvas->setExtent( extent, true );
424 canvas->refresh();
425}
426
427
429{
430 QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
431 QString newName = prefix + '1';
432 for ( int i = 2; parentGroup->findGroup( newName ); ++i )
433 newName = prefix + QString::number( i );
434 return newName;
435}
436
437
439{
440 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
441 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
442 {
444 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
445 if ( !parentGroup || parentGroup == rootGroup )
446 continue;
447 QgsLayerTreeLayer *clonedLayer = l->clone();
448 rootGroup->addChildNode( clonedLayer );
449 parentGroup->removeChildNode( l );
450 }
451}
452
453
455{
456 const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
457 for ( QgsLayerTreeLayer *l : selectedLayerNodes )
458 {
460 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
461 if ( !parentGroup || parentGroup == rootGroup )
462 continue;
463 QgsLayerTreeGroup *tempGroup = parentGroup;
464 while ( tempGroup->parent() != rootGroup )
465 {
466 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
467 }
468 QgsLayerTreeLayer *clonedLayer = l->clone();
469 int insertIdx = rootGroup->children().indexOf( tempGroup );
470 rootGroup->insertChildNode( insertIdx, clonedLayer );
471 parentGroup->removeChildNode( l );
472 }
473}
474
475
477{
478 QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
479 std::reverse( selectedNodes.begin(), selectedNodes.end() );
480 // sort the nodes by depth first to avoid moving a group before its contents
481 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
482 {
483 return a->depth() > b->depth();
484 } );
485 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
486 {
487 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
488 QgsLayerTreeNode *clonedNode = n->clone();
489 parentGroup->insertChildNode( 0, clonedNode );
490 parentGroup->removeChildNode( n );
491 }
492}
493
494
496{
497 QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
498 // sort the nodes by depth first to avoid moving a group before its contents
499 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
500 {
501 return a->depth() > b->depth();
502 } );
503 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
504 {
505 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
506 QgsLayerTreeNode *clonedNode = n->clone();
507 parentGroup->insertChildNode( -1, clonedNode );
508 parentGroup->removeChildNode( n );
509 }
510}
511
512
514{
515 const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
516 if ( nodes.empty() || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
517 return;
518
519 QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
520 int insertIdx = parentGroup->children().indexOf( nodes[0] );
521
522 QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
523 for ( QgsLayerTreeNode *node : nodes )
524 newGroup->addChildNode( node->clone() );
525
526 parentGroup->insertChildNode( insertIdx, newGroup );
527
528 for ( QgsLayerTreeNode *node : nodes )
529 {
530 QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
531 if ( group )
532 group->removeChildNode( node );
533 }
534
535 mView->setCurrentIndex( mView->node2index( newGroup ) );
536 mView->edit( mView->node2index( newGroup ) );
537}
538
540{
542 if ( !node || !QgsLayerTree::isGroup( node ) )
543 return;
544
545 QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
546}
@ 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.
bool isNull() const
Test if the rectangle is null (holding no spatial information).
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
bool isEmpty() const
Returns true if the rectangle has no area.
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:6535
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534