[QGIS Commit] r10279 - trunk/qgis/src/core/raster

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Mar 14 17:54:08 EDT 2009


Author: ersts
Date: 2009-03-14 17:54:08 -0400 (Sat, 14 Mar 2009)
New Revision: 10279

Modified:
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
Log:
-Simplified the QgsRasterLayer::generateBandName function based on a suggestion from Jef

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2009-03-14 19:20:50 UTC (rev 10278)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2009-03-14 21:54:08 UTC (rev 10279)
@@ -4892,33 +4892,7 @@
 
 QString QgsRasterLayer::generateBandName( int theBandNumber )
 {
-  //Calculate magnitude of band count for padding
-  QString myBandName = tr( "Band" ) + " ";
-  int myBandCount = bandCount();
-  int myLeadingZeros = 0;
-  int myWholeNumber = myBandCount / 10;
-  while( myWholeNumber > 0 )
-  {
-    myLeadingZeros++;
-    myWholeNumber = myBandCount / pow( 10, myLeadingZeros + 1 );
-  }
-
-  //Pad the band number of needed
-  int myMagnitude = 0;
-  myWholeNumber = theBandNumber / 10;
-  while( myWholeNumber > 0 )
-  {
-    myMagnitude++;
-    myWholeNumber = theBandNumber / pow( 10, myMagnitude + 1 );
-  }
-
-  for( int myPadder = 0; myPadder < myLeadingZeros - myMagnitude; myPadder++ )
-  {
-    myBandName += "0";
-  }
-  myBandName += QString::number( theBandNumber );
-
-  return myBandName;
+  return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber,  1 + ( int ) log10( ( float ) bandCount() ), 10, QChar( '0' ) );
 }
 
 /**



More information about the QGIS-commit mailing list