Skip to content
Permalink
Browse files

[QgsMapToPixel] API cleanup

* overload toMapCoordinates to also take double (use different PyName)
* deprecate toMapPoint which is strictly equivalent to toMapCoordinates
  • Loading branch information
3nids committed Sep 29, 2018
1 parent 65bdc83 commit 73c02fe95b0816a1a2be473b937e536cc7bdc3b2
@@ -95,8 +95,11 @@ transform.


QgsPointXY toMapCoordinates( int x, int y ) const;
%Docstring
Transform device coordinates to map (world) coordinates
%End

QgsPointXY toMapCoordinatesF( double x, double y ) const;
QgsPointXY toMapCoordinates( double x, double y ) const /PyName=toMapCoordinatesF/;
%Docstring
Transform device coordinates to map (world) coordinates
%End
@@ -110,7 +113,12 @@ Transform device coordinates to map (world) coordinates
:return: QgsPointXY in map coorndiates
%End

QgsPointXY toMapPoint( double x, double y ) const;
QgsPointXY toMapPoint( double x, double y ) const;
%Docstring
Transform device coordinates to map (world) coordinates

.. deprecated:: since QGIS 3.4 use toMapCoordinates instead
%End

void setMapUnitsPerPixel( double mapUnitsPerPixel );
%Docstring
@@ -350,10 +350,10 @@ QPolygonF QgsMapSettings::visiblePolygon() const
const QSize &sz = outputSize();
const QgsMapToPixel &m2p = mapToPixel();

poly << m2p.toMapCoordinatesF( 0, 0 ).toQPointF();
poly << m2p.toMapCoordinatesF( sz.width(), 0 ).toQPointF();
poly << m2p.toMapCoordinatesF( sz.width(), sz.height() ).toQPointF();
poly << m2p.toMapCoordinatesF( 0, sz.height() ).toQPointF();
poly << m2p.toMapCoordinates( 0.0, 0.0 ).toQPointF();
poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), 0.0 ).toQPointF();
poly << m2p.toMapCoordinates( static_cast<double>( sz.width() ), static_cast<double>( sz.height() ) ).toQPointF();
poly << m2p.toMapCoordinates( 0.0, static_cast<double>( sz.height() ) ).toQPointF();

return poly;
}
@@ -88,32 +88,31 @@ bool QgsMapToPixel::updateMatrix()
return true;
}

QgsPointXY QgsMapToPixel::toMapPoint( double x, double y ) const
QgsPointXY QgsMapToPixel::toMapCoordinates( double x, double y ) const
{
bool invertible;
QTransform matrix = mMatrix.inverted( &invertible );
assert( invertible );
qreal mx, my;
qreal x_qreal = x, y_qreal = y;
matrix.map( x_qreal, y_qreal, &mx, &my );
//QgsDebugMsg(QString("XXX toMapPoint x:%1 y:%2 -> x:%3 y:%4").arg(x).arg(y).arg(mx).arg(my));
return QgsPointXY( mx, my );
}

QgsPointXY QgsMapToPixel::toMapCoordinates( QPoint p ) const
{
QgsPointXY mapPt = toMapPoint( p.x(), p.y() );
QgsPointXY mapPt = toMapCoordinates( static_cast<double>( p.x() ), static_cast<double>( p.y() ) );
return QgsPointXY( mapPt );
}

QgsPointXY QgsMapToPixel::toMapCoordinates( int x, int y ) const
{
return toMapPoint( x, y );
return toMapCoordinates( static_cast<double>( x ), static_cast<double>( y ) );
}

QgsPointXY QgsMapToPixel::toMapCoordinatesF( double x, double y ) const
QgsPointXY QgsMapToPixel::toMapPoint( double x, double y ) const
{
return toMapPoint( x, y );
return toMapCoordinates( x, y );
}

void QgsMapToPixel::setMapUnitsPerPixel( double mapUnitsPerPixel )
@@ -117,10 +117,11 @@ class CORE_EXPORT QgsMapToPixel
}
#endif

//! Transform device coordinates to map (world) coordinates
QgsPointXY toMapCoordinates( int x, int y ) const;

//! Transform device coordinates to map (world) coordinates
QgsPointXY toMapCoordinatesF( double x, double y ) const;
QgsPointXY toMapCoordinates( double x, double y ) const SIP_PYNAME( toMapCoordinatesF );

/**
* Transform device coordinates to map (world) coordinates
@@ -129,7 +130,11 @@ class CORE_EXPORT QgsMapToPixel
*/
QgsPointXY toMapCoordinates( QPoint p ) const;

QgsPointXY toMapPoint( double x, double y ) const;
/**
* Transform device coordinates to map (world) coordinates
* \deprecated since QGIS 3.4 use toMapCoordinates instead
*/
Q_DECL_DEPRECATED QgsPointXY toMapPoint( double x, double y ) const;

/**
* Set map units per pixel
@@ -188,10 +188,10 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
mRasterViewPort->mBottomRightPoint.setY( std::ceil( mRasterViewPort->mBottomRightPoint.y() ) );
// recalc myRasterExtent to aligned values
myRasterExtent.set(
mapToPixel.toMapCoordinatesF( mRasterViewPort->mTopLeftPoint.x(),
mRasterViewPort->mBottomRightPoint.y() ),
mapToPixel.toMapCoordinatesF( mRasterViewPort->mBottomRightPoint.x(),
mRasterViewPort->mTopLeftPoint.y() )
mapToPixel.toMapCoordinates( mRasterViewPort->mTopLeftPoint.x(),
mRasterViewPort->mBottomRightPoint.y() ),
mapToPixel.toMapCoordinates( mRasterViewPort->mBottomRightPoint.x(),
mRasterViewPort->mTopLeftPoint.y() )
);

//raster viewport top left / bottom right are already rounded to int
@@ -121,7 +121,7 @@ QgsPoint QgsQuickMapSettings::screenToCoordinate( const QPointF &point ) const
// use floating point precision with mapToCoordinatesF
// this is to avoid rounding errors with an odd screen width or height
// and the point being set to the exact center of it
const QgsPointXY pp = mMapSettings.mapToPixel().toMapCoordinatesF( point.x(), point.y() );
const QgsPointXY pp = mMapSettings.mapToPixel().toMapCoordinates( point.x(), point.y() );
return QgsPoint( pp );
}

0 comments on commit 73c02fe

Please sign in to comment.
You can’t perform that action at this time.