Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a "not set" option to QgsRasterBandComboBox
  • Loading branch information
nyalldawson committed May 9, 2017
1 parent ddf8cc8 commit c9bfb9f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
15 changes: 15 additions & 0 deletions python/gui/raster/qgsrasterbandcombobox.sip
Expand Up @@ -41,6 +41,21 @@ class QgsRasterBandComboBox : QComboBox
:rtype: int
%End

bool isShowingNotSetOption() const;
%Docstring
Returns true if the combo box is showing the "not set" option.
.. seealso:: setShowNotSetOption()
:rtype: bool
%End

void setShowNotSetOption( bool show, const QString &string = QString() );
%Docstring
Sets whether the combo box should show the "not set" option.
Optionally the built in "not set" text can be overridden by specifying
a ``string``.
.. seealso:: setShowNotSetOption()
%End

public slots:

void setLayer( QgsMapLayer *layer );
Expand Down
8 changes: 3 additions & 5 deletions src/gui/raster/qgsmultibandcolorrendererwidget.cpp
Expand Up @@ -57,15 +57,13 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
connect( mBlueBandComboBox, &QgsRasterBandComboBox::bandChanged,
this, &QgsMultiBandColorRendererWidget::onBandChanged );

mRedBandComboBox->setShowNotSetOption( true );
mGreenBandComboBox->setShowNotSetOption( true );
mBlueBandComboBox->setShowNotSetOption( true );
mRedBandComboBox->setLayer( mRasterLayer );
mGreenBandComboBox->setLayer( mRasterLayer );
mBlueBandComboBox->setLayer( mRasterLayer );

//fill available bands into combo boxes
mRedBandComboBox->insertItem( 0, tr( "Not set" ), -1 );
mGreenBandComboBox->insertItem( 0, tr( "Not set" ), -1 );
mBlueBandComboBox->insertItem( 0, tr( "Not set" ), -1 );

//contrast enhancement algorithms
mContrastEnhancementAlgorithmComboBox->addItem( tr( "No enhancement" ), QgsContrastEnhancement::NoEnhancement );
mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch to MinMax" ), QgsContrastEnhancement::StretchToMinimumMaximum );
Expand Down
16 changes: 16 additions & 0 deletions src/gui/raster/qgsrasterbandcombobox.cpp
Expand Up @@ -19,6 +19,7 @@

QgsRasterBandComboBox::QgsRasterBandComboBox( QWidget *parent )
: QComboBox( parent )
, mNotSetString( tr( "Not set" ) )
{
connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]
{
Expand All @@ -43,6 +44,9 @@ void QgsRasterBandComboBox::setLayer( QgsMapLayer *layer )
blockSignals( true );
clear();

if ( mShowNotSet )
addItem( mNotSetString, -1 );

if ( mLayer )
{
QgsRasterDataProvider *provider = mLayer->dataProvider();
Expand Down Expand Up @@ -70,6 +74,18 @@ void QgsRasterBandComboBox::setBand( int band )
setCurrentIndex( findData( band ) );
}

bool QgsRasterBandComboBox::isShowingNotSetOption() const
{
return mShowNotSet;
}

void QgsRasterBandComboBox::setShowNotSetOption( bool show, const QString &string )
{
mShowNotSet = show;
mNotSetString = string.isEmpty() ? tr( "Not set" ) : string;
setLayer( mLayer );
}

QString QgsRasterBandComboBox::displayBandName( QgsRasterDataProvider *provider, int band ) const
{
if ( !provider )
Expand Down
17 changes: 17 additions & 0 deletions src/gui/raster/qgsrasterbandcombobox.h
Expand Up @@ -55,6 +55,20 @@ class GUI_EXPORT QgsRasterBandComboBox : public QComboBox
*/
int currentBand() const;

/**
* Returns true if the combo box is showing the "not set" option.
* \see setShowNotSetOption()
*/
bool isShowingNotSetOption() const;

/**
* Sets whether the combo box should show the "not set" option.
* Optionally the built in "not set" text can be overridden by specifying
* a \a string.
* \see setShowNotSetOption()
*/
void setShowNotSetOption( bool show, const QString &string = QString() );

public slots:

/**
Expand All @@ -81,6 +95,9 @@ class GUI_EXPORT QgsRasterBandComboBox : public QComboBox

QPointer< QgsRasterLayer > mLayer;

bool mShowNotSet = false;
QString mNotSetString;

QString displayBandName( QgsRasterDataProvider *provider, int band ) const;


Expand Down

0 comments on commit c9bfb9f

Please sign in to comment.