27 , mRegistryRemovingLayers( false )
29 , mNewLayersVisible( true )
30 , mInsertionPoint( root, 0 )
55 QList<QgsLayerTreeNode *> nodes;
74 if ( !projectFile.isEmpty() )
77 nodeLayer->
setCustomProperty( QStringLiteral(
"embedded_project" ), projectFile );
99 QgsDebugMsgLevel( QStringLiteral(
"%1 layers will be removed, enabled:%2" ).arg( layerIds.count() ).arg(
mEnabled ), 4 );
108 const auto constLayerIds = layerIds;
109 for (
const QString &layerId : constLayerIds )
113 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
120static void _collectLayerIdsInGroup(
QgsLayerTreeGroup *group,
int indexFrom,
int indexTo, QStringList &lst )
122 for (
int i = indexFrom; i <= indexTo; ++i )
156 QStringList toRemove;
158 for (
const QString &layerId : constMLayerIdsForRemoval )
163 QgsDebugMsgLevel( QStringLiteral(
"%1 layers will be removed" ).arg( toRemove.count() ), 4 );
168 QMetaObject::invokeMethod(
this,
"removeLayersFromRegistry", Qt::QueuedConnection, Q_ARG( QStringList, toRemove ) );
@ TopOfTree
Layers are added at the top of the layer tree.
@ AboveInsertionPoint
Layers are added in the tree above the insertion point.
@ OptimalInInsertionGroup
Layers are added at optimal locations across the insertion point's group.
Layer tree group node serves as a container for layers and further groups.
void insertChildNodes(int index, const QList< QgsLayerTreeNode * > &nodes)
Insert existing nodes at specified position.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
Layer tree node points to a map layer.
QString layerId() const
Returns the ID for the map layer associated with this node.
This class is a base class for nodes in a layer tree.
void removedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes has been removed from a node within the tree.
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
void willRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be removed from a node within the tree.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
void removeLayersFromRegistry(const QStringList &layerIds)
void groupRemovedChildren()
void layersWillBeRemoved(const QStringList &layerIds)
void layersAdded(const QList< QgsMapLayer * > &layers)
QStringList mLayerIdsForRemoval
void addedLayersToLayerTree(const QList< QgsMapLayer * > &layers)
Tell others we have just added layers to the tree (used in QGIS to auto-select first newly added laye...
void groupWillRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
QgsLayerTreeRegistryBridge(QgsLayerTreeGroup *root, QgsProject *project, QObject *parent=nullptr)
Create the instance that synchronizes given project with a layer tree root.
Q_DECL_DEPRECATED void setLayerInsertionPoint(QgsLayerTreeGroup *parentGroup, int index)
Set where the new layers should be inserted - can be used to follow current selection.
QgsLayerTreeGroup * mRoot
InsertionPoint mInsertionPoint
bool mRegistryRemovingLayers
Qgis::LayerTreeInsertionMethod mInsertionMethod
static QgsLayerTreeLayer * insertLayerAtOptimalPlacement(QgsLayerTreeGroup *group, QgsMapLayer *layer)
Inserts a layer within a given group at an optimal index position by insuring a given layer type will...
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
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.
Base class for all map layer types.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void removeMapLayers(const QStringList &layerIds)
Remove a set of layers from the registry by layer ID.
void legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted, when a layer was added to the registry and the legend.
QString layerIsEmbedded(const QString &id) const
Returns the source project file path if the layer with matching id is embedded from other project fil...
#define QgsDebugMsgLevel(str, level)
A structure to define the insertion point to the layer tree.
QgsLayerTreeGroup * group