Skip to content
Permalink
Browse files

[FEATURE]: Show colormap items in legend

  • Loading branch information
mhugent committed Jun 14, 2011
1 parent a954488 commit e28d1e45fc0710a46595305ab671f1a0be5ea757
Showing with 42 additions and 0 deletions.
  1. +12 −0 src/app/legend/qgslegendlayer.cpp
  2. +26 −0 src/core/raster/qgsrasterlayer.cpp
  3. +4 −0 src/core/raster/qgsrasterlayer.h
@@ -306,10 +306,22 @@ void QgsLegendLayer::vectorLayerSymbologyV2( QgsVectorLayer* layer )

void QgsLegendLayer::rasterLayerSymbology( QgsRasterLayer* layer )
{
#if 0
SymbologyList itemList;
QPixmap legendpixmap = layer->legendAsPixmap( true ).scaled( 20, 20, Qt::KeepAspectRatio );
itemList.append( qMakePair( QString(), legendpixmap ) );

changeSymbologySettings( layer, itemList );
#endif //0
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 );
}

@@ -1209,6 +1209,32 @@ QString QgsRasterLayer::lastErrorTitle()
return mErrorCaption;
}

QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
{
QList< QPair< QString, QColor > > symbolList;

switch ( mColorShadingAlgorithm )
{
case ColorRampShader:
{
const QgsColorRampShader* crShader = dynamic_cast<QgsColorRampShader*>( mRasterShader->rasterShaderFunction() );
if( crShader )
{
QList<QgsColorRampShader::ColorRampItem> shaderItems = crShader->colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = shaderItems.constBegin();
for(; itemIt != shaderItems.constEnd(); ++itemIt )
{
symbolList.push_back( qMakePair( itemIt->label, itemIt->color ) );
}
}
break;
}
default:
break;
}
return symbolList;
}

/**
* This is an overloaded version of the legendAsPixmap( bool ) assumes false for the legend name flag.
* @return a pixmap representing a legend image
@@ -521,6 +521,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */
QString lastErrorTitle();

/**Returns a list with classification items (Text and color)
@note this method was added in version 1.8*/
QList< QPair< QString, QColor > > legendSymbologyItems() const;

/** \brief Get a legend image for this layer */
QPixmap legendAsPixmap();

0 comments on commit e28d1e4

Please sign in to comment.
You can’t perform that action at this time.