25#include "moc_qgslayertreeregistrybridge.cpp"
27using namespace Qt::StringLiterals;
65 QList<QgsLayerTreeNode *> newNodes;
86 newNodes << nodeLayer;
97 const QString projectFile =
mProject->layerIsEmbedded( nodeLayer->
layerId() );
98 if ( !projectFile.isEmpty() )
116 mRoot->insertChildNodes( 0, newNodes );
137 const auto constLayerIds = layerIds;
138 for (
const QString &layerId : constLayerIds )
142 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
149static void _collectLayerIdsInGroup(
QgsLayerTreeGroup *group,
int indexFrom,
int indexTo, QStringList &lst )
151 for (
int i = indexFrom; i <= indexTo; ++i )
185 QStringList toRemove;
187 for (
const QString &layerId : constMLayerIdsForRemoval )
188 if ( !
mRoot->findLayer( layerId ) )
192 QgsDebugMsgLevel( u
"%1 layers will be removed"_s.arg( toRemove.count() ), 4 );
197 QMetaObject::invokeMethod(
this,
"removeLayersFromRegistry", Qt::QueuedConnection, Q_ARG( QStringList, toRemove ) );
202 mProject->removeMapLayers( layerIds );
@ 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.
Layer tree node points to a map layer.
QString layerId() const
Returns the ID for the map layer associated with this node.
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
int mInsertionPointPosition
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)
QPointer< QgsLayerTreeGroup > mInsertionPointGroup
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 layerInsertionPoint() const
Returns the insertion point used to add layers to the tree.
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 legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted when layers were added to the registry and the legend.
#define QgsDebugMsgLevel(str, level)
A structure to define the insertion point to the layer tree.
QgsLayerTreeGroup * group