Skip to content

Commit

Permalink
Updated the transparency widget to fix bug #16649 (#5358)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesShaeffer authored and nirvn committed Oct 13, 2017
1 parent 873b4b0 commit b740a89
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/gui/raster/qgsrastertransparencywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ QgsRasterTransparencyWidget::QgsRasterTransparencyWidget( QgsRasterLayer *layer,

connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPanelWidget::widgetChanged );
connect( cboxTransparencyBand, &QgsRasterBandComboBox::bandChanged, this, &QgsPanelWidget::widgetChanged );
connect( mSrcNoDataValueCheckBox, &QCheckBox::stateChanged, this, &QgsPanelWidget::widgetChanged );
connect( leNoDataValue, &QLineEdit::textEdited, this, &QgsPanelWidget::widgetChanged );

mPixelSelectorTool = nullptr;
if ( mMapCanvas )
Expand Down Expand Up @@ -103,6 +105,17 @@ void QgsRasterTransparencyWidget::syncToLayer()
mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
lblSrcNoDataValue->setEnabled( enableSrcNoData );

QgsRasterRangeList noDataRangeList = mRasterLayer->dataProvider()->userNoDataValues( 1 );
QgsDebugMsg( QString( "noDataRangeList.size = %1" ).arg( noDataRangeList.size() ) );
if ( !noDataRangeList.isEmpty() )
{
leNoDataValue->insert( QgsRasterBlock::printValue( noDataRangeList.value( 0 ).min() ) );
}
else
{
leNoDataValue->insert( QLatin1String( "" ) );

This comment has been minimized.

Copy link
@Gustry

Gustry Oct 13, 2017

Contributor

without double quotes?

}

populateTransparencyTable( mRasterLayer->renderer() );
}

Expand Down Expand Up @@ -366,6 +379,25 @@ bool QgsRasterTransparencyWidget::rasterIsMultiBandColor()

void QgsRasterTransparencyWidget::apply()
{
//set NoDataValue
QgsRasterRangeList myNoDataRangeList;

This comment has been minimized.

Copy link
@DelazJ

DelazJ Oct 13, 2017

Contributor

@nirvn I might mix things but aren't we supposed to avoid these my... naming?

if ( "" != leNoDataValue->text() )

This comment has been minimized.

Copy link
@Gustry

Gustry Oct 13, 2017

Contributor

! leNoDataValue->text().isEmpty() ?

I'm just trying to apply what I learn from @nyalldawson ;-)

{
bool myDoubleOk = false;
double myNoDataValue = leNoDataValue->text().toDouble( &myDoubleOk );
if ( myDoubleOk )
{
QgsRasterRange myNoDataRange( myNoDataValue, myNoDataValue );
myNoDataRangeList << myNoDataRange;
}
}
for ( int bandNo = 1; bandNo <= mRasterLayer->dataProvider()->bandCount(); bandNo++ )
{
mRasterLayer->dataProvider()->setUserNoDataValue( bandNo, myNoDataRangeList );
mRasterLayer->dataProvider()->setUseSourceNoDataValue( bandNo, mSrcNoDataValueCheckBox->isChecked() );
}

//transparency settings
QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
if ( rasterRenderer )
{
Expand Down

0 comments on commit b740a89

Please sign in to comment.