QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsguiutils.h"
18#include "qgsapplication.h"
19#include "qgslayertree.h"
20#include "qgslayertreemodel.h"
21#include "qgslayertreeview.h"
22#include "qgsmapcanvas.h"
23#include "qgsproject.h"
24#include "qgsvectorlayer.h"
25
26#include <QAction>
27
29 : QObject( view )
30 , mView( view )
31{
32}
33
35{
36 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddGroup.svg" ) ), tr( "&Add Group" ), parent );
37 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::addGroup );
38 return a;
39}
40
42{
43 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRemoveLayer.svg" ) ), tr( "&Remove" ), parent );
44 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::removeGroupOrLayer );
45 return a;
46}
47
49{
51 if ( !node )
52 return nullptr;
53
54 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInOverview.svg" ) ), tr( "Show in &Overview" ), parent );
55 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showInOverview );
56 a->setCheckable( true );
57 a->setChecked( node->customProperty( QStringLiteral( "overview" ), 0 ).toInt() );
58 return a;
59}
60
62{
64 if ( !node )
65 return nullptr;
66
67 QString text;
68 if ( QgsLayerTree::isGroup( node ) )
69 text = tr( "Re&name Group" );
70 else
71 text = tr( "Re&name Layer" );
72
73 QAction *a = new QAction( text, parent );
74 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::renameGroupOrLayer );
75 return a;
76}
77
79{
81 if ( !node )
82 return nullptr;
83
84 QAction *a = new QAction( tr( "Show Feature &Count" ), parent );
85 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::showFeatureCount );
86 a->setCheckable( true );
87 a->setChecked( node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() );
88 return a;
89}
90
92{
93 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
94 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" ) ),
105 tr( "&Zoom to Layer(s)" ), parent );
106 a->setData( QVariant::fromValue( canvas ) );
107 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToLayers ) );
108 return a;
109}
110
112{
113 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ),
114 tr( "Zoom to &Selection" ), parent );
115 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
116 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
117 return a;
118}
119
121{
122 QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
123 tr( "&Zoom to Group" ), parent );
124 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
125 connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToGroup ) );
126 return a;
127}
128
130{
131 QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
133 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
135 return a;
136}
137
139{
140 QAction *a = new QAction( tr( "Move O&ut of Group" ), parent );
141 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
142 return a;
143}
144
146{
147 QAction *a = new QAction( tr( "Move to &Top" ), parent );
148 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
149 return a;
150}
151
153{
154 QAction *a = new QAction( tr( "Move to &Bottom" ), parent );
155 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToBottom );
156 return a;
157}
158
160{
161 QAction *a = new QAction( tr( "&Group Selected" ), parent );
162 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::groupSelected );
163 return a;
164}
165
167{
169 if ( !node || !QgsLayerTree::isGroup( node ) )
170 return nullptr;
171
172 QAction *a = new QAction( tr( "&Mutually Exclusive Group" ), parent );
173 a->setCheckable( true );
174 a->setChecked( QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
175 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::mutuallyExclusiveGroup );
176 return a;
177}
178
180{
182 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityCheckedRecursive() )
183 return nullptr;
184#ifdef Q_OS_MACX
185 QAction *a = new QAction( tr( "Check and All its Children (⌘-click)" ), parent );
186#else
187 QAction *a = new QAction( tr( "Check and All its Children (Ctrl-click)" ), parent );
188#endif
189 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
190 return a;
191}
192
194{
196 if ( !node || !QgsLayerTree::isGroup( node ) || node->isItemVisibilityUncheckedRecursive() )
197 return nullptr;
198#ifdef Q_OS_MACX
199 QAction *a = new QAction( tr( "Uncheck and All its Children (⌘-click)" ), parent );
200#else
201 QAction *a = new QAction( tr( "Uncheck and All its Children (Ctrl-click)" ), parent );
202#endif
203 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
204 return a;
205}
206
208{
210 if ( !node || !QgsLayerTree::isLayer( node ) || node->isVisible() )
211 return nullptr;
212 QAction *a = new QAction( tr( "Chec&k and All its Parents" ), parent );
213 connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
214 return a;
215}
216
217void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
218{
220 if ( !node )
221 return;
223}
224
225void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
226{
228 if ( !node )
229 return;
231}
232
233void QgsLayerTreeViewDefaultActions::checkAndAllParents()
234{
236 if ( !node )
237 return;
239}
240
242{
243 int nodeCount = mView->selectedNodes( true ).count();
244 if ( nodeCount > 1 || ( nodeCount == 1 && mView->currentLayer() ) )
245 {
247 return;
248 }
250 if ( !group )
251 group = mView->layerTreeModel()->rootGroup();
252
253 QgsLayerTreeGroup *newGroup = group->addGroup( uniqueGroupName( group ) );
254 mView->edit( mView->node2index( newGroup ) );
255}
256
258{
259 const auto constSelectedNodes = mView->selectedNodes( true );
260 for ( QgsLayerTreeNode *node : constSelectedNodes )
261 {
262 // could be more efficient if working directly with ranges instead of individual nodes
263 qobject_cast<QgsLayerTreeGroup *>( node->parent() )->removeChildNode( node );
264 }
265}
266
268{
269 mView->edit( mView->currentIndex() );
270}
271
273{
275 if ( !node )
276 return;
277 int newValue = node->customProperty( QStringLiteral( "overview" ), 0 ).toInt();
278 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
279 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
280 l->setCustomProperty( QStringLiteral( "overview" ), newValue ? 0 : 1 );
281}
282
284{
286 if ( !QgsLayerTree::isLayer( node ) )
287 return;
288
289 int newValue = node->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt();
290 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
291 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
292 l->setCustomProperty( QStringLiteral( "showFeatureCount" ), newValue ? 0 : 1 );
293}
294
296{
297 QgsMapLayer *layer = mView->currentLayer();
298 if ( !layer )
299 return;
300
301 const QList<QgsMapLayer *> layers { layer };
302 zoomToLayers( canvas, layers );
303}
304
306{
307 const QList<QgsMapLayer *> layers = mView->selectedLayers();
308
309 zoomToLayers( canvas, layers );
310}
311
313{
314 QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( mView->currentLayer() );
315
316 const QList<QgsMapLayer *> layers = mView->selectedLayers();
317
318 if ( layers.size() > 1 )
319 canvas->zoomToSelected( layers );
320 else if ( layers.size() <= 1 && layer )
321 canvas->zoomToSelected( layer );
322
323}
324
326{
328 if ( !groupNode )
329 return;
330
331 QList<QgsMapLayer *> layers;
332 const QStringList findLayerIds = groupNode->findLayerIds();
333 for ( const QString &layerId : findLayerIds )
334 layers << QgsProject::instance()->mapLayer( layerId );
335
336 zoomToLayers( canvas, layers );
337}
338
340{
342 QAction *s = qobject_cast<QAction *>( sender() );
343 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
344
345 zoomToLayer( canvas );
347}
348
350{
351 QAction *s = qobject_cast<QAction *>( sender() );
352 QgsMapCanvas *canvas = s->data().value<QgsMapCanvas *>();
353 zoomToLayers( canvas );
354}
355
357{
358 QAction *s = qobject_cast<QAction *>( sender() );
359 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
360 zoomToSelection( canvas );
361}
362
364{
365 QAction *s = qobject_cast<QAction *>( sender() );
366 QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
367 zoomToGroup( canvas );
368}
369
370void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers )
371{
372 QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
373
374 QgsRectangle extent;
375 extent.setMinimal();
376
377 if ( !layers.empty() )
378 {
379 for ( int i = 0; i < layers.size(); ++i )
380 {
381 QgsMapLayer *layer = layers.at( i );
382 QgsRectangle layerExtent = layer->extent();
383
384 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
385 if ( vLayer )
386 {
387 if ( vLayer->geometryType() == QgsWkbTypes::NullGeometry )
388 continue;
389
390 if ( layerExtent.isEmpty() )
391 {
392 vLayer->updateExtents();
393 layerExtent = vLayer->extent();
394 }
395 }
396
397 if ( layerExtent.isNull() )
398 continue;
399
400 //transform extent
401 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( layer, layerExtent );
402
403 extent.combineExtentWith( layerExtent );
404 }
405 }
406
407 // If no layer is selected, use current layer
408 else if ( mView->currentLayer() )
409 {
410 QgsRectangle layerExtent = mView->currentLayer()->extent();
411 layerExtent = canvas->mapSettings().layerExtentToOutputExtent( mView->currentLayer(), layerExtent );
412 extent.combineExtentWith( layerExtent );
413 }
414
415 if ( extent.isNull() )
416 return;
417
418 // Increase bounding box with 5%, so that layer is a bit inside the borders
419 extent.scale( 1.05 );
420
421 //zoom to bounding box
422 canvas->setExtent( extent, true );
423 canvas->refresh();
424}
425
426
428{
429 QString prefix = parentGroup == mView->layerTreeModel()->rootGroup() ? "group" : "sub-group";
430 QString newName = prefix + '1';
431 for ( int i = 2; parentGroup->findGroup( newName ); ++i )
432 newName = prefix + QString::number( i );
433 return newName;
434}
435
436
438{
439 const auto constSelectedLayerNodes = mView->selectedLayerNodes();
440 for ( QgsLayerTreeLayer *l : constSelectedLayerNodes )
441 {
443 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
444 if ( !parentGroup || parentGroup == rootGroup )
445 continue;
446 QgsLayerTreeLayer *clonedLayer = l->clone();
447 rootGroup->addChildNode( clonedLayer );
448 parentGroup->removeChildNode( l );
449 }
450}
451
452
454{
455 const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
456 for ( QgsLayerTreeLayer *l : selectedLayerNodes )
457 {
459 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
460 if ( !parentGroup || parentGroup == rootGroup )
461 continue;
462 QgsLayerTreeGroup *tempGroup = parentGroup;
463 while ( tempGroup->parent() != rootGroup )
464 {
465 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
466 }
467 QgsLayerTreeLayer *clonedLayer = l->clone();
468 int insertIdx = rootGroup->children().indexOf( tempGroup );
469 rootGroup->insertChildNode( insertIdx, clonedLayer );
470 parentGroup->removeChildNode( l );
471 }
472}
473
474
476{
477 QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
478 std::reverse( selectedNodes.begin(), selectedNodes.end() );
479 // sort the nodes by depth first to avoid moving a group before its contents
480 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
481 {
482 return a->depth() > b->depth();
483 } );
484 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
485 {
486 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
487 QgsLayerTreeNode *clonedNode = n->clone();
488 parentGroup->insertChildNode( 0, clonedNode );
489 parentGroup->removeChildNode( n );
490 }
491}
492
493
495{
496 QList< QgsLayerTreeNode * > selectedNodes = mView->selectedNodes();
497 // sort the nodes by depth first to avoid moving a group before its contents
498 std::stable_sort( selectedNodes.begin(), selectedNodes.end(), []( const QgsLayerTreeNode * a, const QgsLayerTreeNode * b )
499 {
500 return a->depth() > b->depth();
501 } );
502 for ( QgsLayerTreeNode *n : std::as_const( selectedNodes ) )
503 {
504 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
505 QgsLayerTreeNode *clonedNode = n->clone();
506 parentGroup->insertChildNode( -1, clonedNode );
507 parentGroup->removeChildNode( n );
508 }
509}
510
511
513{
514 const QList<QgsLayerTreeNode *> nodes = mView->selectedNodes( true );
515 if ( nodes.empty() || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
516 return;
517
518 QgsLayerTreeGroup *parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
519 int insertIdx = parentGroup->children().indexOf( nodes[0] );
520
521 QgsLayerTreeGroup *newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
522 for ( QgsLayerTreeNode *node : nodes )
523 newGroup->addChildNode( node->clone() );
524
525 parentGroup->insertChildNode( insertIdx, newGroup );
526
527 for ( QgsLayerTreeNode *node : nodes )
528 {
529 QgsLayerTreeGroup *group = qobject_cast<QgsLayerTreeGroup *>( node->parent() );
530 if ( group )
531 group->removeChildNode( node );
532 }
533
534 mView->setCurrentIndex( mView->node2index( newGroup ) );
535 mView->edit( mView->node2index( newGroup ) );
536}
537
539{
541 if ( !node || !QgsLayerTree::isGroup( node ) )
542 return;
543
544 QgsLayerTree::toGroup( node )->setIsMutuallyExclusive( !QgsLayerTree::toGroup( node )->isMutuallyExclusive() );
545}
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)
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
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 list of selected nodes filtered to just layer nodes.
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 list of selected 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
Gets list of selected layers.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:53
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:43
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:64
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
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:73
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.
Definition: qgsproject.cpp:477
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:256
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:172
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:391
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:221
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:3061
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:3060