Skip to content

Commit d0625ef

Browse files
author
gjm
committed
Fix for #2820, layer extents use scientific notation for large numbers
when it would be better to stick with non-scientific notation git-svn-id: http://svn.osgeo.org/qgis/trunk@13887 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 75a8fc8 commit d0625ef

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/app/qgsvectorlayerproperties.cpp

+50-2
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,58 @@ QString QgsVectorLayerProperties::metadata()
781781
myMetadata += "</td></tr>";
782782
//extents in layer cs TODO...maybe make a little nested table to improve layout...
783783
myMetadata += "<tr><td>";
784+
785+
// Try to be a bit clever over what number format we use for the
786+
// extents. Some people don't like it using scientific notation when the
787+
// numbers get large, but for small numbers this is the more practical
788+
// option (so we can't force the format to 'f' for all values).
789+
// The scheme:
790+
// - for all numbers with more than 5 digits, force non-scientific notation
791+
// and 2 digits after the decimal point.
792+
// - for all smaller numbers let the OS decide which format to use (it will
793+
// generally use non-scientific unless the number gets much less than 1).
794+
795+
QString xMin, yMin, xMax, yMax;
796+
double changeoverValue = 99999; // The 'largest' 5 digit number
797+
if (fabs(myExtent.xMinimum()) > changeoverValue)
798+
{
799+
xMin = QString("%1").arg(myExtent.xMinimum(), 0, 'f', 2);
800+
}
801+
else
802+
{
803+
xMin = QString("%1").arg(myExtent.xMinimum());
804+
}
805+
806+
if (fabs(myExtent.yMinimum()) > changeoverValue)
807+
{
808+
yMin = QString("%1").arg(myExtent.yMinimum(), 0, 'f', 2);
809+
}
810+
else
811+
{
812+
yMin = QString("%1").arg(myExtent.yMinimum());
813+
}
814+
815+
if (fabs(myExtent.xMaximum()) > changeoverValue)
816+
{
817+
xMax = QString("%1").arg(myExtent.xMaximum(), 0, 'f', 2);
818+
}
819+
else
820+
{
821+
xMax = QString("%1").arg(myExtent.xMaximum());
822+
}
823+
824+
if (fabs(myExtent.yMaximum()) > changeoverValue)
825+
{
826+
yMax = QString("%1").arg(myExtent.yMaximum(), 0, 'f', 2);
827+
}
828+
else
829+
{
830+
yMax = QString("%1").arg(myExtent.yMaximum());
831+
}
832+
784833
myMetadata += tr( "In layer spatial reference system units : " )
785834
+ tr( "xMin,yMin %1,%2 : xMax,yMax %3,%4" )
786-
.arg( myExtent.xMinimum() ).arg( myExtent.yMinimum() )
787-
.arg( myExtent.xMaximum() ).arg( myExtent.yMaximum() );
835+
.arg( xMin ).arg( yMin ).arg( xMax ).arg( yMax );
788836
myMetadata += "</td></tr>";
789837

790838
//extents in project cs

0 commit comments

Comments
 (0)