20 #include <QTextStream> 32 : mMapUnitsPerPixel( mapUnitsPerPixel )
35 , mRotation( rotation )
38 , xMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
39 , yMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
41 Q_ASSERT( mapUnitsPerPixel > 0 );
46 : mMapUnitsPerPixel( mapUnitsPerPixel )
59 : mMapUnitsPerPixel( 1 )
76 : mMapUnitsPerPixel( mapUnitsPerPixel )
98 bool QgsMapToPixel::updateMatrix()
114 assert( invertible );
116 qreal x_qreal = x, y_qreal = y;
117 matrix.
map( x_qreal, y_qreal, &mx, &my );
140 double oldUnits = mMapUnitsPerPixel;
142 if ( !updateMatrix() )
144 mMapUnitsPerPixel = oldUnits;
150 return mMapUnitsPerPixel;
155 double oldRotation = mRotation;
156 double oldXCenter = xCenter;
157 double oldYCenter = yCenter;
158 double oldWidth = mWidth;
166 mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
169 if ( !updateMatrix() )
171 mRotation = oldRotation;
172 xCenter = oldXCenter;
173 yCenter = oldYCenter;
186 double oldRotation = mRotation;
187 double oldYCenter = yCenter;
189 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
191 if ( !updateMatrix() )
193 mRotation = oldRotation;
194 yCenter = oldYCenter;
201 double oldRotation = mRotation;
202 double oldXCenter = xCenter;
204 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
207 if ( !updateMatrix() )
209 mRotation = oldRotation;
210 xCenter = oldXCenter;
217 double oldMUPP = mMapUnitsPerPixel;
218 double oldXMin = xMin;
219 double oldYMin = yMin;
220 double oldHeight = mHeight;
221 double oldXCenter = xCenter;
222 double oldYCenter = yCenter;
223 double oldRotation = mRotation;
229 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
230 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
233 if ( !updateMatrix() )
235 mMapUnitsPerPixel = oldMUPP;
239 xCenter = oldXCenter;
240 yCenter = oldYCenter;
241 mRotation = oldRotation;
252 double oldMUPP = mMapUnitsPerPixel;
253 double oldXCenter = xCenter;
254 double oldYCenter = yCenter;
255 double oldWidth = mWidth;
256 double oldHeight = mHeight;
257 double oldRotation = mRotation;
258 double oldXMin = xMin;
259 double oldYMin = yMin;
266 mRotation = rotation;
267 xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
268 yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
270 if ( !updateMatrix() )
272 mMapUnitsPerPixel = oldMUPP;
273 xCenter = oldXCenter;
274 yCenter = oldYCenter;
277 mRotation = oldRotation;
286 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
287 <<
" center: " << xCenter <<
',' << yCenter
288 <<
" rotation: " << mRotation
289 <<
" size: " << mWidth <<
'x' << mHeight;
301 qreal x = p.
x(), y = p.
y();
309 qreal x = p->
x(), y = p->
y();
319 qreal x_qreal = x, y_qreal = y;
320 mMatrix.
map( x_qreal, y_qreal, &mx, &my );
328 double mx = x, my = y;
346 .
translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
354 .
scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
QgsPoint toMapPoint(double x, double y) const
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
Set parameters for use in transforming coordinates.
QgsPoint toMapCoordinates(int x, int y) const
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double y() const
Get the y value of the point.
double mapRotation() const
Return current map rotation in degrees.
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
int mapWidth() const
Return current map width in pixels The information is only known if setRotation was used...
int mapHeight() const
Return current map height in pixels.
QgsMapToPixel()
Constructor.
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)
Sets the x and y value of the point.
A class to represent a point.
QgsPoint toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
QTransform transform() const
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
double x() const
Get the x value of the point.
Q_DECL_DEPRECATED void setYMinimum(double ymin)
Set minimum y value.