Skip to content

Commit a765b5a

Browse files
committed
FIX BUG #8473 Cannot rename layers in composer legend
If the layer is a raster layer, the layer label is not updated with the user defined text. If the layer is a vector layer with simple symbol the symbol label cannot be updated and be blocked at layer name. The label can be the symbol user label, the layer user label, the layer title or the layer name.
1 parent 1bb2725 commit a765b5a

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/core/composer/qgslegendmodel.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,22 @@ void QgsLegendModel::updateSymbolV2ItemText( QStandardItem* symbolItem )
275275

276276
if ( renderer->type() == "singleSymbol" )
277277
{
278-
label = vLayer->name();
278+
if ( !sv2Item->userText().isEmpty() )
279+
{
280+
label = sv2Item->userText();
281+
}
282+
else if ( !lItem->userText().isEmpty() )
283+
{
284+
label = lItem->userText();
285+
}
286+
else if ( !vLayer->title().isEmpty() )
287+
{
288+
label = vLayer->title();
289+
}
290+
else
291+
{
292+
label = vLayer->name();
293+
}
279294
}
280295

281296
if ( lItem->showFeatureCount() )
@@ -380,10 +395,9 @@ void QgsLegendModel::updateLayer( QStandardItem* layerItem )
380395
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
381396
if ( mapLayer )
382397
{
383-
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
384-
385398
updateLayerItemText( lItem );
386399

400+
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
387401
if ( vLayer )
388402
{
389403
addVectorLayerItemsV2( lItem, vLayer );
@@ -406,14 +420,16 @@ void QgsLegendModel::updateLayerItemText( QStandardItem* layerItem )
406420
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
407421
if ( !mapLayer ) return;
408422

409-
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
410-
if ( !vLayer ) return;
411-
412423
QString label = lItem->userText().isEmpty() ? mapLayer->name() : lItem->userText();
413424

414-
if ( vLayer && lItem->showFeatureCount() )
425+
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
426+
if ( vLayer )
415427
{
416-
label += QString( " [%1]" ).arg( vLayer->featureCount() );
428+
addVectorLayerItemsV2( lItem, vLayer );
429+
if ( lItem->showFeatureCount() )
430+
{
431+
label += QString( " [%1]" ).arg( vLayer->featureCount() );
432+
}
417433
}
418434
lItem->setText( label );
419435
}

0 commit comments

Comments
 (0)