Add a "not set" option to QgsRasterBandComboBox

This commit is contained in:
Nyall Dawson 2017-05-09 10:48:08 +10:00
parent ddf8cc8485
commit c9bfb9f2a1
4 changed files with 51 additions and 5 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -19,6 +19,7 @@
QgsRasterBandComboBox::QgsRasterBandComboBox( QWidget *parent )
: QComboBox( parent )
, mNotSetString( tr( "Not set" ) )
{
connect( this, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]
{
@ -43,6 +44,9 @@ void QgsRasterBandComboBox::setLayer( QgsMapLayer *layer )
blockSignals( true );
clear();
if ( mShowNotSet )
addItem( mNotSetString, -1 );
if ( mLayer )
{
QgsRasterDataProvider *provider = mLayer->dataProvider();
@ -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 )

View File

@ -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:
/**
@ -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;