void QgsLegendModel::updateLayer( QStandardItem* layerItem ) { QgsDebugMsg( "Entered." ); QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem ); if ( lItem ) { QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() ); if ( mapLayer ) { //delete all the entries under layer item int currentRowCount = lItem->rowCount(); for ( int i = currentRowCount - 1; i >= 0; --i ) { lItem->removeRow( i ); } QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer ); //set layer name as item text QString label = mapLayer->name(); if ( vLayer && lItem->showFeatureCount() ) { label += QString( " [%1]" ).arg( vLayer->featureCount() ); } layerItem->setText( label ); if ( vLayer ) { if ( vLayer->isUsingRendererV2() ) { addVectorLayerItemsV2( lItem, vLayer ); } else { addVectorLayerItems( lItem, vLayer ); } } QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( mapLayer ); if ( rLayer ) { addRasterLayerItems( lItem, rLayer ); } } } }
void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer ) { if ( !theMapLayer ) { return; } QgsComposerLayerItem* layerItem = new QgsComposerLayerItem( theMapLayer->name() ); layerItem->setLayerID( theMapLayer->id() ); layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), layerItem ); switch ( theMapLayer->type() ) { case QgsMapLayer::VectorLayer: { QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( theMapLayer ); if ( vl ) { if ( vl->isUsingRendererV2() ) { addVectorLayerItemsV2( layerItem, vl ); } else { addVectorLayerItems( layerItem, vl ); } } break; } case QgsMapLayer::RasterLayer: addRasterLayerItems( layerItem, theMapLayer ); break; default: break; } emit layersChanged(); }