Skip to content
Permalink
Browse files
- introduce qgsDoubleToString for format double with maximum precision
- usage in mssql provider fixes #7638
- read precision in mssql provider (fixes #5966)
- commit errors are only shown once
  • Loading branch information
jef-n committed Jul 17, 2013
1 parent e0a0a3a commit b1efd47961260f58e3536f1916dab196f3ed8d15
@@ -4269,6 +4269,7 @@ void QgisApp::commitError( QgsVectorLayer* vlayer )
showMore->setDefaultAction( act );

connect( showMore, SIGNAL( triggered( QAction* ) ), mv, SLOT( exec() ) );
connect( showMore, SIGNAL( triggered( QAction* ) ), showMore, SLOT( deleteLater() ) );
errorMsg->layout()->addWidget( showMore );

// no timeout set, since notice needs attention and is only shown first time layer is labeled
@@ -940,10 +940,10 @@ void QgsProjectProperties::restoreState()
void QgsProjectProperties::on_pbnWMSExtCanvas_clicked()
{
QgsRectangle ext = mMapCanvas->extent();
mWMSExtMinX->setText( QString::number( ext.xMinimum(), 'f', 8 ) );
mWMSExtMinY->setText( QString::number( ext.yMinimum(), 'f', 8 ) );
mWMSExtMaxX->setText( QString::number( ext.xMaximum(), 'f', 8 ) );
mWMSExtMaxY->setText( QString::number( ext.yMaximum(), 'f', 8 ) );
mWMSExtMinX->setText( qgsDoubleToString( ext.xMinimum() ) );
mWMSExtMinY->setText( qgsDoubleToString( ext.yMinimum() ) );
mWMSExtMaxX->setText( qgsDoubleToString( ext.xMaximum() ) );
mWMSExtMaxY->setText( qgsDoubleToString( ext.yMaximum() ) );
}

void QgsProjectProperties::on_pbnWMSAddSRS_clicked()
@@ -20,6 +20,7 @@

#include <QEvent>
#include <QString>
#include <QRegExp>
#include <QMetaType>
#include <QVariant>
#include <stdlib.h>
@@ -243,6 +244,14 @@ inline void ( *cast_to_fptr( void *p ) )()
return u.f;
}

//
// return a string representation of a double
//
inline QString qgsDoubleToString( const double &a )
{
return QString::number( a, 'f', 17 ).remove( QRegExp( "\\.?0+$" ) );
}

//
// compare two doubles (but allow some difference)
//
@@ -4006,10 +4006,10 @@ QString QgsGeometry::exportToWkt() const
{
mWkt += "POINT(";
x = ( double * )( mGeometry + 5 );
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += " ";
y = ( double * )( mGeometry + 5 + sizeof( double ) );
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
mWkt += ")";
return mWkt;
}
@@ -4035,11 +4035,11 @@ QString QgsGeometry::exportToWkt() const
mWkt += ", ";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += " ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4090,11 +4090,11 @@ QString QgsGeometry::exportToWkt() const
mWkt += ",";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += " ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4128,11 +4128,11 @@ QString QgsGeometry::exportToWkt() const
mWkt += ", ";
}
x = ( double * )( ptr );
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += " ";
ptr += sizeof( double );
y = ( double * )( ptr );
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4172,11 +4172,11 @@ QString QgsGeometry::exportToWkt() const
mWkt += ", ";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
ptr += sizeof( double );
mWkt += " ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4228,11 +4228,11 @@ QString QgsGeometry::exportToWkt() const
mWkt += ",";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
ptr += sizeof( double );
mWkt += " ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4286,10 +4286,10 @@ QString QgsGeometry::exportToGeoJSON() const
{
mWkt += "{ \"type\": \"Point\", \"coordinates\": [";
x = ( double * )( mGeometry + 5 );
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += ", ";
y = ( double * )( mGeometry + 5 + sizeof( double ) );
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
mWkt += "] }";
return mWkt;
}
@@ -4316,11 +4316,11 @@ QString QgsGeometry::exportToGeoJSON() const
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4373,11 +4373,11 @@ QString QgsGeometry::exportToGeoJSON() const
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4413,11 +4413,11 @@ QString QgsGeometry::exportToGeoJSON() const
}
mWkt += "[";
x = ( double * )( ptr );
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * )( ptr );
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4459,11 +4459,11 @@ QString QgsGeometry::exportToGeoJSON() const
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4517,11 +4517,11 @@ QString QgsGeometry::exportToGeoJSON() const
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *x );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
mWkt += qgsDoubleToString( *y );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -190,9 +190,9 @@ void QgsMapRenderer::adjustExtentToSize()
dymax = mExtent.yMaximum() + whitespace;
}

QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( mapUnitsPerPixelX, 0, 'f', 8 ).arg( mapUnitsPerPixelY, 0, 'f', 8 ) );
QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( myWidth, 0, 'f', 8 ).arg( myHeight, 0, 'f', 8 ) );
QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( mExtent.width(), 0, 'f', 8 ).arg( mExtent.height(), 0, 'f', 8 ) );
QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ) ).arg( qgsDoubleToString( mapUnitsPerPixelY ) ) );
QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( myWidth ) ).arg( qgsDoubleToString( myHeight ) ) );
QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ) ).arg( qgsDoubleToString( mExtent.height() ) ) );
QgsDebugMsg( mExtent.toString() );

// update extent
@@ -201,14 +201,14 @@ void QgsMapRenderer::adjustExtentToSize()
mExtent.setYMinimum( dymin );
mExtent.setYMaximum( dymax );

QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( mExtent.width() / myWidth, 0, 'f', 8 ).arg( mExtent.height() / myHeight, 0, 'f', 8 ) );
QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() / myWidth ) ).arg( qgsDoubleToString( mExtent.height() / myHeight ) ) );

QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( mExtent.width() / mMapUnitsPerPixel, 0, 'f', 8 ).arg( mExtent.height() / mMapUnitsPerPixel, 0, 'f', 8 ) );
QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() / mMapUnitsPerPixel ) ).arg( qgsDoubleToString( mExtent.height() / mMapUnitsPerPixel ) ) );

// update the scale
updateScale();

QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( mScale, 0, 'f', 8 ) );
QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );

newCoordXForm.setParameters( mMapUnitsPerPixel, dxmin, dymin, myHeight );
mRenderContext.setMapToPixel( newCoordXForm );
@@ -960,8 +960,8 @@ void QgsMapRenderer::updateFullExtent()

if ( lyr->extent().isEmpty() )
{
it++;
continue;
it++;
continue;
}

// Layer extents are stored in the coordinate system (CS) of the
@@ -1129,10 +1129,10 @@ bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
QDomElement yMax = theDoc.createElement( "ymax" );

QgsRectangle r = extent();
QDomText xMinText = theDoc.createTextNode( QString::number( r.xMinimum(), 'f' ) );
QDomText yMinText = theDoc.createTextNode( QString::number( r.yMinimum(), 'f' ) );
QDomText xMaxText = theDoc.createTextNode( QString::number( r.xMaximum(), 'f' ) );
QDomText yMaxText = theDoc.createTextNode( QString::number( r.yMaximum(), 'f' ) );
QDomText xMinText = theDoc.createTextNode( qgsDoubleToString( r.xMinimum() ) );
QDomText yMinText = theDoc.createTextNode( qgsDoubleToString( r.yMinimum() ) );
QDomText xMaxText = theDoc.createTextNode( qgsDoubleToString( r.xMaximum() ) );
QDomText yMaxText = theDoc.createTextNode( qgsDoubleToString( r.yMaximum() ) );

xMin.appendChild( xMinText );
yMin.appendChild( yMinText );

0 comments on commit b1efd47

Please sign in to comment.