int QgsLegendModel::addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer ) { if ( !layerItem || !rlayer ) { return 1; } QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( rlayer ); if ( !rasterLayer ) { return 2; } QList< QPair< QString, QColor > > rasterItemList = rasterLayer->legendSymbologyItems(); QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin(); for(; itemIt != rasterItemList.constEnd(); ++itemIt ) { QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem( itemIt->first ); if( mHasTopLevelWindow ) { QPixmap itemPixmap( 20, 20 ); itemPixmap.fill( itemIt->second ); currentSymbolItem->setIcon( QIcon( itemPixmap ) ); } currentSymbolItem->setLayerID( rasterLayer->id() ); currentSymbolItem->setColor( itemIt->second ); int currentRowCount = layerItem->rowCount(); layerItem->setChild( currentRowCount, 0, currentSymbolItem ); } return 0; }
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 ); }
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(); for ( ; itemIt != rasterItemList.constEnd(); ++itemIt ) { QPixmap itemPixmap( treeWidget()->iconSize() ); itemPixmap.fill( itemIt->second ); itemList.append( qMakePair( itemIt->first, itemPixmap ) ); } changeSymbologySettings( layer, itemList ); }
int QgsLegendModel::addRasterLayerItems( QStandardItem* layerItem, QgsMapLayer* rlayer ) { if ( !layerItem || !rlayer ) { return 1; } QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( rlayer ); if ( !rasterLayer ) { return 2; } QList< QPair< QString, QColor > > rasterItemList = rasterLayer->legendSymbologyItems(); QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin(); int row = 0; for ( ; itemIt != rasterItemList.constEnd(); ++itemIt ) { QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem( itemIt->first ); QgsComposerRasterSymbolItem* oldSymbolItem = dynamic_cast<QgsComposerRasterSymbolItem*>( layerItem->child( row, 0 ) ); if ( oldSymbolItem ) { currentSymbolItem->setUserText( oldSymbolItem->userText() ); currentSymbolItem->setText( currentSymbolItem->userText() ); } if ( mHasTopLevelWindow ) { QPixmap itemPixmap( 20, 20 ); itemPixmap.fill( itemIt->second ); currentSymbolItem->setIcon( QIcon( itemPixmap ) ); } currentSymbolItem->setLayerID( rasterLayer->id() ); currentSymbolItem->setColor( itemIt->second ); int currentRowCount = layerItem->rowCount(); layerItem->setChild( currentRowCount, 0, currentSymbolItem ); row++; } // Delete following old items (if current number of items decreased) for ( int i = layerItem->rowCount() - 1; i >= row; --i ) { layerItem->removeRow( i ); } return 0; }
void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable ) { if ( itemElem.isNull() ) { return; } setText( itemElem.attribute( "text", "" ) ); setUserText( itemElem.attribute( "userText", "" ) ); setLayerID( itemElem.attribute( "layerId", "" ) ); setColor( QColor( itemElem.attribute( "color" ) ) ); if ( xServerAvailable ) { QPixmap itemPixmap( 20, 20 ); itemPixmap.fill( mColor ); setIcon( QIcon( itemPixmap ) ); } }