void QgsMapToPixel::updateMatrix() { double rotation = mapRotation(); #if 0 // debugging QgsDebugMsg( QString( "XXX %7 -- xCent:%1 yCent:%2 mWidth:%3 mHeight:%4 uPP:%5 rot:%6" ) .arg( xCenter ).arg( yCenter ).arg( mWidth ).arg( mHeight ) .arg( mMapUnitsPerPixel ).arg( rotation ).arg(( quintptr )this, QT_POINTER_SIZE *2, 15, QChar( '0' ) ) ); #endif // NOTE: operations are done in the reverse order in which // they are configured, so translation to geographical // center happens first, then scaling, then rotation // and finally translation to output viewport center if ( qgsDoubleNear( rotation, 0.0 ) ) { //no rotation, return a simplified matrix mMatrix = QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel ) .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) ); return; } double cy = mapHeight() / 2.0; double cx = mapWidth() / 2.0; mMatrix = QTransform::fromTranslate( cx, cy ) .rotate( rotation ) .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel ) .translate( -xCenter, -yCenter ) ; }
QTransform QgsMapToPixel::transform() const { // NOTE: operations are done in the reverse order in which // they are configured, so translation to geographical // center happens first, then scaling, then rotation // and finally translation to output viewport center double rotation = mapRotation(); if ( qgsDoubleNear( rotation, 0.0 ) ) { //no rotation, return a simplified matrix return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel ) .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) ); } else { double cy = mapHeight() / 2.0; double cx = mapWidth() / 2.0; return QTransform::fromTranslate( cx, cy ) .rotate( rotation ) .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel ) .translate( -xCenter, -yCenter ); } }