2 changes: 1 addition & 1 deletion src/core/qgsrasterdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

SET(QGIS_GUI_SRCS

raster/qgsrasterrendererwidget.cpp
raster/qgsmultibandcolorrendererwidget.cpp
raster/qgspalettedrendererwidget.cpp
raster/qgssinglebandgrayrendererwidget.cpp
Expand Down
7 changes: 4 additions & 3 deletions src/gui/raster/qgsmultibandcolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgspalettedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
43 changes: 43 additions & 0 deletions src/gui/raster/qgsrasterrendererwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/***************************************************************************
qgsrasterrendererwidget.cpp
---------------------------
begin : June 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#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;
}
2 changes: 2 additions & 0 deletions src/gui/raster/qgsrasterrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/gui/raster/qgssinglebandgrayrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down