31 , mRotation( rotation )
34 , mXMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
35 , mYMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
54 const double metersPerPixel = 25.4 / dpi / 1000.0;
64bool QgsMapToPixel::updateMatrix()
69 if ( !newMatrix.isInvertible() )
80 const double oldUnits = mMapUnitsPerPixel;
82 if ( !updateMatrix() )
84 mMapUnitsPerPixel = oldUnits;
92 const double oldRotation = mRotation;
93 const double oldXCenter = mXCenter;
94 const double oldYCenter = mYCenter;
95 const double oldWidth = mWidth;
103 mWidth = ( ( mXCenter - mXMin ) * 2 ) / mMapUnitsPerPixel;
106 if ( !updateMatrix() )
108 mRotation = oldRotation;
109 mXCenter = oldXCenter;
110 mYCenter = oldYCenter;
119 const double oldMUPP = mMapUnitsPerPixel;
120 const double oldXCenter = mXCenter;
121 const double oldYCenter = mYCenter;
122 const double oldWidth = mWidth;
123 const double oldHeight = mHeight;
124 const double oldRotation = mRotation;
125 const double oldXMin = mXMin;
126 const double oldYMin = mYMin;
133 mRotation = rotation;
134 mXMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
135 mYMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
137 if ( !updateMatrix() )
139 mMapUnitsPerPixel = oldMUPP;
140 mXCenter = oldXCenter;
141 mYCenter = oldYCenter;
144 mRotation = oldRotation;
165 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel <<
" center: " << mXCenter <<
',' << mYCenter <<
" rotation: " << mRotation <<
" size: " << mWidth <<
'x' << mHeight;
180 return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel ).translate( -mXMin, -( mYMin + mHeight * mMapUnitsPerPixel ) );
186 return QTransform::fromTranslate( cx, cy ).rotate( rotation ).scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel ).translate( -mXCenter, -mYCenter );
DistanceUnit
Units of distance.
int mapHeight() const
Returns current map height in pixels.
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Sets the map units per pixel.
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
QgsMapToPixel()
Constructor for an invalid QgsMapToPixel.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
static QgsMapToPixel fromScale(double scale, Qgis::DistanceUnit mapUnits, double dpi=96)
Returns a new QgsMapToPixel created using a specified scale and distance unit.
QTransform transform() const
Returns a QTransform encapsulating the map to pixel conversion.
int mapWidth() const
Returns the current map width in pixels.
double mapRotation() const
Returns the current map rotation in degrees (clockwise).
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Sets parameters for use in transforming coordinates.
QString showParameters() const
Returns a string representation of the parameters used in the transform.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).