Skip to content

File tree

4 files changed

+135
-47
lines changed

4 files changed

+135
-47
lines changed
 

‎src/gui/qgsrasterlayerproperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa
203203
cboRed->insertItem(myQString);
204204
cboGreen->insertItem(myQString);
205205
cboBlue->insertItem(myQString);
206+
cboTransparent->insertItem(myQString);
206207
}
207208
cboRed->insertItem(tr("Not Set"));
208209
cboGreen->insertItem(tr("Not Set"));
209210
cboBlue->insertItem(tr("Not Set"));
211+
cboTransparent->insertItem(tr("Not Set"));
210212
if (cboGray->count() != 1)
211213
cboGray->insertItem(tr("Not Set"));
212214
}
@@ -291,6 +293,7 @@ void QgsRasterLayerProperties::apply()
291293
rasterLayer->setGreenBandName(cboGreen->currentText());
292294
rasterLayer->setBlueBandName(cboBlue->currentText());
293295
rasterLayer->setGrayBandName(cboGray->currentText());
296+
rasterLayer->setTransparentBandName(cboTransparent->currentText());
294297
//set the appropriate color ramping type
295298
if (cboColorMap->currentText() == tr("Pseudocolor"))
296299
{
@@ -682,6 +685,7 @@ void QgsRasterLayerProperties::sync()
682685
cboGreen->setCurrentText(rasterLayer->getGreenBandName());
683686
cboBlue->setCurrentText(rasterLayer->getBlueBandName());
684687
cboGray->setCurrentText(rasterLayer->getGrayBandName());
688+
cboTransparent->setCurrentText(rasterLayer->getTransparentBandName());
685689

686690

687691
} // QgsRasterLayerProperties::sync()

‎src/raster/qgsrasterlayer.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ QgsRasterLayer::readFile( QString const & fileName )
653653
redBandNameQString = "Red"; // sensible default
654654
greenBandNameQString = "Green"; // sensible default
655655
blueBandNameQString = "Blue";// sensible default
656+
transparentBandNameQString = tr("Not Set"); // sensible default
656657
grayBandNameQString = tr("Not Set"); //sensible default
657658
drawingStyle = PALETTED_MULTI_BAND_COLOR; //sensible default
658659
}
@@ -670,6 +671,11 @@ QgsRasterLayer::readFile( QString const & fileName )
670671
{
671672
blueBandNameQString = tr("Not Set"); // sensible default
672673
}
674+
if (gdalDataset->GetRasterCount() > 3)
675+
transparentBandNameQString = getRasterBandName(4);
676+
else
677+
transparentBandNameQString = tr("Not Set");
678+
673679
grayBandNameQString = tr("Not Set"); //sensible default
674680
drawingStyle = MULTI_BAND_COLOR; //sensible default
675681
}
@@ -679,6 +685,7 @@ QgsRasterLayer::readFile( QString const & fileName )
679685
redBandNameQString = tr("Not Set"); //sensible default
680686
greenBandNameQString = tr("Not Set"); //sensible default
681687
blueBandNameQString = tr("Not Set"); //sensible default
688+
transparentBandNameQString = tr("Not Set"); //sensible default
682689
drawingStyle = SINGLE_BAND_GRAY; //sensible default
683690
grayBandNameQString = getRasterBandName(1); // usually gdal will return gray or undefined
684691
}
@@ -2333,6 +2340,20 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
23332340
void *myGdalGreenData = readData ( myGdalGreenBand, theRasterViewPort );
23342341
void *myGdalBlueData = readData ( myGdalBlueBand, theRasterViewPort );
23352342

