Navigation Menu

Skip to content

Commit

Permalink
[FEATURE]: Show colormap items in legend
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 14, 2011
1 parent a954488 commit e28d1e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app/legend/qgslegendlayer.cpp
Expand Up @@ -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 );
}

Expand Down
26 changes: 26 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -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();

Expand Down

0 comments on commit e28d1e4

Please sign in to comment.