Skip to content
Permalink
Browse files

Use band number as text in raster renderer widgets if color interpret…

…ation is undefined. Fix for ticket #5799
  • Loading branch information
mhugent committed Jun 15, 2012
1 parent ab1c989 commit 57ee79911c48dd3e29ee9be46bbdd6f67cb78031
@@ -376,7 +376,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
virtual QgsRasterBandStats bandStatistics( int theBandNo );

/** \brief helper function to create zero padded band names */
QString generateBandName( int theBandNumber )
QString generateBandName( int theBandNumber ) const
{
return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
}
@@ -1,6 +1,7 @@

SET(QGIS_GUI_SRCS

raster/qgsrasterrendererwidget.cpp
raster/qgsmultibandcolorrendererwidget.cpp
raster/qgspalettedrendererwidget.cpp
raster/qgssinglebandgrayrendererwidget.cpp
@@ -46,9 +46,10 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mRedBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mGreenBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mBlueBandComboBox->addItem( provider->colorInterpretationName( i ), i );
QString bandName = displayBandName( i );
mRedBandComboBox->addItem( bandName, i );
mGreenBandComboBox->addItem( bandName, i );
mBlueBandComboBox->addItem( bandName, i );
}

setFromRenderer( mRasterLayer->renderer() );
@@ -36,7 +36,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer* layer ): Q
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mBandComboBox->addItem( displayBandName( i ), i );
}

setFromRenderer( mRasterLayer->renderer() );
@@ -0,0 +1,26 @@
#include "qgsrasterrendererwidget.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasterlayer.h"


QString QgsRasterRendererWidget::displayBandName( int band ) const
{
QString name;
if ( !mRasterLayer )
{
return name;
}

const QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
if ( !provider )
{
return name;
}

name = provider->colorInterpretationName( band );
if ( name == "Undefined" )
{
name = provider->generateBandName( band );
}
return name;
}
@@ -36,6 +36,8 @@ class GUI_EXPORT QgsRasterRendererWidget: public QWidget

protected:
QgsRasterLayer* mRasterLayer;
/**Returns a band name for display. First choice is color name, otherwise band number*/
QString displayBandName( int band ) const;
};

#endif // QGSRASTERRENDERERWIDGET_H
@@ -37,7 +37,7 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mGrayBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mGrayBandComboBox->addItem( displayBandName( i ), i );
}

//contrast enhancement algorithms
@@ -44,7 +44,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mBandComboBox->addItem( displayBandName( i ), i );
}

mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 );

0 comments on commit 57ee799

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