Skip to content

Commit

Permalink
Modify raster legend mechanism to work with raster renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 14, 2012
1 parent b4d7a30 commit c236182
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/raster/qgscolorrampshader.cpp
Expand Up @@ -293,3 +293,12 @@ bool QgsColorRampShader::shade( double theRedValue, double theGreenValue,

return false;
}

void QgsColorRampShader::legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const
{
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorRampIt = mColorRampItemList.constBegin();
for ( ; colorRampIt != mColorRampItemList.constEnd(); ++colorRampIt )
{
symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
}
}
2 changes: 2 additions & 0 deletions src/core/raster/qgscolorrampshader.h
Expand Up @@ -91,6 +91,8 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
/** \brief Generates and new RGB value based on original RGB value */
bool shade( double, double, double, int*, int*, int* );

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

private:
/** Current index from which to start searching the color table*/
int mCurrentColorRampItemIndex;
Expand Down
8 changes: 8 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1169,6 +1169,13 @@ QString QgsRasterLayer::lastErrorTitle()
QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
{
QList< QPair< QString, QColor > > symbolList;
if ( mRenderer )
{
mRenderer->legendSymbologyItems( symbolList );
}
return symbolList;

#if 0
if ( mDrawingStyle == SingleBandGray || mDrawingStyle == PalettedSingleBandGray || mDrawingStyle == MultiBandSingleBandGray )
{
//add min/max from contrast enhancement
Expand Down Expand Up @@ -1244,6 +1251,7 @@ QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
}
}
return symbolList;
#endif //0
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Expand Up @@ -19,6 +19,7 @@
#define QGSRASTERRENDERER_H

#include "qgsrasterdataprovider.h"
#include <QPair>

class QPainter;
class QgsMapToPixel;
Expand Down Expand Up @@ -76,6 +77,9 @@ class QgsRasterRenderer
void setMaxOversampling( double os ) { mMaxOversampling = os; }
double maxOversampling() const { return mMaxOversampling; }

/**Get symbology items if provided by renderer*/
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const { Q_UNUSED( symbolItems ); }

virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const = 0;

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
Expand Down
5 changes: 5 additions & 0 deletions src/core/raster/qgsrastershaderfunction.h
Expand Up @@ -24,6 +24,9 @@ email : ersts@amnh.org
* typically used to render grayscale images as false color.
*/

#include <QColor>
#include <QPair>

class CORE_EXPORT QgsRasterShaderFunction
{

Expand All @@ -48,6 +51,8 @@ class CORE_EXPORT QgsRasterShaderFunction
double minimumValue() const { return mMinimumValue; }
double maximumValue() const { return mMaximumValue; }

virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const { Q_UNUSED( symbolItems ); }

protected:
/** \brief User defineable maximum value for the shading function */
double mMaximumValue;
Expand Down
12 changes: 12 additions & 0 deletions src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Expand Up @@ -179,3 +179,15 @@ void QgsSingleBandPseudoColorRenderer::writeXML( QDomDocument& doc, QDomElement&
}
parentElem.appendChild( rasterRendererElem );
}

void QgsSingleBandPseudoColorRenderer::legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const
{
if ( mShader )
{
QgsRasterShaderFunction* shaderFunction = mShader->rasterShaderFunction();
if ( shaderFunction )
{
shaderFunction->legendSymbologyItems( symbolItems );
}
}
}
2 changes: 2 additions & 0 deletions src/core/raster/qgssinglebandpseudocolorrenderer.h
Expand Up @@ -40,6 +40,8 @@ class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

private:
QgsRasterShader* mShader;
int mBand;
Expand Down

0 comments on commit c236182

Please sign in to comment.