Skip to content

Commit c95c7f1

Browse files
author
ersts
committedJul 21, 2008
-Moved invert color controls back onto main tab
-Changed default load behavior so two band images show up on initial load, closes ticket #1157 -Moved to using generic band names (i.e., Band 1, Band 2) rather than names stored in the raster file itself -Updated set default contrast enhancement behavior so that it not applied until the ok or apply button is clicked -Added a default band combination setting that will be persistant between QGIS sessions. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8819 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

6 files changed

+248
-262
lines changed

6 files changed

+248
-262
lines changed
 

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,13 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa
284284
QPixmap myPyramidPixmap(myThemePath + "/mIconPyramid.png");
285285
QPixmap myNoPyramidPixmap(myThemePath + "/mIconNoPyramid.png");
286286

287-
pbnAddValuesManually->setIcon(QIcon(QPixmap(myThemePath + "/mActionNewAttribute.png")));
288-
pbnAddValuesFromDisplay->setIcon(QIcon(QPixmap(myThemePath + "/mActionContextHelp.png")));
289-
pbnRemoveSelectedRow->setIcon(QIcon(QPixmap(myThemePath + "/mActionDeleteAttribute.png")));
290-
pbnDefaultValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionCopySelected.png")));
291-
pbnImportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
292-
pbnExportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
293-
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
287+
pbnAddValuesManually->setIcon(QIcon(myThemePath + "/mActionNewAttribute.png"));
288+
pbnAddValuesFromDisplay->setIcon(QIcon(myThemePath + "/mActionContextHelp.png"));
289+
pbnRemoveSelectedRow->setIcon(QIcon(myThemePath + "/mActionDeleteAttribute.png"));
290+
pbnDefaultValues->setIcon(QIcon(myThemePath + "/mActionCopySelected.png"));
291+
pbnImportTransparentPixelValues->setIcon(QIcon(myThemePath + "/mActionFileOpen.png"));
292+
pbnExportTransparentPixelValues->setIcon(QIcon(myThemePath + "/mActionFileSave.png"));
293+
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(myThemePath + "/mActionFileSave.png"));
294294

295295
// Only do pyramids if dealing directly with GDAL.
296296
if (mRasterLayerIsGdal)
@@ -729,20 +729,25 @@ void QgsRasterLayerProperties::sync()
729729

730730
//Display the current default contrast enhancement algorithm
731731
QSettings myQSettings;
732-
QString myDefaultAlgorithm = myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString();
733-
if(myDefaultAlgorithm == "NO_STRETCH")
732+
mDefaultRedBand = myQSettings.value("/Raster/defaultRedBand", 1).toInt();
733+
mDefaultGreenBand = myQSettings.value("/Raster/defaultGreenBand", 2).toInt();
734+
mDefaultBlueBand = myQSettings.value("/Raster/defaultBlueBand", 3).toInt();
735+
labelDefaultBandCombination->setText(QString(tr("Default") + " R:%1 G:%2 B:%3") .arg(mDefaultRedBand) .arg(mDefaultGreenBand) .arg(mDefaultBlueBand));
736+
737+
mDefaultContrastEnhancementAlgorithm = myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString();
738+
if(mDefaultContrastEnhancementAlgorithm == "NO_STRETCH")
734739
{
735740
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Stretch"));
736741
}
737-
if(myDefaultAlgorithm == "STRETCH_TO_MINMAX")
742+
if(mDefaultContrastEnhancementAlgorithm == "STRETCH_TO_MINMAX")
738743
{
739744
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch To MinMax"));
740745
}
741-
else if(myDefaultAlgorithm == "STRETCH_AND_CLIP_TO_MINMAX")
746+
else if(mDefaultContrastEnhancementAlgorithm == "STRETCH_AND_CLIP_TO_MINMAX")
742747
{
743748
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch And Clip To MinMax"));
744749
}
745-
else if(myDefaultAlgorithm == "CLIP_TO_MINMAX")
750+
else if(mDefaultContrastEnhancementAlgorithm == "CLIP_TO_MINMAX")
746751
{
747752
labelDefaultContrastEnhancementAlgorithm->setText(tr("Clip To MinMax"));
748753
}
@@ -1196,6 +1201,13 @@ void QgsRasterLayerProperties::apply()
11961201
}
11971202
}
11981203

