void QgsLegendModel::updateSymbolV2ItemText( QStandardItem* symbolItem ) { QgsComposerSymbolV2Item* sv2Item = dynamic_cast<QgsComposerSymbolV2Item*>( symbolItem ); if ( !sv2Item ) return; QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( sv2Item->parent() ); if ( !lItem ) return; QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() ); if ( !mapLayer ) return; QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer ); if ( !vLayer ) return; QgsFeatureRendererV2* renderer = vLayer->rendererV2(); if ( !renderer ) return; if ( lItem->showFeatureCount() ) vLayer->countSymbolFeatures(); QgsLegendSymbolList symbolList = renderer->legendSymbolItems(); QPair<QString, QgsSymbolV2*> symbol = symbolList.value( symbolItem->row() ); QString label = sv2Item->userText().isEmpty() ? symbol.first : sv2Item->userText(); if ( renderer->type() == "singleSymbol" ) { if ( !sv2Item->userText().isEmpty() ) { label = sv2Item->userText(); } else if ( !lItem->userText().isEmpty() ) { label = lItem->userText(); } else if ( !vLayer->title().isEmpty() ) { label = vLayer->title(); } else { label = vLayer->name(); } } if ( lItem->showFeatureCount() ) { // Add counts to multi symbols layers only or labeled single symbols, // so that single symbol layers are still drawn on single line if ( symbolList.size() > 1 || !label.isEmpty() ) { label += QString( " [%1]" ).arg( vLayer->featureCount( symbol.second ) ); } } symbolItem->setText( label ); }
void QgsLegendModel::updateLayerItemText( QStandardItem* layerItem ) { QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem ); if ( !lItem ) return; QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() ); if ( !mapLayer ) return; QString label = lItem->userText().isEmpty() ? mapLayer->name() : lItem->userText(); QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer ); if ( vLayer ) { addVectorLayerItemsV2( lItem, vLayer ); if ( lItem->showFeatureCount() ) { label += QString( " [%1]" ).arg( vLayer->featureCount() ); } } lItem->setText( label ); }