20 #include <QTextStream>
34 : mMapUnitsPerPixel( mapUnitsPerPixel )
37 , mRotation( rotation )
40 , xMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
41 , yMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
48 : mMapUnitsPerPixel( mapUnitsPerPixel )
59 double metersPerPixel = 25.4 / dpi / 1000.0;
79 bool QgsMapToPixel::updateMatrix()
84 if ( !newMatrix.isInvertible() )
94 QTransform matrix = mMatrix.inverted( &invertible );
97 qreal x_qreal = x, y_qreal = y;
98 matrix.map( x_qreal, y_qreal, &mx, &my );
110 return toMapCoordinates(
static_cast<double>( x ),
static_cast<double>( y ) );
120 double oldUnits = mMapUnitsPerPixel;
122 if ( !updateMatrix() )
124 mMapUnitsPerPixel = oldUnits;
130 return mMapUnitsPerPixel;
135 double oldRotation = mRotation;
136 double oldXCenter = mXCenter;
137 double oldYCenter = mYCenter;
138 double oldWidth = mWidth;
146 mWidth = ( ( mXCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
149 if ( !updateMatrix() )
151 mRotation = oldRotation;
152 mXCenter = oldXCenter;
153 mYCenter = oldYCenter;
170 double oldMUPP = mMapUnitsPerPixel;
171 double oldXCenter = mXCenter;
172 double oldYCenter = mYCenter;
173 double oldWidth = mWidth;
174 double oldHeight = mHeight;
175 double oldRotation = mRotation;
176 double oldXMin = xMin;
177 double oldYMin = yMin;
184 mRotation = rotation;
185 xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
186 yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
188 if ( !updateMatrix() )
190 mMapUnitsPerPixel = oldMUPP;
191 mXCenter = oldXCenter;
192 mYCenter = oldYCenter;
195 mRotation = oldRotation;
204 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
205 <<
" center: " << mXCenter <<
',' << mYCenter
206 <<
" rotation: " << mRotation
207 <<
" size: " << mWidth <<
'x' << mHeight;
219 qreal x = p.
x(), y = p.
y();
227 qreal x = p->
x(), y = p->
y();
237 qreal x_qreal = x, y_qreal = y;
238 mMatrix.map( x_qreal, y_qreal, &mx, &my );
246 double mx = x, my = y;
263 return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
264 .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
270 return QTransform::fromTranslate( cx, cy )
272 .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
273 .translate( -mXCenter, -mYCenter );