Skip to content
Permalink
Browse files

show band names instead of numbers in transparency tab

don't add empty row when loading default transparency values
  • Loading branch information
alexbruy committed Jul 15, 2012
1 parent f87777e commit f84d9658e11c4fa84ef794ac7404156397ff045b
Showing with 79 additions and 41 deletions.
  1. +37 −17 src/app/qgsrasterlayerproperties.cpp
  2. +42 −24 src/ui/qgsrasterlayerpropertiesbase.ui
@@ -445,41 +445,58 @@ void QgsRasterLayerProperties::populateTransparencyTable( QgsRasterRenderer* ren
tableTransparency->setColumnCount( 0 );
tableTransparency->setRowCount( 0 );

QList<int> bandList = renderer->usesBands();
tableTransparency->setColumnCount( bandList.size() + 1 );
for ( int i = 0; i < bandList.size(); ++i )
int nBands = renderer->usesBands().size();
tableTransparency->setColumnCount( nBands + 1 );
if ( nBands == 3 )
{
tableTransparency->setHorizontalHeaderItem( i, new QTableWidgetItem( QString::number( bandList.at( i ) ) ) );
tableTransparency->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Red" ) ) );
tableTransparency->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Green" ) ) );
tableTransparency->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Blue" ) ) );
tableTransparency->setHorizontalHeaderItem( 3, new QTableWidgetItem( tr( "Percent Transparent" ) ) );
}
else //1 band
{
if ( QgsRasterLayer::PalettedColor != mRasterLayer->drawingStyle() &&
QgsRasterLayer::PalettedSingleBandGray != mRasterLayer->drawingStyle() &&
QgsRasterLayer::PalettedSingleBandPseudoColor != mRasterLayer->drawingStyle() &&
QgsRasterLayer::PalettedMultiBandColor != mRasterLayer->drawingStyle() )
{
tableTransparency->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Gray" ) ) );
}
else
{
tableTransparency->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Indexed Value" ) ) );
}
tableTransparency->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Percent Transparent" ) ) );
}
tableTransparency->setHorizontalHeaderItem( bandList.size(), new QTableWidgetItem( tr( "Percent Transparent" ) ) );

const QgsRasterTransparency* rasterTransparency = renderer->rasterTransparency();
if ( !rasterTransparency )
{
return;
}

if ( bandList.count() == 1 )
if ( nBands == 1 )
{
QList<QgsRasterTransparency::TransparentSingleValuePixel> pixelList = rasterTransparency->transparentSingleValuePixelList();
for ( int i = 0; i < pixelList.size(); ++i )
{
tableTransparency->insertRow( i );
QTableWidgetItem* grayItem = new QTableWidgetItem( QString::number( pixelList[i].pixelValue ) );
QTableWidgetItem* grayItem = new QTableWidgetItem( QString::number( pixelList[i].pixelValue, 'f' ) );
QTableWidgetItem* percentItem = new QTableWidgetItem( QString::number( pixelList[i].percentTransparent ) );
tableTransparency->setItem( i, 0, grayItem );
tableTransparency->setItem( i, 1, percentItem );
}
}
else if ( bandList.count() == 3 )
else if ( nBands == 3 )
{
QList<QgsRasterTransparency::TransparentThreeValuePixel> pixelList = rasterTransparency->transparentThreeValuePixelList();
for ( int i = 0; i < pixelList.size(); ++i )
{
tableTransparency->insertRow( i );
QTableWidgetItem* redItem = new QTableWidgetItem( QString::number( pixelList[i].red ) );
QTableWidgetItem* greenItem = new QTableWidgetItem( QString::number( pixelList[i].green ) );
QTableWidgetItem* blueItem = new QTableWidgetItem( QString::number( pixelList[i].blue ) );
QTableWidgetItem* redItem = new QTableWidgetItem( QString::number( pixelList[i].red, 'f' ) );
QTableWidgetItem* greenItem = new QTableWidgetItem( QString::number( pixelList[i].green, 'f' ) );
QTableWidgetItem* blueItem = new QTableWidgetItem( QString::number( pixelList[i].blue, 'f' ) );
QTableWidgetItem* transparentItem = new QTableWidgetItem( QString::number( pixelList[i].percentTransparent ) );

tableTransparency->setItem( i, 0, redItem );
@@ -1117,10 +1134,12 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
int nBands = r->usesBands().size();
delete r;

tableTransparency->clear();
tableTransparency->setRowCount( 0 );
tableTransparency->setColumnCount( nBands + 1 );

if ( nBands == 3 )
{
tableTransparency->clear();
tableTransparency->setColumnCount( 4 );
tableTransparency->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Red" ) ) );
tableTransparency->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Green" ) ) );
tableTransparency->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Blue" ) ) );
@@ -1131,13 +1150,11 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
tableTransparency->setItem( 0, 0, new QTableWidgetItem( QString::number( mRasterLayer->noDataValue(), 'f' ) ) );
tableTransparency->setItem( 0, 1, new QTableWidgetItem( QString::number( mRasterLayer->noDataValue(), 'f' ) ) );
tableTransparency->setItem( 0, 2, new QTableWidgetItem( QString::number( mRasterLayer->noDataValue(), 'f' ) ) );
tableTransparency->setItem( 0, 3, new QTableWidgetItem( "100.0" ) );
tableTransparency->setItem( 0, 3, new QTableWidgetItem( "100" ) );
}
}
else //1 band
{
tableTransparency->clear();
tableTransparency->setColumnCount( 2 );
if ( QgsRasterLayer::PalettedColor != mRasterLayer->drawingStyle() &&
QgsRasterLayer::PalettedSingleBandGray != mRasterLayer->drawingStyle() &&
QgsRasterLayer::PalettedSingleBandPseudoColor != mRasterLayer->drawingStyle() &&
@@ -1155,9 +1172,12 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
{
tableTransparency->insertRow( tableTransparency->rowCount() );
tableTransparency->setItem( 0, 0, new QTableWidgetItem( QString::number( mRasterLayer->noDataValue(), 'f' ) ) );
tableTransparency->setItem( 0, 1, new QTableWidgetItem( "100.0" ) );
tableTransparency->setItem( 0, 1, new QTableWidgetItem( "100" ) );
}
}

tableTransparency->resizeColumnsToContents();
tableTransparency->resizeRowsToContents();
}

void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()

0 comments on commit f84d965

Please sign in to comment.
You can’t perform that action at this time.