1204+
QSettings myQSettings;
1205+
myQSettings.setValue("/Raster/defaultRedBand", mDefaultRedBand);
1206+
myQSettings.setValue("/Raster/defaultGreenBand", mDefaultGreenBand);
1207+
myQSettings.setValue("/Raster/defaultBlueBand", mDefaultBlueBand);
1208+
1209+
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", mDefaultContrastEnhancementAlgorithm);
1210+
11991211
#ifdef QGISDEBUG
12001212
QgsDebugMsg("QgsRasterLayerProperties::apply processing transparency tab");
12011213
#endif
@@ -1857,29 +1869,6 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
18571869
std::cout << "QgsRasterLayerProperties::on_pbnHistRefresh_clicked" << std::endl;
18581870
#endif
18591871
int myBandCountInt = mRasterLayer->getBandCount();
1860-
//
1861-
// Find out how many bands are selected and short circuit out clearing the image
1862-
// if needed
1863-
int mySelectionCount=0;
1864-
for (int myIteratorInt = 1;
1865-
myIteratorInt <= myBandCountInt;
1866-
++myIteratorInt)
1867-
{
1868-
QgsRasterBandStats myRasterBandStats = mRasterLayer->getRasterBandStats(myIteratorInt);
1869-
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt-1 );
1870-
if ( myItem->isSelected() )
1871-
{
1872-
mySelectionCount++;
1873-
}
1874-
}
1875-
if (mySelectionCount==0)
1876-
{
1877-
int myImageWidth = pixHistogram->width();
1878-
int myImageHeight = pixHistogram->height();
1879-
QPixmap myPixmap(myImageWidth,myImageHeight);
1880-
myPixmap.fill(Qt::white);
1881-
pixHistogram->setPixmap(myPixmap);
1882-
}
18831872

18841873
// Explanation:
18851874
// We use the gdal histogram creation routine is called for each selected
@@ -2766,32 +2755,36 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
27662755
}
27672756
}
27682757

