@@ -516,10 +516,9 @@ bool QgsRasterLayer::readFile( QString const & fileName )
516
516
for (int i = 1 ; i <= GDALGetRasterCount (mGdalDataset ); i++)
517
517
{
518
518
GDALRasterBandH myGdalBand = GDALGetRasterBand (mGdalDataset ,i);
519
- QString myColorQString = GDALGetColorInterpretationName (GDALGetRasterColorInterpretation (myGdalBand));
520
519
QgsRasterBandStats myRasterBandStats;
521
520
// myRasterBandStats.bandName = myColorQString ;
522
- myRasterBandStats.bandName =QString::number (i) + " : " + myColorQString ;
521
+ myRasterBandStats.bandName =" Band " + QString::number (i);
523
522
myRasterBandStats.bandNo = i;
524
523
myRasterBandStats.statsGatheredFlag = false ;
525
524
myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector ();
@@ -567,16 +566,16 @@ bool QgsRasterLayer::readFile( QString const & fileName )
567
566
else if (rasterLayerType == MULTIBAND)
568
567
{
569
568
// 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
572
571
// for the third layer we cant be sure so..
573
572
if (GDALGetRasterCount (mGdalDataset ) > 2 )
574
573
{
575
- mBlueBandName = getRasterBandName (3 ); // sensible default
574
+ mBlueBandName = getRasterBandName (myQSettings. value ( " /Raster/defaultBlueBand " , 3 ). toInt () ); // sensible default
576
575
}
577
576
else
578
577
{
579
- mBlueBandName = TRSTRING_NOT_SET ; // sensible default
578
+ mBlueBandName = getRasterBandName (myQSettings. value ( " /Raster/defaultBlueBand " , 2 ). toInt ()) ; // sensible default
580
579
}
581
580
582
581
mTransparencyBandName = TRSTRING_NOT_SET;
@@ -2220,50 +2219,41 @@ void QgsRasterLayer::showDebugOverlay(QPainter * theQPainter, QgsRasterViewPort
2220
2219
2221
2220
} // end of main draw method
2222
2221
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)
2228
2223
{
2229
2224
2230
2225
// we cant use a vector iterator because the iterator is astruct not a class
2231
2226
// and the qvector model does not like this.
2232
2227
for (int i = 1 ; i <= GDALGetRasterCount (mGdalDataset ); i++)
2233
2228
{
2234
2229
QgsRasterBandStats myRasterBandStats = getRasterBandStats (i);
2235
- if (myRasterBandStats.bandName == theBandNameQString )
2230
+ if (myRasterBandStats.bandName == theBandName )
2236
2231
{
2237
2232
return myRasterBandStats;
2238
2233
}
2239
2234
}
2240
2235
2241
2236
return QgsRasterBandStats (); // return a null one
2242
- // XXX is this ok? IS there a "null" one?
2243
2237
}
2244
2238
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)
2250
2240
{
2251
2241
for (int myIterator = 0 ; myIterator < mRasterStatsList .size (); ++myIterator)
2252
2242
{
2253
2243
// find out the name of this band
2254
2244
QgsRasterBandStats myRasterBandStats = mRasterStatsList [myIterator];
2255
- QgsDebugMsg (" myRasterBandStats.bandName: " + myRasterBandStats.bandName + " :: theBandNameQString : " \
2256
- + theBandNameQString );
2245
+ QgsDebugMsg (" myRasterBandStats.bandName: " + myRasterBandStats.bandName + " :: theBandName : " \
2246
+ + theBandName );
2257
2247
2258
- if (myRasterBandStats.bandName == theBandNameQString )
2248
+ if (myRasterBandStats.bandName == theBandName )
2259
2249
{
2260
2250
QgsDebugMsg (" ********** band " + QString::number (myRasterBandStats.bandNo ) +\
2261
- " was found in getRasterBandNumber " + theBandNameQString );
2251
+ " was found in getRasterBandNumber " + theBandName );
2262
2252
2263
2253
return myRasterBandStats.bandNo ;
2264
2254
}
2265
2255
}
2266
- QgsDebugMsg (" ********** no band was found in getRasterBandNumber " + theBandNameQString );
2256
+ QgsDebugMsg (" ********** no band was found in getRasterBandNumber " + theBandName );
2267
2257
2268
2258
return 0 ; // no band was found
2269
2259
}
@@ -2274,7 +2264,7 @@ int QgsRasterLayer::getRasterBandNumber(QString const & theBandNameQString)
2274
2264
const QString QgsRasterLayer::getRasterBandName (int theBandNo)
2275
2265
{
2276
2266
2277
- if (theBandNo <= mRasterStatsList .size ())
2267
+ if (theBandNo <= mRasterStatsList .size () && theBandNo > 0 )
2278
2268
{
2279
2269
// vector starts at base 0, band counts at base1 !
2280
2270
return mRasterStatsList [theBandNo - 1 ].bandName ;
@@ -2290,7 +2280,7 @@ const QString QgsRasterLayer::getRasterBandName(int theBandNo)
2290
2280
/* * Check whether a given band number has stats associated with it */
2291
2281
bool QgsRasterLayer::hasStats (int theBandNo)
2292
2282
{
2293
- if (theBandNo <= mRasterStatsList .size ())
2283
+ if (theBandNo <= mRasterStatsList .size () && theBandNo > 0 )
2294
2284
{
2295
2285
// vector starts at base 0, band counts at base1 !
2296
2286
return mRasterStatsList [theBandNo - 1 ].statsGatheredFlag ;
@@ -2643,180 +2633,88 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNo)
2643
2633
2644
2634
2645
2635
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)
2649
2637
{
2650
- QgsDebugMsg (" setRedBandName : " + theBandNameQString );
2638
+ QgsDebugMsg (" validateBandName : Checking... " );
2651
2639
// 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 )
2653
2641
{
2642
+ QgsDebugMsg (" validateBandName : Band name is '" + QSTRING_NOT_SET + " '. Nothing to do." );
2654
2643
// Use translated name internally
2655
- mRedBandName = TRSTRING_NOT_SET;
2656
- return ;
2644
+ return TRSTRING_NOT_SET;
2657
2645
}
2646
+
2658
2647
// 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" ))
2660
2649
{
2661
- mRedBandName = theBandNameQString ;
2662
- return ;
2650
+ QgsDebugMsg ( " validateBandName : Paletted image valid faux RGB band name " ) ;
2651
+ return theBandName ;
2663
2652
}
2653
+
2664
2654
// check that a valid band name was passed
2665
-
2655
+ QgsDebugMsg ( " validateBandName : Looking through raster band stats for matching band name " );
2666
2656
for (int myIterator = 0 ; myIterator < mRasterStatsList .size (); ++myIterator)
2667
2657
{
2668
2658
// find out the name of this band
2669
- QgsRasterBandStats myRasterBandStats = mRasterStatsList [myIterator];
2670
- if (myRasterBandStats.bandName == theBandNameQString)
2659
+ if (mRasterStatsList [myIterator].bandName == theBandName)
2671
2660
{
2672
- mRedBandName = theBandNameQString ;
2673
- return ;
2661
+ QgsDebugMsg ( " validateBandName : Matching band name found " ) ;
2662
+ return theBandName ;
2674
2663
}
2675
2664
}
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 (' :' ))
2703
2671
{
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 )
2707
2674
{
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
+ }
2710
2681
}
2711
2682
}
2712
-
2683
+
2713
2684
// 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 ;
2716
2687
}
2717
2688
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 )
2720
2691
{
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
+ }
2735
2695
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
+ }
2746
2701
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);
2750
2706
}
2751
2707
2752
2708
// mutator for transparent band name
2753
- void QgsRasterLayer::setTransparentBandName (QString const & theBandNameQString )
2709
+ void QgsRasterLayer::setTransparentBandName (QString const & theBandName )
2754
2710
{
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);
2783
2712
}
2784
2713
2785
-
2786
2714
// mutator for gray band name
2787
- void QgsRasterLayer::setGrayBandName (QString const & theBandNameQString )
2715
+ void QgsRasterLayer::setGrayBandName (QString const & theBandName )
2788
2716
{
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);
2820
2718
}
2821
2719
2822
2720
/* * Return a pixmap representing a legend image. This is an overloaded
0 commit comments