54 QAction *a =
new QAction( tr(
"&Show in Overview" ), parent );
56 a->setCheckable(
true );
57 a->setChecked( node->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() );
63 QAction *a =
new QAction( tr(
"Re&name" ), parent );
74 QAction *a =
new QAction( tr(
"Show Feature Count" ), parent );
76 a->setCheckable(
true );
77 a->setChecked( node->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
84 tr(
"&Zoom to Layer" ), parent );
85 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
93 tr(
"&Zoom to Group" ), parent );
94 a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
101 QAction *a =
new QAction( tr(
"&Move to Top-level" ), parent );
108 QAction *a =
new QAction( tr(
"&Group Selected" ), parent );
119 QAction *a =
new QAction( tr(
"Mutually Exclusive Group" ), parent );
120 a->setCheckable(
true );
132 QAction *a =
new QAction( tr(
"Check and all its Children (⌘-click)" ), parent );
134 QAction *a =
new QAction( tr(
"Check and all its Children (Ctrl-click)" ), parent );
136 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllChildren );
146 QAction *a =
new QAction( tr(
"Uncheck and all its Children (⌘-click)" ), parent );
148 QAction *a =
new QAction( tr(
"Uncheck and all its Children (Ctrl-click)" ), parent );
150 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::uncheckAndAllChildren );
159 QAction *a =
new QAction( tr(
"Check and all its Parents" ), parent );
160 connect( a, &QAction::triggered,
this, &QgsLayerTreeViewDefaultActions::checkAndAllParents );
164 void QgsLayerTreeViewDefaultActions::checkAndAllChildren()
172 void QgsLayerTreeViewDefaultActions::uncheckAndAllChildren()
180 void QgsLayerTreeViewDefaultActions::checkAndAllParents()
217 int newValue = node->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt();
228 int newValue = node->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt();
240 QList<QgsMapLayer *> layers;
251 QList<QgsMapLayer *> layers;
252 Q_FOREACH (
const QString &layerId, groupNode->
findLayerIds() )
260 QAction *s = qobject_cast<QAction *>( sender() );
262 QApplication::setOverrideCursor( Qt::WaitCursor );
264 QApplication::restoreOverrideCursor();
269 QAction *s = qobject_cast<QAction *>( sender() );
271 QApplication::setOverrideCursor( Qt::WaitCursor );
273 QApplication::restoreOverrideCursor();
282 for (
int i = 0; i < layers.size(); ++i )
296 layerExtent = vLayer->
extent();
300 if ( layerExtent.
isNull() )
313 extent.
scale( 1.05 );
324 QString newName = prefix +
'1';
325 for (
int i = 2; parentGroup->
findGroup( newName ); ++i )
326 newName = prefix + QString::number( i );
337 if ( !parentGroup || parentGroup == rootGroup )
353 int insertIdx = parentGroup->
children().indexOf( nodes[0] );
Layer tree group node serves as a container for layers and further groups.
A rectangle specified with double values.
Base class for all map layer types.
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
bool isItemVisibilityUncheckedRecursive() const
Return whether this node is unchecked and all its children.
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
void zoomToLayers(QgsMapCanvas *canvas, const QList< QgsMapLayer *> &layers)
QAction * actionZoomToGroup(QgsMapCanvas *canvas, QObject *parent=nullptr)
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
QAction * actionCheckAndAllChildren(QObject *parent=nullptr)
Action to check a group and all its children.
QgsLayerTreeViewDefaultActions(QgsLayerTreeView *view)
QAction * actionAddGroup(QObject *parent=nullptr)
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
void renameGroupOrLayer()
QAction * actionGroupSelected(QObject *parent=nullptr)
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QAction * actionRemoveGroupOrLayer(QObject *parent=nullptr)
void refresh()
Repaints the canvas map.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well) ...
QgsMapLayer * currentLayer() const
Get currently selected layer. May be null.
QModelIndex node2index(QgsLayerTreeNode *node) const
Return index for a given node. If the node does not belong to the layer tree, the result is undefined...
Map canvas is a class for displaying all GIS data types on a canvas.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Return list of selected nodes filtered to just layer nodes.
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
virtual void updateExtents(bool force=false)
Update the extents for the layer.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules) ...
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
void removeGroupOrLayer()
QgsRectangle extent() const override
Returns the extent of the layer.
bool isEmpty() const
Returns true if the rectangle is empty.
QAction * actionMakeTopLevel(QObject *parent=nullptr)
void mutuallyExclusiveGroup()
Slot to enable/disable mutually exclusive group flag.
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node.
QgsLayerTreeGroup * currentGroupNode() const
Get current group node. If a layer is current node, the function will return parent group...
QAction * actionCheckAndAllParents(QObject *parent=nullptr)
Action to check a group and all its parents.
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...
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
QgsLayerTreeModel * layerTreeModel() const
Get access to the model casted to QgsLayerTreeModel.
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
bool isItemVisibilityCheckedRecursive() const
Return whether this node is checked and all its children.
QAction * actionZoomToLayer(QgsMapCanvas *canvas, QObject *parent=nullptr)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void combineExtentWith(const QgsRectangle &rect)
Expand the rectangle so that covers both the original rectangle and the given rectangle.
QAction * actionMutuallyExclusiveGroup(QObject *parent=nullptr)
Action to enable/disable mutually exclusive flag of a group (only one child node may be checked) ...
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Return list of selected nodes.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
QgsLayerTree * rootGroup() const
Return pointer to the root node of the layer tree. Always a non-null pointer.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString uniqueGroupName(QgsLayerTreeGroup *parentGroup)
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
void setExtent(const QgsRectangle &r, bool magnified=false)
Set the extent of the map canvas.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
QAction * actionShowFeatureCount(QObject *parent=nullptr)
QAction * actionRenameGroupOrLayer(QObject *parent=nullptr)
Represents a vector layer which manages a vector based data sets.
QAction * actionUncheckAndAllChildren(QObject *parent=nullptr)
Action to uncheck a group and all its children.
QgsLayerTreeLayer * clone() const override
Create a copy of the node. Returns new instance.
QAction * actionShowInOverview(QObject *parent=nullptr)
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the node. Properties are stored in a map and saved in project file...
Layer tree node points to a map layer.
QgsLayerTreeNode * currentNode() const
Get current node. May be null.