2758+
void QgsRasterLayerProperties::on_pbtnMakeBandCombinationDefault_clicked()
2759+
{
2760+
mDefaultRedBand = cboRed->currentIndex() + 1;
2761+
mDefaultGreenBand = cboGreen->currentIndex() + 1;
2762+
mDefaultBlueBand = cboBlue->currentIndex() + 1;
2763+
labelDefaultBandCombination->setText(QString(tr("Default") + " R:%1 G:%2 B:%3") .arg(mDefaultRedBand) .arg(mDefaultGreenBand) .arg(mDefaultBlueBand));
2764+
}
2765+
27692766
void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked()
27702767
{
2771-
//Like some of the other functionality in the raster properties GUI this deviated a little from the
2772-
//best practice of GUI design as this pressing cancel will not undo setting the default
2773-
//contrast enhancement algorithm
27742768
if(cboxContrastEnhancementAlgorithm->currentText() != tr("User Defined"))
27752769
{
2776-
QSettings myQSettings;
27772770
if(cboxContrastEnhancementAlgorithm->currentText() == tr("No Stretch"))
27782771
{
2779-
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH");
2772+
mDefaultContrastEnhancementAlgorithm = "NO_STRETCH";
27802773
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
27812774
}
27822775
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch To MinMax"))
27832776
{
2784-
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_TO_MINMAX");
2777+
mDefaultContrastEnhancementAlgorithm = "STRETCH_TO_MINMAX";
27852778
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
27862779
}
27872780
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch And Clip To MinMax"))
27882781
{
2789-
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_AND_CLIP_TO_MINMAX");
2782+
mDefaultContrastEnhancementAlgorithm = "STRETCH_AND_CLIP_TO_MINMAX";
27902783
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
27912784
}
27922785
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Clip To MinMax"))
27932786
{
2794-
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "CLIP_TO_MINMAX");
2787+
mDefaultContrastEnhancementAlgorithm = "CLIP_TO_MINMAX";
27952788
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
27962789
}
27972790
else

‎src/app/qgsrasterlayerproperties.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
108108
void handleColormapTreeWidgetDoubleClick(QTreeWidgetItem* item, int column);
109109
/**This slot loads the minimum and maximum values from the raster band and updates the gui*/
110110
void on_pbtnLoadMinMax_clicked();
111-
/**This slot save the current contrast enhancement algorithm as the default algorithm */
111+
/**This slot sets the default band combination varaible to current band combination */
112+
void on_pbtnMakeBandCombinationDefault_clicked();
113+
/**This slot sets the default contrast enhancement varaible to current contrast enhancement algorithm */
112114
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();
113-
115+
114116
/** Load the default style when appriate button is pressed. */
115117
void on_pbnLoadDefaultStyle_clicked();
116118
/** Save the default style when appriate button is pressed. */
@@ -133,6 +135,14 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
133135
/** Id for context help */
134136
static const int context_id = 394441851;
135137

138+
/** \brief Default contrast enhancement algorithm */
139+
QString mDefaultContrastEnhancementAlgorithm;
140+
141+
/** \brief Default band combination */
142+
int mDefaultRedBand;
143+
int mDefaultGreenBand;
144+
int mDefaultBlueBand;
145+
136146
/** \brief Internal flag used to short circuit signal loop between min max field and stdDev spin box */
137147
bool ignoreSpinBoxEvent;
138148

‎src/core/raster/qgsrasterbandstats.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
class CORE_EXPORT QgsRasterBandStats
3737
{
3838
public:
39-
//This constructor was added because values were being used un initalized
40-
//TODO: This should not be in the header file.
4139
QgsRasterBandStats() {
4240
bandName = "";
4341
statsGatheredFlag = false;

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 64 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,9 @@ bool QgsRasterLayer::readFile( QString const & fileName )
516516
for (int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++)
517517
{
518518
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,i);
519-
QString myColorQString = GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(myGdalBand));
520519
QgsRasterBandStats myRasterBandStats;
521520
//myRasterBandStats.bandName = myColorQString ;
522-
myRasterBandStats.bandName=QString::number(i) + " : " + myColorQString;
521+
myRasterBandStats.bandName="Band " + QString::number(i);
523522
myRasterBandStats.bandNo = i;
524523
myRasterBandStats.statsGatheredFlag = false;
525524
myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
@@ -567,16 +566,16 @@ bool QgsRasterLayer::readFile( QString const & fileName )
567566
else if (rasterLayerType == MULTIBAND)
568567
{
569568
//we know we have at least 2 layers...
570-
mRedBandName = getRasterBandName(1); // sensible default
571-
mGreenBandName = getRasterBandName(2); // sensible default
569+
mRedBandName = getRasterBandName(myQSettings.value("/Raster/defaultRedBand", 1).toInt()); // sensible default
570+
mGreenBandName = getRasterBandName(myQSettings.value("/Raster/defaultGreenBand", 2).toInt()); // sensible default
572571
//for the third layer we cant be sure so..
573572
if (GDALGetRasterCount(mGdalDataset) > 2)
574573
{
575-
mBlueBandName = getRasterBandName(3); // sensible default
574+
mBlueBandName = getRasterBandName(myQSettings.value("/Raster/defaultBlueBand", 3).toInt()); // sensible default
576575
}
577576
else
578577
{
579-
mBlueBandName = TRSTRING_NOT_SET; // sensible default
578+
mBlueBandName = getRasterBandName(myQSettings.value("/Raster/defaultBlueBand", 2).toInt()); // sensible default
580579
}
581580

582581
mTransparencyBandName = TRSTRING_NOT_SET;
@@ -2220,50 +2219,41 @@ void QgsRasterLayer::showDebugOverlay(QPainter * theQPainter, QgsRasterViewPort
22202219

22212220
} //end of main draw method
22222221

2223-
/** Return the statistics for a given band name.
2224-
WARDNING::: THERE IS NO GUARANTEE THAT BAND NAMES ARE UNIQE
2225-
THE FIRST MATCH WILL BE RETURNED!!!!!!!!!!!!
2226-
*/
2227-
const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(QString const & theBandNameQString)
2222+
const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(QString const & theBandName)
22282223
{
22292224

22302225
//we cant use a vector iterator because the iterator is astruct not a class
22312226
//and the qvector model does not like this.
22322227
for (int i = 1; i <= GDALGetRasterCount(mGdalDataset); i++)
22332228
{
22342229
QgsRasterBandStats myRasterBandStats = getRasterBandStats(i);
2235-
if (myRasterBandStats.bandName == theBandNameQString)
2230+
if (myRasterBandStats.bandName == theBandName)
22362231
{
22372232
return myRasterBandStats;
22382233
}
22392234
}
22402235

22412236
return QgsRasterBandStats(); // return a null one
2242-
// XXX is this ok? IS there a "null" one?
22432237
}
22442238

2245-
//get the number of a band given its name
2246-
//note this should be the rewritten name set up in the constructor,
2247-
//not the name retrieved directly from gdal!
2248-
//if no matching band is found zero will be returned!
2249-
int QgsRasterLayer::getRasterBandNumber(QString const & theBandNameQString)
2239+
int QgsRasterLayer::getRasterBandNumber(QString const & theBandName)
22502240
{
22512241
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
22522242
{
22532243
//find out the name of this band
22542244
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2255-
QgsDebugMsg("myRasterBandStats.bandName: " + myRasterBandStats.bandName + " :: theBandNameQString: "\
2256-
+ theBandNameQString);
2245+
QgsDebugMsg("myRasterBandStats.bandName: " + myRasterBandStats.bandName + " :: theBandName: "\
2246+
+ theBandName);
22572247

2258-
if (myRasterBandStats.bandName == theBandNameQString)
2248+
if (myRasterBandStats.bandName == theBandName)
22592249
{
22602250
QgsDebugMsg("********** band " + QString::number(myRasterBandStats.bandNo) +\
2261-
" was found in getRasterBandNumber " + theBandNameQString);
2251+
" was found in getRasterBandNumber " + theBandName);
22622252

22632253
return myRasterBandStats.bandNo;
22642254
}
22652255
}
2266-
QgsDebugMsg("********** no band was found in getRasterBandNumber " + theBandNameQString);
2256+
QgsDebugMsg("********** no band was found in getRasterBandNumber " + theBandName);
22672257

22682258
return 0; //no band was found
22692259
}
@@ -2274,7 +2264,7 @@ int QgsRasterLayer::getRasterBandNumber(QString const & theBandNameQString)
22742264
const QString QgsRasterLayer::getRasterBandName(int theBandNo)
22752265
{
22762266

2277-
if (theBandNo <= mRasterStatsList.size())
2267+
if (theBandNo <= mRasterStatsList.size() && theBandNo > 0)
22782268
{
22792269
//vector starts at base 0, band counts at base1 !
22802270
return mRasterStatsList[theBandNo - 1].bandName;
@@ -2290,7 +2280,7 @@ const QString QgsRasterLayer::getRasterBandName(int theBandNo)
22902280
/** Check whether a given band number has stats associated with it */
22912281
bool QgsRasterLayer::hasStats(int theBandNo)
22922282
{
2293-
if (theBandNo <= mRasterStatsList.size())
2283+
if (theBandNo <= mRasterStatsList.size() && theBandNo > 0)
22942284
{
22952285
//vector starts at base 0, band counts at base1 !
22962286
return mRasterStatsList[theBandNo - 1].statsGatheredFlag;
@@ -2643,180 +2633,88 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
26432633

26442634

26452635

2646-
2647-
//mutator for red band name (allows alternate mappings e.g. map blue as red colour)
2648-
void QgsRasterLayer::setRedBandName(QString const & theBandNameQString)
2636+
QString QgsRasterLayer::validateBandName(QString const & theBandName)
26492637
{
2650-
QgsDebugMsg("setRedBandName : " + theBandNameQString);
2638+
QgsDebugMsg("validateBandName : Checking...");
26512639
//check if the band is unset
2652-
if (theBandNameQString == TRSTRING_NOT_SET || theBandNameQString == QSTRING_NOT_SET )
2640+
if (theBandName == TRSTRING_NOT_SET || theBandName == QSTRING_NOT_SET )
26532641
{
2642+
QgsDebugMsg("validateBandName : Band name is '" + QSTRING_NOT_SET + "'. Nothing to do.");
26542643
// Use translated name internally
2655-
mRedBandName = TRSTRING_NOT_SET;
2656-
return;
2644+
return TRSTRING_NOT_SET;
26572645
}
2646+
26582647
//check if the image is paletted
2659-
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
2648+
if (rasterLayerType == PALETTE && (theBandName == "Red" || theBandName == "Green" || theBandName == "Blue"))
26602649
{
2661-
mRedBandName = theBandNameQString;
2662-
return;
2650+
QgsDebugMsg("validateBandName : Paletted image valid faux RGB band name");
2651+
return theBandName;
26632652
}
2653+
26642654
//check that a valid band name was passed
2665-
2655+
QgsDebugMsg("validateBandName : Looking through raster band stats for matching band name");
26662656
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
26672657
{
26682658
//find out the name of this band
2669-
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2670-
if (myRasterBandStats.bandName == theBandNameQString)
2659+
if (mRasterStatsList[myIterator].bandName == theBandName)
26712660
{
2672-
mRedBandName = theBandNameQString;
2673-
return;
2661+
QgsDebugMsg("validateBandName : Matching band name found");
2662+
return theBandName;
26742663
}
26752664
}
2676-
2677-
//if no matches were found default to not set
2678-
mRedBandName = TRSTRING_NOT_SET;
2679-
return;
2680-
}
2681-
2682-
2683-
2684-
//mutator for green band name
2685-
void QgsRasterLayer::setGreenBandName(QString const & theBandNameQString)
2686-
{
2687-
//check if the band is unset
2688-
if (theBandNameQString == TRSTRING_NOT_SET || theBandNameQString == QSTRING_NOT_SET )
2689-
{
2690-
// Use translated name internally
2691-
mGreenBandName = TRSTRING_NOT_SET;
2692-
return;
2693-
}
2694-
//check if the image is paletted
2695-
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
2696-
{
2697-
mGreenBandName = theBandNameQString;
2698-
return;
2699-
}
2700-
//check that a valid band name was passed
2701-
2702-
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
2665+
QgsDebugMsg("validateBandName : No matching band name found in raster band stats");
2666+
2667+
QgsDebugMsg("validateBandName : Testing older naming format");
2668+
//See of the band in an older format #:something.
2669+
//TODO Remove test in v2.0
2670+
if(theBandName.contains(':'))
27032671
{
2704-
//find out the name of this band
2705-
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2706-
if (myRasterBandStats.bandName == theBandNameQString)
2672+
QStringList myBandNameComponents = theBandName.split(":");
2673+
if(myBandNameComponents.size() == 2)
27072674
{
2708-
mGreenBandName = theBandNameQString;
2709-
return;
2675+
int myBandNumber = myBandNameComponents.at(0).toInt();
2676+
if(myBandNumber > 0)
2677+
{
2678+
QgsDebugMsg("validateBandName : Transformed older name format to current format");
2679+
return "Band " + QString::number(myBandNumber);
2680+
}
27102681
}
27112682
}
2712-
2683+
27132684
//if no matches were found default to not set
2714-
mGreenBandName = TRSTRING_NOT_SET;
2715-
return;
2685+
QgsDebugMsg("validateBandName : All checks failed, returning '" + QSTRING_NOT_SET + "'");
2686+
return TRSTRING_NOT_SET;
27162687
}
27172688

2718-
//mutator for blue band name
2719-
void QgsRasterLayer::setBlueBandName(QString const & theBandNameQString)
2689+
//mutator for red band name (allows alternate mappings e.g. map blue as red colour)
2690+
void QgsRasterLayer::setRedBandName(QString const & theBandName)
27202691
{
2721-
//check if the band is unset
2722-
if (theBandNameQString == TRSTRING_NOT_SET || theBandNameQString == QSTRING_NOT_SET)
2723-
{
2724-
// Use translated name internally
2725-
mBlueBandName = TRSTRING_NOT_SET;
2726-
return;
2727-
}
2728-
//check if the image is paletted
2729-
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
2730-
{
2731-
mBlueBandName = theBandNameQString;
2732-
return;
2733-
}
2734-
//check that a valid band name was passed
2692+
QgsDebugMsg("setRedBandName : " + theBandName);
2693+
mRedBandName = validateBandName(theBandName);
2694+
}
27352695

2736-
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
2737-
{
2738-
//find out the name of this band
2739-
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2740-
if (myRasterBandStats.bandName == theBandNameQString)
2741-
{
2742-
mBlueBandName = theBandNameQString;
2743-
return;
2744-
}
2745-
}
2696+
//mutator for green band name
2697+
void QgsRasterLayer::setGreenBandName(QString const & theBandName)
2698+
{
2699+
mGreenBandName = validateBandName(theBandName);
2700+
}
27462701

2747-
//if no matches were found default to not set
2748-
mBlueBandName = TRSTRING_NOT_SET;
2749-
return;
2702+
//mutator for blue band name
2703+
void QgsRasterLayer::setBlueBandName(QString const & theBandName)
2704+
{
2705+
mBlueBandName = validateBandName(theBandName);
27502706
}
27512707

27522708
//mutator for transparent band name
2753-
void QgsRasterLayer::setTransparentBandName(QString const & theBandNameQString)
2709+
void QgsRasterLayer::setTransparentBandName(QString const & theBandName)
27542710
{
2755-
//check if the band is unset
2756-
if (theBandNameQString == TRSTRING_NOT_SET)
2757-
{
2758-
mTransparencyBandName = theBandNameQString;
2759-
return;
2760-
}
2761-
//check if the image is paletted
2762-
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
2763-
{
2764-
mTransparencyBandName = theBandNameQString;
2765-
return;
2766-
}
2767-
//check that a valid band name was passed
2768-
2769-
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
2770-
{
2771-
//find out the name of this band
2772-
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2773-
if (myRasterBandStats.bandName == theBandNameQString)
2774-
{
2775-
mTransparencyBandName = theBandNameQString;
2776-
return;
2777-
}
2778-
}
2779-
2780-
//if no matches were found default to not set
2781-
mTransparencyBandName = TRSTRING_NOT_SET;
2782-
return;
2711+
mTransparencyBandName = validateBandName(theBandName);
27832712
}
27842713

2785-
27862714
//mutator for gray band name
2787-
void QgsRasterLayer::setGrayBandName(QString const & theBandNameQString)
2715+
void QgsRasterLayer::setGrayBandName(QString const & theBandName)
27882716
{
2789-
//check if the band is unset
2790-
if (theBandNameQString == TRSTRING_NOT_SET || theBandNameQString == QSTRING_NOT_SET )
2791-
{
2792-
// Use translated name internally
2793-
mGrayBandName = TRSTRING_NOT_SET;
2794-
return;
2795-
}
2796-
//check if the image is paletted
2797-
if (rasterLayerType == PALETTE && (theBandNameQString == mRedBandName || theBandNameQString == mGreenBandName || theBandNameQString == mBlueBandName))
2798-
{
2799-
mGrayBandName = theBandNameQString;
2800-
return;
2801-
}
2802-
//otherwise check that a valid band name was passed
2803-
2804-
for (int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator)
2805-
{
2806-
//find out the name of this band
2807-
QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator];
2808-
QgsDebugMsg("Checking if " + myRasterBandStats.bandName + " == "
2809-
+ mGrayBandName);
2810-
if (myRasterBandStats.bandName == theBandNameQString)
2811-
{
2812-
mGrayBandName = theBandNameQString;
2813-
return;
2814-
}
2815-
}
2816-
2817-
//if no matches were found default to not set
2818-
mGrayBandName = TRSTRING_NOT_SET;
2819-
return;
2717+
mGrayBandName = validateBandName(theBandName);
28202718
}
28212719

28222720
/** Return a pixmap representing a legend image. This is an overloaded

‎src/core/raster/qgsrasterlayer.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
367367
/** \brief Get the number of a band given its name. Note this will be the rewritten name set
368368
* up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
369369
* If no matching band is found zero will be returned! */
370-
int getRasterBandNumber (const QString & theBandNameQString);
370+
int getRasterBandNumber (const QString & theBandName);
371371
/** \brief Get the name of a band given its number. */
372372
const QString getRasterBandName(int theBandNoInt);
373373
/** \brief Find out whether a given band exists. */
@@ -380,7 +380,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
380380
return mRedBandName;
381381
}
382382
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color). */
383-
void setRedBandName(const QString & theBandNameQString);
383+
void setRedBandName(const QString & theBandName);
384384
//
385385
// Accessor and mutator for green band name
386386
//
@@ -390,7 +390,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
390390
return mGreenBandName;
391391
}
392392
/** \brief Mutator for green band name mapping. */
393-
void setGreenBandName(const QString & theBandNameQString);
393+
void setGreenBandName(const QString & theBandName);
394394
//
395395
// Accessor and mutator for blue band name
396396
//
@@ -400,7 +400,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
400400
return mBlueBandName;
401401
}
402402
/** \brief Mutator for blue band name mapping. */
403-
void setBlueBandName(const QString & theBandNameQString);
403+
void setBlueBandName(const QString & theBandName);
404404

405405
//
406406
// Accessor raster transparency object
@@ -417,7 +417,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
417417
return mTransparencyBandName;
418418
}
419419
/** \brief Mutator for transparent band name mapping. */
420-
void setTransparentBandName(const QString & theBandNameQString);
420+
void setTransparentBandName(const QString & theBandName);
421421

