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 qreal x_qreal = x, y_qreal = y;
121 matrix.
map( x_qreal, y_qreal, &mx, &my );
144 double oldUnits = mMapUnitsPerPixel;
146 if ( !updateMatrix() )
148 mMapUnitsPerPixel = oldUnits;
154 return mMapUnitsPerPixel;
159 double oldRotation = mRotation;
160 double oldXCenter = xCenter;
161 double oldYCenter = yCenter;
162 double oldWidth = mWidth;
170 mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
173 if ( !updateMatrix() )
175 mRotation = oldRotation;
176 xCenter = oldXCenter;
177 yCenter = oldYCenter;
190 double oldRotation = mRotation;
191 double oldYCenter = yCenter;
193 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
195 if ( !updateMatrix() )
197 mRotation = oldRotation;
198 yCenter = oldYCenter;
205 double oldRotation = mRotation;
206 double oldXCenter = xCenter;
208 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
211 if ( !updateMatrix() )
213 mRotation = oldRotation;
214 xCenter = oldXCenter;
221 double oldMUPP = mMapUnitsPerPixel;
222 double oldXMin = xMin;
223 double oldYMin = yMin;
224 double oldHeight = mHeight;
225 double oldXCenter = xCenter;
226 double oldYCenter = yCenter;
227 double oldRotation = mRotation;
233 xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
234 yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
237 if ( !updateMatrix() )
239 mMapUnitsPerPixel = oldMUPP;
243 xCenter = oldXCenter;
244 yCenter = oldYCenter;
245 mRotation = oldRotation;
256 double oldMUPP = mMapUnitsPerPixel;
257 double oldXCenter = xCenter;
258 double oldYCenter = yCenter;
259 double oldWidth = mWidth;
260 double oldHeight = mHeight;
261 double oldRotation = mRotation;
262 double oldXMin = xMin;
263 double oldYMin = yMin;
270 mRotation = rotation;
271 xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
272 yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
274 if ( !updateMatrix() )
276 mMapUnitsPerPixel = oldMUPP;
277 xCenter = oldXCenter;
278 yCenter = oldYCenter;
281 mRotation = oldRotation;
290 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
291 <<
" center: " << xCenter <<
"," << yCenter
292 <<
" rotation: " << mRotation
293 <<
" size: " << mWidth <<
"x" << mHeight;
305 qreal x = p.
x(), y = p.
y();
313 qreal x = p->
x(), y = p->
y();
323 qreal x_qreal = x, y_qreal = y;
324 mMatrix.
map( x_qreal, y_qreal, &mx, &my );
331 double mx = x, my = y;
348 .
translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
356 .
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)
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)
double x() const
Get the x value of the point.
void transformInPlace(double &x, double &y) const
Transform device coordinates to map (world) coordinates.
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.
QgsPoint toMapCoordinates(int x, int y) const
int mapHeight() const
Return current map height in pixels.
double y() const
Get the y value of the point.
QTransform transform() const
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
~QgsMapToPixel()
destructor
QgsPoint toMapPoint(double x, double y) const
Q_DECL_DEPRECATED void setYMinimum(double ymin)
Set minimum y value.