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 )
102 bool QgsMapToPixel::updateMatrix()
118 assert( invertible );
120 matrix.
map( x, y, &mx, &my );
143 double oldUnits = mMapUnitsPerPixel;
145 if ( !updateMatrix() )
147 mMapUnitsPerPixel = oldUnits;
153 return mMapUnitsPerPixel;
158 double oldRotation = mRotation;
159 double oldXCenter = xCenter;
160 double oldYCenter = yCenter;
161 double oldWidth = mWidth;
169 mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
172 if ( !updateMatrix() )
174 mRotation = oldRotation;
175 xCenter = oldXCenter;
176 yCenter = oldYCenter;
189 double oldRotation = mRotation;
190 double oldYCenter = yCenter;
192 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
194 if ( !updateMatrix() )
196 mRotation = oldRotation;
197 yCenter = oldYCenter;
204 double oldRotation = mRotation;
205 double oldXCenter = xCenter;
207 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
210 if ( !updateMatrix() )
212 mRotation = oldRotation;
213 xCenter = oldXCenter;
220 double oldMUPP = mMapUnitsPerPixel;
221 double oldXMin = xMin;
222 double oldYMin = yMin;
223 double oldHeight = mHeight;
224 double oldXCenter = xCenter;
225 double oldYCenter = yCenter;
226 double oldRotation = mRotation;
232 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
233 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
236 if ( !updateMatrix() )
238 mMapUnitsPerPixel = oldMUPP;
242 xCenter = oldXCenter;
243 yCenter = oldYCenter;
244 mRotation = oldRotation;
255 double oldMUPP = mMapUnitsPerPixel;
256 double oldXCenter = xCenter;
257 double oldYCenter = yCenter;
258 double oldWidth = mWidth;
259 double oldHeight = mHeight;
260 double oldRotation = mRotation;
261 double oldXMin = xMin;
262 double oldYMin = yMin;
269 mRotation = rotation;
270 xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
271 yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
273 if ( !updateMatrix() )
275 mMapUnitsPerPixel = oldMUPP;
276 xCenter = oldXCenter;
277 yCenter = oldYCenter;
280 mRotation = oldRotation;
289 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
290 <<
" center: " << xCenter <<
"," << yCenter
291 <<
" rotation: " << mRotation
292 <<
" size: " << mWidth <<
"x" << mHeight;
304 qreal x = p.
x(), y = p.
y();
312 qreal x = p->
x(), y = p->
y();
322 mMatrix.
map( x, y, &mx, &my );
339 .
translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
347 .
scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
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
Transform device coordinates to map (world) coordinates.
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
Set parameters for use in transforming coordinates.
double mapRotation() const
Return current map rotation in degrees.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
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)
A class to represent a point.
QgsPoint toMapCoordinatesF(double x, double y) const
Transform device coordinates to map (world) coordinates.
QgsPoint toMapCoordinates(int x, int y) const
int mapHeight() const
Return current map height in pixels.
QTransform transform() const
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
~QgsMapToPixel()
destructor
QgsPoint toMapPoint(qreal x, qreal y) const
Q_DECL_DEPRECATED void setYMinimum(double ymin)
Set minimum y value.