23#include "moc_qgsrasterbandcombobox.cpp"
25using namespace Qt::StringLiterals;
29 , mNotSetString( tr(
"Not set" ) )
31 connect(
this,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this] {
32 if ( mLayer && mLayer->isValid() )
34 const int newBand = currentIndex() >= 0 ? currentData().toInt() : -1;
35 if ( newBand != mPrevBand )
37 emit
bandChanged( currentIndex() >= 0 ? currentData().toInt() : -1 );
43 connect(
this, &QComboBox::currentTextChanged,
this, [
this](
const QString &value ) {
44 if ( !mLayer || !mLayer->isValid() )
47 const int band = value.toInt( &ok );
48 if ( ok &&
band != mPrevBand )
53 else if ( mShowNotSet && mPrevBand != -1 )
64 setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon );
74 if ( !mLayer || !mLayer->dataProvider() || !mLayer->isValid() )
77 const int band = currentText().toInt( &ok );
84 if ( currentIndex() < 0 )
87 return currentData().toInt();
102 addItem( mNotSetString, -1 );
107 if ( provider && mLayer->
isValid() )
109 setEditable(
false );
111 const int nBands = provider->
bandCount();
112 for (
int i = 1; i <= nBands; ++i )
130 setCurrentIndex( 0 );
132 blockSignals(
false );
141 if ( !mLayer || !mLayer->dataProvider() || !mLayer->isValid() )
145 setCurrentIndex( -1 );
146 if ( mPrevBand != -1 )
150 setCurrentText( QString::number(
band ) );
154 setCurrentIndex( findData(
band ) );
167 mNotSetString =
string.isEmpty() ? tr(
"Not set" ) : string;
181 if ( !description.isEmpty() )
183 return name.contains( description, Qt::CaseInsensitive ) ? name : u
"%1 - %2"_s.arg( name, description );
virtual bool isValid() const =0
Returns true if this is a valid layer.
Base class for all map layer types.
QgsRasterLayer * layer() const
Returns the layer currently associated with the combobox.
void bandChanged(int band)
Emitted when the currently selected band changes.
void setShowNotSetOption(bool show, const QString &string=QString())
Sets whether the combo box should show the "not set" option.
int currentBand() const
Returns the current band number selected in the combobox, or -1 if no band is selected.
QgsRasterBandComboBox(QWidget *parent=nullptr)
Constructor for QgsRasterBandComboBox.
void setLayer(QgsMapLayer *layer)
Sets the raster layer for which the bands are listed in the combobox.
static QString displayBandName(QgsRasterDataProvider *provider, int band)
Returns a user-friendly band name for the specified band.
bool isShowingNotSetOption() const
Returns true if the combo box is showing the "not set" option.
void setBand(int band)
Sets the current band number selected in the combobox.
Base class for raster data providers.
virtual QString bandDescription(int bandNumber)
Returns the description for band bandNumber, or an empty string if the band is not valid or has not d...
virtual int bandCount() const =0
Gets number of bands.
QString displayBandName(int bandNumber) const
Generates a friendly, descriptive name for the specified bandNumber.
Represents a raster layer.