Skip to content
Permalink
Browse files

Improve legend for pseudocolor, freakout, grayscale

  • Loading branch information
mhugent committed Jun 15, 2011
1 parent 992be14 commit 4e78d8ea25acd9d4f22417df26824dc372f5e1ab
@@ -306,13 +306,6 @@ 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();
@@ -94,7 +94,7 @@ class CORE_EXPORT QgsContrastEnhancement
/** \brief Return the minimum value for the contrast enhancement range. */
double minimumValue() const { return mMinimumValue; }

ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() { return mContrastEnhancementAlgorithm; }
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const { return mContrastEnhancementAlgorithm; }

/*
*
@@ -44,6 +44,12 @@ class CORE_EXPORT QgsFreakOutShader : public QgsRasterShaderFunction
/** \brief Return the minimum value */
void setMinimumValue( double );

double classBreakMin1() const { return mClassBreakMin1; }
double classBreakMax1() const { return mClassBreakMax1; }
double classBreakMin2() const { return mClassBreakMin2; }
double classBreakMax2() const { return mClassBreakMax2; }
double classBreakMin3() const { return mClassBreakMin3; }

private:
void setClassBreaks();

@@ -256,7 +256,7 @@ typedef QgsDataProvider * classFactoryFunction_t( const QString * );
//
/////////////////////////////////////////////////////////

unsigned int QgsRasterLayer::bandCount()
unsigned int QgsRasterLayer::bandCount() const
{
return mBandCount;
}
@@ -274,7 +274,7 @@ const QString QgsRasterLayer::bandName( int theBandNo )
}
}

int QgsRasterLayer::bandNumber( QString const & theBandName )
int QgsRasterLayer::bandNumber( QString const & theBandName ) const
{
for ( int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator )
{
@@ -679,6 +679,16 @@ QgsContrastEnhancement* QgsRasterLayer::contrastEnhancement( unsigned int theBan
return 0;
}

const QgsContrastEnhancement* QgsRasterLayer::constContrastEnhancement( unsigned int theBand ) const
{
if ( 0 < theBand && theBand <= bandCount() )
{
return &mContrastEnhancementList[theBand - 1];
}

return 0;
}

QString QgsRasterLayer::contrastEnhancementAlgorithmAsString() const
{
switch ( mContrastEnhancementAlgorithm )
@@ -1238,12 +1248,51 @@ QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const
symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMin1() ), QColor( 0, 0, 255 ) ) );
symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMax1() ), QColor( 0, 255, 255 ) ) );
symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMax2() ), QColor(255, 255, 0 ) ) );
symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMin2() ), QColor( 255, 0, 0 ) ) );
symbolList.push_back( qMakePair( QString::number( pcShader->maximumValue() ), QColor( 255, 0, 0 ) ) );
}
break;
}
case FreakOutShader:
{
const QgsFreakOutShader* foShader = dynamic_cast<QgsFreakOutShader*>( mRasterShader->rasterShaderFunction() );
if( foShader )
{
symbolList.push_back( qMakePair( QString::number( foShader->classBreakMin1() ), QColor( 255, 0, 255 ) ) );
symbolList.push_back( qMakePair( QString::number( foShader->classBreakMax1() ), QColor( 0, 255, 255 ) ) );
symbolList.push_back( qMakePair( QString::number( foShader->classBreakMax2() ), QColor( 255, 0, 0 ) ) );
symbolList.push_back( qMakePair( QString::number( foShader->maximumValue() ), QColor( 0, 255, 0 ) ) );
}
}
default:
break;
{
//grayscale?
if( mDrawingStyle == SingleBandGray || mDrawingStyle == PalettedSingleBandGray || mDrawingStyle == MultiBandSingleBandGray )
{
//add min/max from contrast enhancement
QString grayBand = grayBandName();
if( !grayBand.isEmpty() )
{
int grayBandNr = bandNumber( grayBand );
const QgsContrastEnhancement* ceh = constContrastEnhancement( grayBandNr );
if( ceh )
{
QgsContrastEnhancement::ContrastEnhancementAlgorithm alg = ceh->contrastEnhancementAlgorithm();
if( alg == QgsContrastEnhancement::NoEnhancement
|| alg == QgsContrastEnhancement::ClipToMinimumMaximum )
{
//diffcult to display a meaningful item
symbolList.push_back( qMakePair( QString::number( ceh->minimumValue() ) + "-" + QString::number( ceh->maximumValue() ), QColor( 125, 125, 125 ) ) );
}
else
{
symbolList.push_back( qMakePair( QString::number( ceh->minimumValue() ), QColor( 0, 0, 0 ) ) );
symbolList.push_back( qMakePair( QString::number( ceh->maximumValue() ), QColor( 255, 255, 255 ) ) );
}
}
}
}
break;
}
}
return symbolList;
}
@@ -415,15 +415,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
// Non Static methods
//
/** \brief Get the number of bands in this layer */
unsigned int bandCount();
unsigned int bandCount() const;

/** \brief Get the name of a band given its number */
const QString bandName( int theBandNoInt );

/** \brief Get the number of a band given its name. The name is the rewritten name set
* up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
* If no matching band is found zero will be returned! */
int bandNumber( const QString & theBandName );
int bandNumber( const QString & theBandName ) const;

/** \brief Get RasterBandStats for a band given its number (read only) */
const QgsRasterBandStats bandStatistics( int );
@@ -464,6 +464,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Get a pointer to the contrast enhancement for the selected band */
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );

const QgsContrastEnhancement* constContrastEnhancement( unsigned int theBand ) const;

/**Copies the symbology settings from another layer. Returns true in case of success*/
bool copySymbologySettings( const QgsMapLayer& theOther );

@@ -45,6 +45,9 @@ class CORE_EXPORT QgsRasterShaderFunction

double minimumMaximumRange() const { return mMinimumMaximumRange; }

double minimumValue() const { return mMinimumValue; }
double maximumValue() const { return mMaximumValue; }

protected:
/** \brief User defineable maximum value for the shading function */
double mMaximumValue;

0 comments on commit 4e78d8e

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