Skip to content

Commit

Permalink
Use band number as text in raster renderer widgets if color interpret…
Browse files Browse the repository at this point in the history
…ation is undefined. Fix for ticket #5799
  • Loading branch information
mhugent committed Jun 15, 2012
1 parent ab1c989 commit 57ee799
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsrasterdataprovider.h
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
@@ -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
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
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
26 changes: 26 additions & 0 deletions src/gui/raster/qgsrasterrendererwidget.cpp
@@ -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;
}
2 changes: 2 additions & 0 deletions src/gui/raster/qgsrasterrendererwidget.h
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
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
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

0 comments on commit 57ee799

Please sign in to comment.