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 ) ) );
105 tr(
"&Zoom to Layer(s)" ), parent );
106 a->setData( QVariant::fromValue( canvas ) );
114 tr(
"Zoom to &Selection" ), parent );
115 a->setData( QVariant::fromValue(
reinterpret_cast<void *
>( canvas ) ) );
123 tr(
"&Zoom to Group" ), parent );
124 a->setData( QVariant::fromValue(
reinterpret_cast<void *
>( canvas ) ) );
131 QAction *a =
new QAction( tr(
"&Move to Top-level" ), parent );
140 QAction *a =
new QAction( tr(
"Move O&ut of Group" ), parent );
147 QAction *a =
new QAction( tr(
"Move to &Top" ), parent );
154 QAction *a =
new QAction( tr(
"Move to &Bottom" ), parent );
161 QAction *a =
new QAction( tr(
"&Group Selected" ), parent );
172 QAction *a =
new QAction( tr(
"&Mutually Exclusive Group" ), parent );
173 a->setCheckable(
true );
185 QAction *a =
new QAction( tr(
"Check and All its Children (⌘-click)" ), parent );
187 QAction *a =
new QAction( tr(
"Check and All its Children (Ctrl-click)" ), parent );
189 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
199 QAction *a =
new QAction( tr(
"Uncheck and All its Children (⌘-click)" ), parent );
201 QAction *a =
new QAction( tr(
"Uncheck and All its Children (Ctrl-click)" ), parent );
203 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
212 QAction *a =
new QAction( tr(
"Chec&k and All its Parents" ), parent );
213 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
217 void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
225 void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
233 void QgsLayerTreeViewDefaultActions::checkAndAllParents()
263 qobject_cast<QgsLayerTreeGroup *>( node->
parent() )->removeChildNode( node );
277 int newValue = node->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt();
280 l->setCustomProperty( QStringLiteral(
"overview" ), newValue ? 0 : 1 );
289 int newValue = node->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt();
292 l->setCustomProperty( QStringLiteral(
"showFeatureCount" ), newValue ? 0 : 1 );
301 const QList<QgsMapLayer *> layers { layer };
318 if ( layers.size() > 1 )
320 else if ( layers.size() <= 1 && layer )
331 QList<QgsMapLayer *> layers;
332 const QStringList findLayerIds = groupNode->
findLayerIds();
333 for (
const QString &layerId : findLayerIds )
342 QAction *s = qobject_cast<QAction *>( sender() );
351 QAction *s = qobject_cast<QAction *>( sender() );
358 QAction *s = qobject_cast<QAction *>( sender() );
365 QAction *s = qobject_cast<QAction *>( sender() );
377 if ( !layers.empty() )
379 for (
int i = 0; i < layers.size(); ++i )
393 layerExtent = vLayer->
extent();
397 if ( layerExtent.
isNull() )
419 extent.
scale( 1.05 );
430 QString newName = prefix +
'1';
431 for (
int i = 2; parentGroup->
findGroup( newName ); ++i )
432 newName = prefix + QString::number( i );
443 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
444 if ( !parentGroup || parentGroup == rootGroup )
459 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
460 if ( !parentGroup || parentGroup == rootGroup )
463 while ( tempGroup->
parent() != rootGroup )
465 tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->
parent() );
468 int insertIdx = rootGroup->
children().indexOf( tempGroup );
478 std::reverse( selectedNodes.begin(), selectedNodes.end() );
482 return a->depth() > b->depth();
486 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
500 return a->depth() > b->depth();
504 QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
519 int insertIdx = parentGroup->
children().indexOf( nodes[0] );
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.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
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.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
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 removeGroupOrLayer()
void zoomToLayers()
Zooms to the combined extent of all the selected layer(s) in the layer tree.
Q_DECL_DEPRECATED void makeTopLevel()
void renameGroupOrLayer()
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.
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 setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
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.
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 (all coordinates zero or after call to setMinimal()).
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
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 is empty.
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.
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
#define Q_NOWARN_DEPRECATED_PUSH