QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
54 QAction *a =
new QAction(
QgsApplication::getThemeIcon( QStringLiteral(
"/mActionInOverview.svg" ) ), tr(
"&Show in Overview" ), parent );
56 a->setCheckable(
true );
57 a->setChecked( node->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() );
69 text = tr(
"Re&name Group" );
71 text = tr(
"Re&name Layer" );
73 QAction *a =
new QAction( text, parent );
84 QAction *a =
new QAction( tr(
"Show Feature Count" ), parent );
86 a->setCheckable(
true );
87 a->setChecked( node->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
94 tr(
"&Zoom to Layer" ), parent );
95 a->setData( QVariant::fromValue(
reinterpret_cast<void *
>( canvas ) ) );
103 tr(
"&Zoom to Selection" ), parent );
104 a->setData( QVariant::fromValue(
reinterpret_cast<void *
>( canvas ) ) );
112 tr(
"&Zoom to Group" ), parent );
113 a->setData( QVariant::fromValue(
reinterpret_cast<void *
>( canvas ) ) );
120 QAction *a =
new QAction( tr(
"&Move to Top-level" ), parent );
129 QAction *a =
new QAction( tr(
"Move Out of &Group" ), parent );
136 QAction *a =
new QAction( tr(
"Move to &Top" ), parent );
143 QAction *a =
new QAction( tr(
"Move to &Bottom" ), parent );
150 QAction *a =
new QAction( tr(
"&Group Selected" ), parent );
161 QAction *a =
new QAction( tr(
"Mutually Exclusive Group" ), parent );
162 a->setCheckable(
true );
174 QAction *a =
new QAction( tr(
"Check and All its Children (⌘-click)" ), parent );
176 QAction *a =
new QAction( tr(
"Check and All its Children (Ctrl-click)" ), parent );
178 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
188 QAction *a =
new QAction( tr(
"Uncheck and All its Children (⌘-click)" ), parent );
190 QAction *a =
new QAction( tr(
"Uncheck and All its Children (Ctrl-click)" ), parent );
192 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
201 QAction *a =
new QAction( tr(
"Check and All its Parents" ), parent );
202 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
206 void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
214 void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
222 void QgsLayerTreeViewDefaultActions::checkAndAllParents()
251 qobject_cast<QgsLayerTreeGroup *>( node->
parent() )->removeChildNode( node );
265 int newValue = node->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt();
268 l->setCustomProperty( QStringLiteral(
"overview" ), newValue ? 0 : 1 );
277 int newValue = node->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt();
280 l->setCustomProperty( QStringLiteral(
"showFeatureCount" ), newValue ? 0 : 1 );
290 QList<QgsMapLayer *> layers;
310 QList<QgsMapLayer *> layers;
311 const auto constFindLayerIds = groupNode->
findLayerIds();
312 for (
const QString &layerId : constFindLayerIds )
320 QAction *s = qobject_cast<QAction *>( sender() );
322 QApplication::setOverrideCursor( Qt::WaitCursor );
324 QApplication::restoreOverrideCursor();
329 QAction *s = qobject_cast<QAction *>( sender() );
337 QAction *s = qobject_cast<QAction *>( sender() );
339 QApplication::setOverrideCursor( Qt::WaitCursor );
341 QApplication::restoreOverrideCursor();
350 for (
int i = 0; i < layers.size(); ++i )
364 layerExtent = vLayer->
extent();
368 if ( layerExtent.
isNull() )
381 extent.
scale( 1.05 );
392 QString newName = prefix +
'1';
393 for (
int i = 2; parentGroup->
findGroup( newName ); ++i )
394 newName = prefix + QString::number( i );
405 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
406 if ( !parentGroup || parentGroup == rootGroup )
421 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
422 if ( !parentGroup || parentGroup == rootGroup )
425 while ( tempGroup->
parent() != rootGroup )
427 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->
parent() );
430 int insertIdx = rootGroup->
children().indexOf( tempGroup );
440 std::reverse( selectedNodes.begin(), selectedNodes.end() );
444 return a->depth() > b->depth();
448 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
462 return a->depth() > b->depth();
466 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
481 int insertIdx = parentGroup->
children().indexOf( nodes[0] );
QgsLayerTreeGroup * currentGroupNode() const
Gets current group node. If a layer is current node, the function will return parent group....
QString uniqueGroupName(QgsLayerTreeGroup *parentGroup)
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void refresh()
Repaints the canvas map.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
QAction * actionRemoveGroupOrLayer(QObject *parent=nullptr)
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
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 * actionZoomToGroup(QgsMapCanvas *canvas, QObject *parent=nullptr)
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
QgsLayerTreeModel * layerTreeModel() const
Gets access to the model casted to QgsLayerTreeModel.
Q_DECL_DEPRECATED void makeTopLevel()
void renameGroupOrLayer()
static QgsProject * instance()
Returns the QgsProject singleton instance.
QAction * actionMoveToBottom(QObject *parent=nullptr)
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Returns list of selected nodes.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QAction * actionCheckAndAllChildren(QObject *parent=nullptr)
Action to check a group and all its children.
void moveOutOfGroup()
Moves selected layer(s) out of the group(s) and places this/these above the group(s)
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
QAction * actionShowFeatureCount(QObject *parent=nullptr)
bool isItemVisibilityCheckedRecursive() const
Returns whether this node is checked and all its children.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
QAction * actionAddGroup(QObject *parent=nullptr)
QAction * actionGroupSelected(QObject *parent=nullptr)
#define Q_NOWARN_DEPRECATED_POP
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns index for a given node. If the node does not belong to the layer tree, the result is undefine...
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 ...
void removeGroupOrLayer()
QAction * actionUncheckAndAllChildren(QObject *parent=nullptr)
Action to uncheck a group and all its children.
bool isItemVisibilityUncheckedRecursive() const
Returns whether this node is unchecked and all its children.
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
QAction * actionZoomToLayer(QgsMapCanvas *canvas, QObject *parent=nullptr)
virtual QgsRectangle extent() const
Returns the extent of the layer.
Q_DECL_DEPRECATED QAction * actionMakeTopLevel(QObject *parent=nullptr)
void mutuallyExclusiveGroup()
Slot to enable/disable mutually exclusive group flag.
QgsLayerTreeNode * currentNode() const
Gets current node. May be nullptr.
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
QAction * actionMoveToTop(QObject *parent=nullptr)
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
QAction * actionMoveOutOfGroup(QObject *parent=nullptr)
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
QAction * actionCheckAndAllParents(QObject *parent=nullptr)
Action to check a group and all its parents.
void zoomToLayers(QgsMapCanvas *canvas, const QList< QgsMapLayer * > &layers)
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
QgsMapLayer * currentLayer() const
Returns the currently selected layer, or nullptr if no layers is selected.
void zoomToSelection()
Slot to zoom to selected features of a vector layer.
QAction * actionShowInOverview(QObject *parent=nullptr)
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
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.
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Returns list of selected nodes filtered to just layer nodes.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
QAction * actionMutuallyExclusiveGroup(QObject *parent=nullptr)
Action to enable/disable mutually exclusive flag of a group (only one child node may be checked)
QAction * actionRenameGroupOrLayer(QObject *parent=nullptr)
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well)
QAction * actionZoomToSelection(QgsMapCanvas *canvas, QObject *parent=nullptr)
Action to zoom to selected features of a vector layer.
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
#define Q_NOWARN_DEPRECATED_PUSH
bool isEmpty() const
Returns true if the rectangle is empty.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Temporarily sets a cursor override for the QApplication for the lifetime of the object.