void QgsLegendLayer::rasterLayerSymbology( QgsRasterLayer* layer ) { SymbologyList itemList; QList< QPair< QString, QColor > > rasterItemList = layer->legendSymbologyItems(); QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin(); #if QT_VERSION >= 0x40700 itemList.reserve( rasterItemList.size() ); #endif // GetLegendGraphics in case of WMS service... pixmap can return null if GetLegendGraphics // is not supported by the server QgsDebugMsg( QString( "layer providertype:: %1" ).arg( layer->providerType() ) ); if ( layer->providerType() == "wms" ) { double currentScale = legend()->canvas()->scale(); QImage legendGraphic = layer->dataProvider()->getLegendGraphic( currentScale ); if ( !legendGraphic.isNull() ) { QgsDebugMsg( QString( "downloaded legend with dimension width:" ) + QString::number( legendGraphic.width() ) + QString( " and Height:" ) + QString::number( legendGraphic.height() ) ); #if QT_VERSION >= 0x40700 if ( rasterItemList.size() == 0 ) itemList.reserve( 1 ); #endif itemList.append( qMakePair( QString( "" ), QPixmap::fromImage( legendGraphic ) ) ); } } // Paletted raster may have many colors, for example UInt16 may have 65536 colors // and it is very slow, so we limit max count QSize iconSize = treeWidget()->iconSize(); int count = 0; int max_count = 1000; for ( ; itemIt != rasterItemList.constEnd(); ++itemIt ) { QPixmap itemPixmap( iconSize ); itemPixmap.fill( itemIt->second ); // This is very slow, not clear why, it should not be, probably realloc, // but it seems to be non linear itemList.append( qMakePair( itemIt->first, itemPixmap ) ); count++; if ( count == max_count ) { itemPixmap = QPixmap( iconSize ); itemPixmap.fill( Qt::transparent ); QString label = tr( "following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count ); itemList.append( qMakePair( label, itemPixmap ) ); break; } } changeSymbologySettings( layer, itemList ); }
void QgsLegendLayer::rasterLayerSymbology( QgsRasterLayer* layer ) { SymbologyList itemList; QList< QPair< QString, QColor > > rasterItemList = layer->legendSymbologyItems(); QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin(); #if QT_VERSION >= 0x40700 itemList.reserve( rasterItemList.size() ); #endif // Paletted raster may have many colors, for example UInt16 may have 65536 colors // and it is very slow, so we limit max count QSize iconSize = treeWidget()->iconSize(); int count = 0; int max_count = 1000; for ( ; itemIt != rasterItemList.constEnd(); ++itemIt ) { QPixmap itemPixmap( iconSize ); itemPixmap.fill( itemIt->second ); // This is very slow, not clear why, it should not be, probably realloc, // but it seems to be non linear itemList.append( qMakePair( itemIt->first, itemPixmap ) ); count++; if ( count == max_count ) { itemPixmap = QPixmap( iconSize ); itemPixmap.fill( Qt::transparent ); QString label = tr( "following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count ); itemList.append( qMakePair( label, itemPixmap ) ); break; } } changeSymbologySettings( layer, itemList ); }