Skip to content

Commit

Permalink
Fix maybe uninitialized warnings in QgsLayerTreeRegistryBridge::layer…
Browse files Browse the repository at this point in the history
…sAdded

And make memory ownership of values clearer
  • Loading branch information
nyalldawson committed Feb 14, 2025
1 parent cc96192 commit d5db8a7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/layertree/qgslayertreeregistrybridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void QgsLayerTreeRegistryBridge::layersAdded( const QList<QgsMapLayer *> &layers
if ( !mEnabled )
return;

QList<QgsLayerTreeNode *> nodes;
QList<QgsLayerTreeNode *> newNodes;
for ( QgsMapLayer *layer : layers )
{
QgsLayerTreeLayer *nodeLayer;
QgsLayerTreeLayer *nodeLayer = nullptr;
switch ( mInsertionMethod )
{
case Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup:
Expand All @@ -72,6 +72,7 @@ void QgsLayerTreeRegistryBridge::layersAdded( const QList<QgsMapLayer *> &layers
if ( !targetGroup )
targetGroup = mRoot;

// returned layer is already owned by the group!
nodeLayer = QgsLayerTreeUtils::insertLayerAtOptimalPlacement( targetGroup, layer );
break;
}
Expand All @@ -80,13 +81,15 @@ void QgsLayerTreeRegistryBridge::layersAdded( const QList<QgsMapLayer *> &layers
case Qgis::LayerTreeInsertionMethod::TopOfTree:
{
nodeLayer = new QgsLayerTreeLayer( layer );
newNodes << nodeLayer;
break;
}
}

nodeLayer->setItemVisibilityChecked( mNewLayersVisible );
if ( !nodeLayer )
continue;

nodes << nodeLayer;
nodeLayer->setItemVisibilityChecked( mNewLayersVisible );

// check whether the layer is marked as embedded
const QString projectFile = mProject->layerIsEmbedded( nodeLayer->layerId() );
Expand All @@ -102,13 +105,13 @@ void QgsLayerTreeRegistryBridge::layersAdded( const QList<QgsMapLayer *> &layers
case Qgis::LayerTreeInsertionMethod::AboveInsertionPoint:
if ( QgsLayerTreeGroup *group = mInsertionPointGroup )
{
group->insertChildNodes( mInsertionPointPosition, nodes );
group->insertChildNodes( mInsertionPointPosition, newNodes );
break;
}
// if no group for the insertion point, then insert into root instead
[[fallthrough]];
case Qgis::LayerTreeInsertionMethod::TopOfTree:
mRoot->insertChildNodes( 0, nodes );
mRoot->insertChildNodes( 0, newNodes );
break;
case Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup:
break;
Expand Down

0 comments on commit d5db8a7

Please sign in to comment.