2343+
bool haveTransparencyBand(false);
2344+
GDALRasterBand *myGdalTransparentBand;
2345+
GDALDataType myTransparentType;
2346+
void *myGdalTransparentData;
2347+
2348+
if (transparentBandNameQString != tr("Not Set"))
2349+
{
2350+
haveTransparencyBand = true;
2351+
int myTransparentBandNoInt = getRasterBandNumber(transparentBandNameQString);
2352+
myGdalTransparentBand = gdalDataset->GetRasterBand(myTransparentBandNoInt);
2353+
myTransparentType = myGdalTransparentBand->GetRasterDataType();
2354+
myGdalTransparentData = readData ( myGdalTransparentBand, theRasterViewPort );
2355+
}
2356+
23362357
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
23372358
//myQImage.fill(0);
23382359
myQImage.setAlphaBuffer(true);
@@ -2347,9 +2368,16 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
23472368
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
23482369
double myBlueValueDouble = readValue ( myGdalBlueData, myBlueType,
23492370
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
2371+
if (haveTransparencyBand)
2372+
{
2373+
double myTransparentValueDouble = readValue ( myGdalTransparentData, myTransparentType,
2374+
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
2375+
if (myTransparentValueDouble == 0.0)
2376+
continue;
2377+
}
23502378

23512379
// TODO: check all channels ?
2352-
if ( myRedValueDouble == noDataValueDouble || myRedValueDouble != myRedValueDouble )
2380+
if ( myRedValueDouble == noDataValueDouble || myRedValueDouble != myRedValueDouble)
23532381
{
23542382
#ifdef QGISDEBUG
23552383
QgsLogger::debug("myRedValueDouble", myRedValueDouble, __FILE__, __FUNCTION__, __LINE__, 1);
@@ -2439,6 +2467,8 @@ QgsDebugMsg("QgsRasterLayer::drawSingleBandGray: painting image to canvas from s
24392467
CPLFree(myGdalRedData);
24402468
CPLFree(myGdalGreenData);
24412469
CPLFree(myGdalBlueData);
2470+
if (haveTransparencyBand)
2471+
CPLFree(myGdalTransparentData);
24422472
}
24432473

24442474

@@ -3007,6 +3037,38 @@ void QgsRasterLayer::setBlueBandName(QString const & theBandNameQString)
30073037
return;
30083038
}
30093039

3040+
//mutator for transparent band name
3041+
void QgsRasterLayer::setTransparentBandName(QString const & theBandNameQString)
3042+
{
3043+
//check if the band is unset
3044+
if (theBandNameQString == tr("Not Set"))
3045+
{
3046+
transparentBandNameQString = theBandNameQString;
3047+
return;
3048+
}
3049+
//check if the image is paletted
3050+
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
3051+
{
3052+
transparentBandNameQString = theBandNameQString;
3053+
return;
3054+
}
3055+
//check that a valid band name was passed
3056+
3057+
for (int myIteratorInt = 0; myIteratorInt < rasterStatsVector.size(); ++myIteratorInt)
3058+
{
3059+
//find out the name of this band
3060+
QgsRasterBandStats myRasterBandStats = rasterStatsVector[myIteratorInt];
3061+
if (myRasterBandStats.bandName == theBandNameQString)
3062+
{
3063+
transparentBandNameQString = theBandNameQString;
3064+
return;
3065+
}
3066+
}
3067+
3068+
//if no matches were found default to not set
3069+
transparentBandNameQString = tr("Not Set");
3070+
return;
3071+
}
30103072

30113073

30123074
//mutator for gray band name

‎src/raster/qgsrasterlayer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ class QgsRasterLayer : public QgsMapLayer
415415
/** \brief Mutator for blue band name mapping. */
416416
void setBlueBandName(QString const & theBandNameQString);
417417
//
418+
// Accessor and mutator for transparent band name
419+
//
420+
/** \brief Accessor for transparent band name mapping. */
421+
QString getTransparentBandName()
422+
{
423+
return transparentBandNameQString;
424+
};
425+
/** \brief Mutator for transparent band name mapping. */
426+
void setTransparentBandName(QString const & theBandNameQString);
427+
//
418428
// Accessor and mutator for gray band name
419429
//
420430
/** \brief Accessor for gray band name mapping. */
@@ -1007,6 +1017,8 @@ public slots:
10071017
QString greenBandNameQString;
10081018
/** \brief The band to be associated with the color blue - usually 3. */
10091019
QString blueBandNameQString;
1020+
/** \brief The band to be associated with transparency. */
1021+
QString transparentBandNameQString;
10101022
/** \brief The band to be associated with the grayscale only ouput - usually 1. */
10111023
QString grayBandNameQString;
10121024
/** \brief Minimum red value - used in scaling procedure. */

‎src/ui/qgsrasterlayerpropertiesbase.ui

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,27 @@
191191
<property name="spacing" >
192192
<number>6</number>
193193
</property>
194-
<item row="4" column="1" >
195-
<spacer>
196-
<property name="orientation" >
197-
<enum>Qt::Vertical</enum>
194+
<item row="3" column="1" >
195+
<widget class="QComboBox" name="cboBlue" />
196+
</item>
197+
<item row="1" column="1" >
198+
<widget class="QComboBox" name="cboRed" />
199+
</item>
200+
<item row="0" column="0" >
201+
<widget class="QLabel" name="textLabel2_4" >
202+
<property name="text" >
203+
<string>Color</string>
198204
</property>
199-
<property name="sizeHint" >
200-
<size>
201-
<width>20</width>
202-
<height>40</height>
203-
</size>
205+
</widget>
206+
</item>
207+
<item row="0" column="1" >
208+
<widget class="QLabel" name="textLabel2_5" >
209+
<property name="text" >
210+
<string>Band</string>
204211
</property>
205-
</spacer>
212+
</widget>
206213
</item>
207-
<item row="4" column="0" >
214+
<item row="5" column="1" >
208215
<spacer>
209216
<property name="orientation" >
210217
<enum>Qt::Vertical</enum>
@@ -217,18 +224,8 @@
217224
</property>
218225
</spacer>
219226
</item>
220-
<item row="3" column="1" >
221-
<widget class="QComboBox" name="cboBlue" />
222-
</item>
223-
<item row="3" column="0" >
224-
<widget class="QLabel" name="textLabel2_3" >
225-
<property name="text" >
226-
<string>&lt;b>&lt;font color="#0000ff">Blue&lt;/font>&lt;/b></string>
227-
</property>
228-
<property name="buddy" >
229-
<cstring>cboBlue</cstring>
230-
</property>
231-
</widget>
227+
<item row="2" column="1" >
228+
<widget class="QComboBox" name="cboGreen" />
232229
</item>
233230
<item row="2" column="0" >
234231
<widget class="QLabel" name="textLabel2_2" >
@@ -240,12 +237,6 @@
240237
</property>
241238
</widget>
242239
</item>
243-
<item row="2" column="1" >
244-
<widget class="QComboBox" name="cboGreen" />
245-
</item>
246-
<item row="1" column="1" >
247-
<widget class="QComboBox" name="cboRed" />
248-
</item>
249240
<item row="1" column="0" >
250241
<widget class="QLabel" name="textLabel2" >
251242
<property name="text" >
@@ -256,20 +247,39 @@
256247
</property>
257248
</widget>
258249
</item>
259-
<item row="0" column="1" >
260-
<widget class="QLabel" name="textLabel2_5" >
250+
<item row="5" column="0" >
251+
<spacer>
252+
<property name="orientation" >
253+
<enum>Qt::Vertical</enum>
254+
</property>
255+
<property name="sizeHint" >
256+
<size>
257+
<width>20</width>
258+
<height>40</height>
259+
</size>
260+
</property>
261+
</spacer>
262+
</item>
263+
<item row="3" column="0" >
264+
<widget class="QLabel" name="textLabel2_3" >
261265
<property name="text" >
262-
<string>Band</string>
266+
<string>&lt;b>&lt;font color="#0000ff">Blue&lt;/font>&lt;/b></string>
267+
</property>
268+
<property name="buddy" >
269+
<cstring>cboBlue</cstring>
263270
</property>
264271
</widget>
265272
</item>
266-
<item row="0" column="0" >
267-
<widget class="QLabel" name="textLabel2_4" >
273+
<item row="4" column="0" >
274+
<widget class="QLabel" name="label" >
268275
<property name="text" >
269-
<string>Color</string>
276+
<string>Transparent</string>
270277
</property>
271278
</widget>
272279
</item>
280+
<item row="4" column="1" >
281+
<widget class="QComboBox" name="cboTransparent" />
282+
</item>
273283
</layout>
274284
</widget>
275285
</item>
@@ -1068,9 +1078,14 @@
10681078
<layoutdefault spacing="6" margin="11" />
10691079
<customwidgets>
10701080
<customwidget>
1071-
<class>Q3TextBrowser</class>
1072-
<extends>Q3TextEdit</extends>
1073-
<header>Qt3Support/Q3TextBrowser</header>
1081+
<class>Q3TextEdit</class>
1082+
<extends>Q3Frame</extends>
1083+
<header>q3textedit.h</header>
1084+
</customwidget>
1085+
<customwidget>
1086+
<class>Q3ListBox</class>
1087+
<extends>Q3Frame</extends>
1088+
<header>q3listbox.h</header>
10741089
</customwidget>
10751090
<customwidget>
10761091
<class>Q3GroupBox</class>
@@ -1079,14 +1094,9 @@
10791094
<container>1</container>
10801095
</customwidget>
10811096
<customwidget>
1082-
<class>Q3ListBox</class>
1083-
<extends>Q3Frame</extends>
1084-
<header>q3listbox.h</header>
1085-
</customwidget>
1086-
<customwidget>
1087-
<class>Q3TextEdit</class>
1088-
<extends>Q3Frame</extends>
1089-
<header>q3textedit.h</header>
1097+
<class>Q3TextBrowser</class>
1098+
<extends>Q3TextEdit</extends>
1099+
<header>Qt3Support/Q3TextBrowser</header>
10901100
</customwidget>
10911101
</customwidgets>
10921102
<tabstops>

0 commit comments

Comments
 (0)
Please sign in to comment.