Skip to content

Commit 3562bdb

Browse files
committed
raster saveas: load nodata from layer transparency
1 parent 72978cf commit 3562bdb

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

src/app/qgsrasterlayerproperties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,17 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
256256
cboxTransparencyBand->addItem( bandName, i );
257257
}
258258

259+
// Alpha band is set in sync()
260+
#if 0
259261
if ( renderer )
260262
{
261-
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
263+
QgsDebugMsg( QString( "alphaBand = %1" ).arg( renderer->alphaBand() ) );
264+
if ( renderer->alphaBand() > 0 )
265+
{
266+
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
267+
}
262268
}
269+
#endif
263270
}
264271

265272
// create histogram widget

src/core/raster/qgsrasternuller.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,23 @@ void * QgsRasterNuller::readBlock( int bandNo, QgsRectangle const & extent, int
5656

5757
void * rasterData = mInput->block( bandNo, extent, width, height );
5858

59-
QgsRasterInterface::DataType dataType = mInput->dataType( bandNo );
60-
int pixelSize = mInput->typeSize( dataType ) / 8;
59+
QgsRasterInterface::DataType dataType = mInput->dataType( bandNo );
6160

62-
double noDataValue = mInput->noDataValue ( bandNo );
61+
double noDataValue = mInput->noDataValue( bandNo );
6362

64-
for ( int i = 0; i < height; ++i )
63+
for ( int i = 0; i < height; i++ )
6564
{
66-
for ( int j = 0; j < width; ++j )
65+
for ( int j = 0; j < width; j++ )
6766
{
68-
int index = pixelSize * ( i * width + j );
67+
int index = i * width + j;
6968

7069
double value = readValue( rasterData, dataType, index );
71-
70+
7271
foreach ( NoData noData, mNoData )
7372
{
74-
if ( ( value >= noData.min && value <= noData.max ) ||
75-
doubleNear( value, noData.min ) ||
76-
doubleNear( value, noData.max ) )
73+
if (( value >= noData.min && value <= noData.max ) ||
74+
doubleNear( value, noData.min ) ||
75+
doubleNear( value, noData.max ) )
7776
{
7877
writeValue( rasterData, dataType, index, noDataValue );
7978
}

src/gui/qgsrasterlayersaveasdialog.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
589589
lineEdit->setValidator( new QDoubleValidator( 0 ) );
590590
if ( !qIsNaN( value ) )
591591
{
592-
valueString = QString::number( value, 'f' );
592+
valueString = QgsRasterInterface::printValue( value );
593593
}
594594
break;
595595
default:
@@ -603,6 +603,8 @@ void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
603603
lineEdit->setText( valueString );
604604
mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );
605605

606+
adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );
607+
606608
connect( lineEdit, SIGNAL( textEdited( const QString & ) ), this, SLOT( noDataCellTextEdited( const QString & ) ) );
607609
}
608610
mNoDataTableWidget->resizeColumnsToContents();
@@ -737,6 +739,17 @@ double QgsRasterLayerSaveAsDialog::noDataCellValue( int row, int column ) const
737739
return lineEdit->text().toDouble();
738740
}
739741

742+
void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
743+
{
744+
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
745+
if ( !lineEdit ) return;
746+
747+
int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
748+
width = qMax( width, mNoDataTableWidget->columnWidth( column ) );
749+
750+
lineEdit->setFixedWidth( width );
751+
}
752+
740753
QList<QgsRasterNuller::NoData> QgsRasterLayerSaveAsDialog::noData() const
741754
{
742755
QList<QgsRasterNuller::NoData> noDataList;

src/gui/qgsrasterlayersaveasdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
134134
void addNoDataRow( double min, double max );
135135
void setNoDataToEdited( int row );
136136
double noDataCellValue( int row, int column ) const;
137+
void adjustNoDataCellWidth( int row, int column );
137138
};
138139

139140

src/ui/qgsrasterlayersaveasdialogbase.ui

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
<property name="geometry">
3030
<rect>
3131
<x>0</x>
32-
<y>-293</y>
33-
<width>539</width>
34-
<height>831</height>
32+
<y>-263</y>
33+
<width>549</width>
34+
<height>806</height>
3535
</rect>
3636
</property>
3737
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -527,6 +527,12 @@
527527
<property name="enabled">
528528
<bool>true</bool>
529529
</property>
530+
<property name="minimumSize">
531+
<size>
532+
<width>0</width>
533+
<height>150</height>
534+
</size>
535+
</property>
530536
<property name="toolTip">
531537
<string>Additional no data values. The specified values will be set to no data in output raster.</string>
532538
</property>
@@ -568,9 +574,6 @@
568574
</item>
569575
<item row="2" column="0">
570576
<widget class="QToolButton" name="mLoadTransparentNoDataToolButton">
571-
<property name="enabled">
572-
<bool>false</bool>
573-
</property>
574577
<property name="toolTip">
575578
<string>Load user defined fully transparent (100%) values </string>
576579
</property>
@@ -643,7 +646,7 @@
643646
<string>No pyramids</string>
644647
</property>
645648
<attribute name="buttonGroup">
646-
<string notr="true">mPyramidsButtonGroup</string>
649+
<string>mPyramidsButtonGroup</string>
647650
</attribute>
648651
</widget>
649652
</item>
@@ -653,7 +656,7 @@
653656
<string>Build pyramids</string>
654657
</property>
655658
<attribute name="buttonGroup">
656-
<string notr="true">mPyramidsButtonGroup</string>
659+
<string>mPyramidsButtonGroup</string>
657660
</attribute>
658661
</widget>
659662
</item>
@@ -663,7 +666,7 @@
663666
<string>Use existing</string>
664667
</property>
665668
<attribute name="buttonGroup">
666-
<string notr="true">mPyramidsButtonGroup</string>
669+
<string>mPyramidsButtonGroup</string>
667670
</attribute>
668671
</widget>
669672
</item>

0 commit comments

Comments
 (0)