Skip to content

Commit c236182

Browse files
committedApr 14, 2012
Modify raster legend mechanism to work with raster renderers
1 parent b4d7a30 commit c236182

7 files changed

+42
-0
lines changed
 

‎src/core/raster/qgscolorrampshader.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,12 @@ bool QgsColorRampShader::shade( double theRedValue, double theGreenValue,
293293

294294
return false;
295295
}
296+
297+
void QgsColorRampShader::legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const
298+
{
299+
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorRampIt = mColorRampItemList.constBegin();
300+
for ( ; colorRampIt != mColorRampItemList.constEnd(); ++colorRampIt )
301+
{
302+
symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
303+
}
304+
}

‎src/core/raster/qgscolorrampshader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
9191
/** \brief Generates and new RGB value based on original RGB value */
9292
bool shade( double, double, double, int*, int*, int* );
9393

94+
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
95+
9496
private:
9597
/** Current index from which to start searching the color table*/
9698
int mCurrentColorRampItemIndex;

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,13 @@ QString QgsRasterLayer::lastErrorTitle()
11691169
QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
11701170
{
11711171
QList< QPair< QString, QColor > > symbolList;
1172+
if ( mRenderer )
1173+
{
1174+
mRenderer->legendSymbologyItems( symbolList );
1175+
}
1176+
return symbolList;
1177+
1178+
#if 0
11721179
if ( mDrawingStyle == SingleBandGray || mDrawingStyle == PalettedSingleBandGray || mDrawingStyle == MultiBandSingleBandGray )
11731180
{
11741181
//add min/max from contrast enhancement
@@ -1244,6 +1251,7 @@ QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
12441251
}
12451252
}
12461253
return symbolList;
1254+
#endif //0
12471255
}
12481256

12491257
/**

‎src/core/raster/qgsrasterrenderer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define QGSRASTERRENDERER_H
2020

2121
#include "qgsrasterdataprovider.h"
22+
#include <QPair>
2223

2324
class QPainter;
2425
class QgsMapToPixel;
@@ -76,6 +77,9 @@ class QgsRasterRenderer
7677
void setMaxOversampling( double os ) { mMaxOversampling = os; }
7778
double maxOversampling() const { return mMaxOversampling; }
7879

80+
/**Get symbology items if provided by renderer*/
81+
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const { Q_UNUSED( symbolItems ); }
82+
7983
virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const = 0;
8084

8185
/**Sets base class members from xml. Usually called from create() methods of subclasses*/

‎src/core/raster/qgsrastershaderfunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ email : ersts@amnh.org
2424
* typically used to render grayscale images as false color.
2525
*/
2626

27+
#include <QColor>
28+
#include <QPair>
29+
2730
class CORE_EXPORT QgsRasterShaderFunction
2831
{
2932

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

54+
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const { Q_UNUSED( symbolItems ); }
55+
5156
protected:
5257
/** \brief User defineable maximum value for the shading function */
5358
double mMaximumValue;

‎src/core/raster/qgssinglebandpseudocolorrenderer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,15 @@ void QgsSingleBandPseudoColorRenderer::writeXML( QDomDocument& doc, QDomElement&
179179
}
180180
parentElem.appendChild( rasterRendererElem );
181181
}
182+
183+
void QgsSingleBandPseudoColorRenderer::legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const
184+
{
185+
if ( mShader )
186+
{
187+
QgsRasterShaderFunction* shaderFunction = mShader->rasterShaderFunction();
188+
if ( shaderFunction )
189+
{
190+
shaderFunction->legendSymbologyItems( symbolItems );
191+
}
192+
}
193+
}

‎src/core/raster/qgssinglebandpseudocolorrenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
4040

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

43+
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
44+
4345
private:
4446
QgsRasterShader* mShader;
4547
int mBand;

0 commit comments

Comments
 (0)
Please sign in to comment.