Skip to content

Commit

Permalink
Flip some more custom raster band combo boxes to QgsRasterBandComboBox
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 9, 2017
1 parent e4a94bc commit f4b353c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 82 deletions.
28 changes: 4 additions & 24 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
//transparency band
if ( provider )
{
cboxTransparencyBand->addItem( tr( "None" ), -1 );
int nBands = provider->bandCount();
QString bandName;
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
bandName = provider->generateBandName( i );

QString colorInterp = provider->colorInterpretationName( i );
if ( colorInterp != QLatin1String( "Undefined" ) )
{
bandName.append( QStringLiteral( " (%1)" ).arg( colorInterp ) );
}
cboxTransparencyBand->addItem( bandName, i );
}
cboxTransparencyBand->setShowNotSetOption( true, tr( "None" ) );
cboxTransparencyBand->setLayer( mRasterLayer );

// Alpha band is set in sync()
#if 0
Expand Down Expand Up @@ -667,15 +655,7 @@ void QgsRasterLayerProperties::sync()
//update the transparency percentage label
sliderTransparency_valueChanged( ( 1.0 - renderer->opacity() ) * 255 );

int myIndex = renderer->alphaBand();
if ( -1 != myIndex )
{
cboxTransparencyBand->setCurrentIndex( myIndex );
}
else
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findText( TRSTRING_NOT_SET ) );
}
cboxTransparencyBand->setBand( renderer->alphaBand() );
}

//add current NoDataValue to NoDataValue line edit
Expand Down Expand Up @@ -888,7 +868,7 @@ void QgsRasterLayerProperties::apply()
QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
if ( rasterRenderer )
{
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentData().toInt() );
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentBand() );

//Walk through each row in table and test value. If not valid set to 0.0 and continue building transparency list
QgsRasterTransparency *rasterTransparency = new QgsRasterTransparency();
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 @@ -400,7 +400,7 @@ void QgsPalettedRendererWidget::classify()
return;
}

mGatherer = new QgsPalettedRendererClassGatherer( mRasterLayer, mBandComboBox->currentBand(), btnColorRamp->colorRamp() );
mGatherer = new QgsPalettedRendererClassGatherer( mRasterLayer, mBandComboBox->currentBand(), mModel->classData(), btnColorRamp->colorRamp() );

connect( mGatherer, &QgsPalettedRendererClassGatherer::progressChanged, mCalculatingProgressBar, &QProgressBar::setValue );
mCalculatingProgressBar->show();
Expand Down
30 changes: 5 additions & 25 deletions src/gui/raster/qgsrastertransparencywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QgsRasterTransparencyWidget::QgsRasterTransparencyWidget( QgsRasterLayer *layer,
syncToLayer();

connect( sliderTransparency, &QAbstractSlider::valueChanged, this, &QgsPanelWidget::widgetChanged );
connect( cboxTransparencyBand, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPanelWidget::widgetChanged );
connect( cboxTransparencyBand, &QgsRasterBandComboBox::bandChanged, this, &QgsPanelWidget::widgetChanged );
connect( sliderTransparency, &QAbstractSlider::valueChanged, this, &QgsRasterTransparencyWidget::sliderTransparency_valueChanged );

mPixelSelectorTool = nullptr;
Expand Down Expand Up @@ -74,34 +74,14 @@ void QgsRasterTransparencyWidget::syncToLayer()
gboxCustomTransparency->setEnabled( false );
}

cboxTransparencyBand->addItem( tr( "None" ), -1 );
int nBands = provider->bandCount();
QString bandName;
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
bandName = provider->generateBandName( i );

QString colorInterp = provider->colorInterpretationName( i );
if ( colorInterp != QLatin1String( "Undefined" ) )
{
bandName.append( QStringLiteral( " (%1)" ).arg( colorInterp ) );
}
cboxTransparencyBand->addItem( bandName, i );
}
cboxTransparencyBand->setShowNotSetOption( true, tr( "None" ) );
cboxTransparencyBand->setLayer( mRasterLayer );

sliderTransparency->setValue( ( 1.0 - renderer->opacity() ) * 255 );
//update the transparency percentage label
sliderTransparency_valueChanged( ( 1.0 - renderer->opacity() ) * 255 );

int myIndex = renderer->alphaBand();
if ( -1 != myIndex )
{
cboxTransparencyBand->setCurrentIndex( myIndex );
}
else
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findText( TRSTRING_NOT_SET ) );
}
cboxTransparencyBand->setBand( renderer->alphaBand() );
}

if ( mRasterLayer->dataProvider()->sourceHasNoDataValue( 1 ) )
Expand Down Expand Up @@ -393,7 +373,7 @@ void QgsRasterTransparencyWidget::apply()
QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
if ( rasterRenderer )
{
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentData().toInt() );
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentBand() );

//Walk through each row in table and test value. If not valid set to 0.0 and continue building transparency list
QgsRasterTransparency *rasterTransparency = new QgsRasterTransparency();
Expand Down
63 changes: 34 additions & 29 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="mOptsPage_General">
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down Expand Up @@ -241,8 +241,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>233</height>
<width>467</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -512,8 +512,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>616</width>
<height>546</height>
<width>603</width>
<height>544</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -1143,8 +1143,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>358</width>
<height>354</height>
<width>617</width>
<height>541</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -1367,7 +1367,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cboxTransparencyBand">
<widget class="QgsRasterBandComboBox" name="cboxTransparencyBand">
<property name="enabled">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -1559,8 +1559,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>457</width>
<height>169</height>
<width>576</width>
<height>213</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1623,8 +1623,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1729,8 +1729,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>98</width>
<height>47</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
Expand Down Expand Up @@ -1788,8 +1788,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>297</width>
<height>556</height>
<width>340</width>
<height>697</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down Expand Up @@ -2250,10 +2250,9 @@ p, li { white-space: pre-wrap; }
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
Expand All @@ -2262,14 +2261,14 @@ p, li { white-space: pre-wrap; }
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScaleRangeWidget</class>
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
<class>QgsRasterBandComboBox</class>
<extends>QComboBox</extends>
<header>raster/qgsrasterbandcombobox.h</header>
</customwidget>
<customwidget>
<class>QgsLayerTreeEmbeddedConfigWidget</class>
<extends>QWidget</extends>
<header>qgslayertreeembeddedconfigwidget.h</header>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
Expand All @@ -2284,9 +2283,15 @@ p, li { white-space: pre-wrap; }
<container>1</container>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
<class>QgsScaleRangeWidget</class>
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
</customwidget>
<customwidget>
<class>QgsLayerTreeEmbeddedConfigWidget</class>
<extends>QWidget</extends>
<header>qgslayertreeembeddedconfigwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
Expand Down
20 changes: 17 additions & 3 deletions src/ui/raster/qgsrastertransparencywidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
<rect>
<x>0</x>
<y>0</y>
<width>294</width>
<width>306</width>
<height>623</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="1" column="0">
Expand Down Expand Up @@ -210,7 +219,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cboxTransparencyBand">
<widget class="QgsRasterBandComboBox" name="cboxTransparencyBand">
<property name="enabled">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -387,6 +396,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsRasterBandComboBox</class>
<extends>QComboBox</extends>
<header>raster/qgsrasterbandcombobox.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
Expand Down

0 comments on commit f4b353c

Please sign in to comment.