20 #include <QTextStream> 33 : mMapUnitsPerPixel( mapUnitsPerPixel )
36 , mRotation( rotation )
39 , xMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
40 , yMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
42 Q_ASSERT( mapUnitsPerPixel > 0 );
47 : mMapUnitsPerPixel( 1 )
63 : mMapUnitsPerPixel( mapUnitsPerPixel )
89 void QgsMapToPixel::updateMatrix()
94 QgsDebugMsg( QString(
"XXX %7 -- xCent:%1 yCent:%2 mWidth:%3 mHeight:%4 uPP:%5 rot:%6" )
95 .arg( xCenter ).arg( yCenter ).arg( mWidth ).arg( mHeight )
96 .arg( mMapUnitsPerPixel ).arg( rotation ).arg(( quintptr )
this, QT_POINTER_SIZE *2, 15, QChar(
'0' ) ) );
107 mMatrix = QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
108 .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
114 mMatrix = QTransform::fromTranslate( cx, cy )
116 .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
117 .translate( -xCenter, -yCenter );
123 QTransform matrix = mMatrix.inverted( &invertible );
124 assert( invertible );
126 matrix.map( x, y, &mx, &my );
155 return mMapUnitsPerPixel;
166 mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
179 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
187 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
199 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
200 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
217 mRotation = rotation;
218 xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
219 yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
226 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
227 <<
" center: " << xCenter <<
"," << yCenter
228 <<
" rotation: " << mRotation
229 <<
" size: " << mWidth <<
"x" << mHeight;
241 qreal x = p.
x(), y = p.
y();
249 qreal x = p->
x(), y = p->
y();
259 mMatrix.map( x, y, &mx, &my );
int mapWidth() const
Return current map width in pixels The information is only known if setRotation was used...
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
void transformInPlace(qreal &x, qreal &y) const
QgsPoint transform(const QgsPoint &p) const
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
double mapRotation() const
Return current map rotation in degrees.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Q_DECL_DEPRECATED void setXMinimum(double xmin)
set minimum x value
QString showParameters() const
String representation of the parameters used in the transform.
double mapUnitsPerPixel() const
Return current map units per pixel.
void set(double x, double y)
A class to represent a point.
QgsPoint toMapCoordinatesF(double x, double y) const
QgsPoint toMapCoordinates(int x, int y) const
int mapHeight() const
Return current map height in pixels.
void setMapUnitsPerPixel(double mapUnitsPerPixel)
~QgsMapToPixel()
destructor
QgsPoint toMapPoint(qreal x, qreal y) const
Q_DECL_DEPRECATED void setYMinimum(double ymin)
Set minimum y value.