422422
//
423423
// Accessor and mutator for gray band name
@@ -428,7 +428,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
428428
return mGrayBandName;
429429
}
430430
/** \brief Mutator for gray band name mapping. */
431-
void setGrayBandName(const QString & theBandNameQString);
431+
void setGrayBandName(const QString & theBandName);
432432
//
433433
// Accessor and mutator for mDebugOverlayFlag
434434
//
@@ -1010,6 +1010,9 @@ public slots:
10101010
/** \brief Update the layer if it is outdated */
10111011
bool update ();
10121012

1013+
/** \brief Verify and transform band name for internal consistency. Return 'Not Set' on any type of failure */
1014+
QString validateBandName(const QString & theBandName);
1015+
10131016
//
10141017
// Private member vars
10151018
//

‎src/ui/qgsrasterlayerpropertiesbase.ui

Lines changed: 127 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,60 @@
3737
<property name="title" >
3838
<string>Render as</string>
3939
</property>
40-
<layout class="QGridLayout" >
41-
<item row="0" column="0" >
40+
<layout class="QHBoxLayout" >
41+
<item>
4242
<widget class="QRadioButton" name="rbtnSingleBand" >
4343
<property name="text" >
4444
<string>Single band gray</string>
4545
</property>
4646
</widget>
4747
</item>
48-
<item row="0" column="1" >
48+
<item>
49+
<spacer>
50+
<property name="orientation" >
51+
<enum>Qt::Horizontal</enum>
52+
</property>
53+
<property name="sizeHint" >
54+
<size>
55+
<width>40</width>
56+
<height>20</height>
57+
</size>
58+
</property>
59+
</spacer>
60+
</item>
61+
<item>
4962
<widget class="QRadioButton" name="rbtnThreeBand" >
5063
<property name="text" >
5164
<string>Three band color</string>
5265
</property>
5366
</widget>
5467
</item>
68+
<item>
69+
<spacer>
70+
<property name="orientation" >
71+
<enum>Qt::Horizontal</enum>
72+
</property>
73+
<property name="sizeHint" >
74+
<size>
75+
<width>40</width>
76+
<height>20</height>
77+
</size>
78+
</property>
79+
</spacer>
80+
</item>
81+
<item>
82+
<widget class="QCheckBox" name="cboxInvertColorMap" >
83+
<property name="sizePolicy" >
84+
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
85+
<horstretch>0</horstretch>
86+
<verstretch>0</verstretch>
87+
</sizepolicy>
88+
</property>
89+
<property name="text" >
90+
<string>Invert color map</string>
91+
</property>
92+
</widget>
93+
</item>
5594
</layout>
5695
</widget>
5796
</item>
@@ -96,7 +135,7 @@
96135
</property>
97136
</widget>
98137
</item>
99-
<item row="0" column="1" colspan="3" >
138+
<item row="0" column="1" colspan="4" >
100139
<widget class="QComboBox" name="cboRed" >
101140
<property name="sizePolicy" >
102141
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -128,7 +167,7 @@
128167
</property>
129168
</widget>
130169
</item>
131-
<item row="1" column="1" colspan="3" >
170+
<item row="1" column="1" colspan="4" >
132171
<widget class="QComboBox" name="cboGreen" >
133172
<property name="sizePolicy" >
134173
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -160,7 +199,7 @@
160199
</property>
161200
</widget>
162201
</item>
163-
<item row="2" column="1" colspan="3" >
202+
<item row="2" column="1" colspan="4" >
164203
<widget class="QComboBox" name="cboBlue" >
165204
<property name="sizePolicy" >
166205
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -182,14 +221,47 @@
182221
</property>
183222
</widget>
184223
</item>
185-
<item row="3" column="0" colspan="2" >
224+
<item row="3" column="3" colspan="2" >
225+
<layout class="QHBoxLayout" >
226+
<item>
227+
<widget class="QLabel" name="labelDefaultBandCombination" >
228+
<property name="text" >
229+
<string>Default R:1 G:2 B:3</string>
230+
</property>
231+
</widget>
232+
</item>
233+
<item>
234+
<widget class="QPushButton" name="pbtnMakeBandCombinationDefault" >
235+
<property name="sizePolicy" >
236+
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
237+
<horstretch>0</horstretch>
238+
<verstretch>0</verstretch>
239+
</sizepolicy>
240+
</property>
241+
<property name="toolTip" >
242+
<string>Save current band combination as default. This setting will be persistent between QGIS sessions.</string>
243+
</property>
244+
<property name="whatsThis" >
245+
<string>Save current band combination as a default. This setting will be persistent between QGIS sessions.</string>
246+
</property>
247+
<property name="text" >
248+
<string/>
249+
</property>
250+
<property name="icon" >
251+
<iconset>../../images/themes/default/mActionFileSave.png</iconset>
252+
</property>
253+
</widget>
254+
</item>
255+
</layout>
256+
</item>
257+
<item row="4" column="0" colspan="5" >
186258
<widget class="QRadioButton" name="rbtnThreeBandMinMax" >
187259
<property name="text" >
188260
<string>Custom min / max values</string>
189261
</property>
190262
</widget>
191263
</item>
192-
<item row="4" column="0" >
264+
<item row="5" column="0" >
193265
<widget class="QLabel" name="lblRedMin" >
194266
<property name="sizePolicy" >
195267
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -202,7 +274,7 @@
202274
</property>
203275
</widget>
204276
</item>
205-
<item row="4" column="1" >
277+
<item row="5" column="1" >
206278
<widget class="QLineEdit" name="leRedMin" >
207279
<property name="sizePolicy" >
208280
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -227,7 +299,20 @@
227299
</property>
228300
</widget>
229301
</item>
230-
<item row="4" column="2" >
302+
<item row="5" column="2" >
303+
<spacer>
304+
<property name="orientation" >
305+
<enum>Qt::Horizontal</enum>
306+
</property>
307+
<property name="sizeHint" >
308+
<size>
309+
<width>119</width>
310+
<height>16</height>
311+
</size>
312+
</property>
313+
</spacer>
314+
</item>
315+
<item row="5" column="3" >
231316
<widget class="QLabel" name="lblRedMax" >
232317
<property name="sizePolicy" >
233318
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -240,7 +325,7 @@
240325
</property>
241326
</widget>
242327
</item>
243-
<item row="4" column="3" >
328+
<item row="5" column="4" >
244329
<widget class="QLineEdit" name="leRedMax" >
245330
<property name="sizePolicy" >
246331
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -265,7 +350,7 @@
265350
</property>
266351
</widget>
267352
</item>
268-
<item row="5" column="0" >
353+
<item row="6" column="0" >
269354
<widget class="QLabel" name="lblGreenMin" >
270355
<property name="sizePolicy" >
271356
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -278,7 +363,7 @@
278363
</property>
279364
</widget>
280365
</item>
281-
<item row="5" column="1" >
366+
<item row="6" column="1" >
282367
<widget class="QLineEdit" name="leGreenMin" >
283368
<property name="sizePolicy" >
284369
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -303,7 +388,7 @@
303388
</property>
304389
</widget>
305390
</item>
306-
<item row="5" column="2" >
391+
<item row="6" column="3" >
307392
<widget class="QLabel" name="lblGreenMax" >
308393
<property name="sizePolicy" >
309394
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -316,7 +401,7 @@
316401
</property>
317402
</widget>
318403
</item>
319-
<item row="5" column="3" >
404+
<item row="6" column="4" >
320405
<widget class="QLineEdit" name="leGreenMax" >
321406
<property name="sizePolicy" >
322407
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -341,7 +426,7 @@
341426
</property>
342427
</widget>
343428
</item>
344-
<item row="6" column="0" >
429+
<item row="7" column="0" >
345430
<widget class="QLabel" name="lblBlueMin" >
346431
<property name="sizePolicy" >
347432
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -354,7 +439,7 @@
354439
</property>
355440
</widget>
356441
</item>
357-
<item row="6" column="1" >
442+
<item row="7" column="1" >
358443
<widget class="QLineEdit" name="leBlueMin" >
359444
<property name="sizePolicy" >
360445
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -379,7 +464,7 @@
379464
</property>
380465
</widget>
381466
</item>
382-
<item row="6" column="2" >
467+
<item row="7" column="3" >
383468
<widget class="QLabel" name="lblBlueMax" >
384469
<property name="sizePolicy" >
385470
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
@@ -392,7 +477,7 @@
392477
</property>
393478
</widget>
394479
</item>
395-
<item row="6" column="3" >
480+
<item row="7" column="4" >
396481
<widget class="QLineEdit" name="leBlueMax" >
397482
<property name="sizePolicy" >
398483
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
@@ -417,14 +502,14 @@
417502
</property>
418503
</widget>
419504
</item>
420-
<item row="7" column="0" colspan="2" >
505+
<item row="8" column="0" colspan="2" >
421506
<widget class="QRadioButton" name="rbtnThreeBandStdDev" >
422507
<property name="text" >
423-
<string>Std. deviation</string>
508+
<string>Use standard deviation</string>
424509
</property>
425510
</widget>
426511
</item>
427-
<item row="7" column="3" >
512+
<item row="8" column="4" >
428513
<widget class="QDoubleSpinBox" name="sboxThreeBandStdDev" >
429514
<property name="maximum" >
430515
<double>10.000000000000000</double>
@@ -514,27 +599,14 @@
514599
</property>
515600
</widget>
516601
</item>
517-
<item row="2" column="1" colspan="5" >
518-
<widget class="QCheckBox" name="cboxInvertColorMap" >
519-
<property name="sizePolicy" >
520-
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
521-
<horstretch>0</horstretch>
522-
<verstretch>0</verstretch>
523-
</sizepolicy>
524-
</property>
525-
<property name="text" >
526-
<string>Invert color map</string>
527-
</property>
528-
</widget>
529-
</item>
530-
<item row="3" column="0" colspan="2" >
602+
<item row="4" column="0" colspan="2" >
531603
<widget class="QRadioButton" name="rbtnSingleBandMinMax" >
532604
<property name="text" >
533605
<string>Custom min / max values</string>
534606
</property>
535607
</widget>
536608
</item>
537-
<item row="3" column="2" >
609+
<item row="4" column="2" >
538610
<widget class="QLabel" name="lblGrayMin" >
539611
<property name="sizePolicy" >
540612
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
@@ -547,7 +619,7 @@
547619
</property>
548620
</widget>
549621
</item>
550-
<item row="3" column="3" >
622+
<item row="4" column="3" >
551623
<widget class="QLineEdit" name="leGrayMin" >
552624
<property name="sizePolicy" >
553625
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
@@ -572,7 +644,7 @@
572644
</property>
573645
</widget>
574646
</item>
575-
<item row="3" column="4" >
647+
<item row="4" column="4" >
576648
<widget class="QLabel" name="lblGrayMax" >
577649
<property name="sizePolicy" >
578650
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
@@ -585,7 +657,7 @@
585657
</property>
586658
</widget>
587659
</item>
588-
<item row="3" column="5" >
660+
<item row="4" column="5" >
589661
<widget class="QLineEdit" name="leGrayMax" >
590662
<property name="sizePolicy" >
591663
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
@@ -610,14 +682,14 @@
610682
</property>
611683
</widget>
612684
</item>
613-
<item row="4" column="0" colspan="2" >
685+
<item row="5" column="0" colspan="2" >
614686
<widget class="QRadioButton" name="rbtnSingleBandStdDev" >
615687
<property name="text" >
616688
<string>Use standard deviation</string>
617689
</property>
618690
</widget>
619691
</item>
620-
<item row="4" column="3" >
692+
<item row="5" column="3" >
621693
<widget class="QDoubleSpinBox" name="sboxSingleBandStdDev" >
622694
<property name="maximum" >
623695
<double>10.000000000000000</double>
@@ -630,6 +702,19 @@
630702
</property>
631703
</widget>
632704
</item>
705+
<item row="2" column="1" >
706+
<spacer>
707+
<property name="orientation" >
708+
<enum>Qt::Vertical</enum>
709+
</property>
710+
<property name="sizeHint" >
711+
<size>
712+
<width>20</width>
713+
<height>40</height>
714+
</size>
715+
</property>
716+
</spacer>
717+
</item>
633718
</layout>
634719
</widget>
635720
</item>
@@ -2041,7 +2126,6 @@ p, li { white-space: pre-wrap; }
20412126
<layoutdefault spacing="6" margin="11" />
20422127
<tabstops>
20432128
<tabstop>tabBar</tabstop>
2044-
<tabstop>cboxInvertColorMap</tabstop>
20452129
<tabstop>cboRed</tabstop>
20462130
<tabstop>cboGreen</tabstop>
20472131
<tabstop>cboBlue</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.