@@ -204,6 +204,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, const QS
204
204
jobMapSettings.setMapUnits ( ms.mapUnits () );
205
205
jobMapSettings.setBackgroundColor ( Qt::transparent );
206
206
jobMapSettings.setOutputImageFormat ( ms.outputImageFormat () );
207
+ jobMapSettings.setRotation ( mEvaluatedMapRotation );
207
208
208
209
// set layers to render
209
210
QStringList theLayerSet = layersToRender ();
@@ -255,19 +256,16 @@ void QgsComposerMap::cache( void )
255
256
256
257
mDrawing = true ;
257
258
258
- // in case of rotation, we need to request a larger rectangle and create a larger cache image
259
- QgsRectangle requestExtent;
260
- requestedExtent ( requestExtent );
261
-
262
259
double horizontalVScaleFactor = horizontalViewScaleFactor ();
263
260
if ( horizontalVScaleFactor < 0 )
264
261
{
265
262
// make sure scale factor is positive
266
263
horizontalVScaleFactor = mLastValidViewScaleFactor > 0 ? mLastValidViewScaleFactor : 1 ;
267
264
}
268
265
269
- double widthMM = requestExtent.width () * mapUnitsToMM ();
270
- double heightMM = requestExtent.height () * mapUnitsToMM ();
266
+ const QgsRectangle &ext = *currentMapExtent ();
267
+ double widthMM = ext.width () * mapUnitsToMM ();
268
+ double heightMM = ext.height () * mapUnitsToMM ();
271
269
272
270
int w = widthMM * horizontalVScaleFactor;
273
271
int h = heightMM * horizontalVScaleFactor;
@@ -302,7 +300,7 @@ void QgsComposerMap::cache( void )
302
300
303
301
QPainter p ( &mCacheImage );
304
302
305
- draw ( &p, requestExtent , QSizeF ( w, h ), mCacheImage .logicalDpiX () );
303
+ draw ( &p, ext , QSizeF ( w, h ), mCacheImage .logicalDpiX () );
306
304
p.end ();
307
305
mCacheUpdated = true ;
308
306
@@ -344,29 +342,12 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
344
342
345
343
// Background color is already included in cached image, so no need to draw
346
344
347
- QgsRectangle requestRectangle;
348
- requestedExtent ( requestRectangle );
349
-
350
- QgsRectangle cExtent = *currentMapExtent ();
351
-
352
- double imagePixelWidth = cExtent.width () / requestRectangle.width () * mCacheImage .width () ; // how many pixels of the image are for the map extent?
345
+ double imagePixelWidth = mCacheImage .width (); // how many pixels of the image are for the map extent?
353
346
double scale = rect ().width () / imagePixelWidth;
354
- QgsPoint rotationPoint = QgsPoint (( cExtent.xMaximum () + cExtent.xMinimum () ) / 2.0 , ( cExtent.yMaximum () + cExtent.yMinimum () ) / 2.0 );
355
-
356
- // shift such that rotation point is at 0/0 point in the coordinate system
357
- double yShiftMM = ( requestRectangle.yMaximum () - rotationPoint.y () ) * mapUnitsToMM ();
358
- double xShiftMM = ( requestRectangle.xMinimum () - rotationPoint.x () ) * mapUnitsToMM ();
359
-
360
- // shift such that top left point of the extent at point 0/0 in item coordinate system
361
- double xTopLeftShift = ( rotationPoint.x () - cExtent.xMinimum () ) * mapUnitsToMM ();
362
- double yTopLeftShift = ( cExtent.yMaximum () - rotationPoint.y () ) * mapUnitsToMM ();
363
347
364
348
painter->save ();
365
349
366
350
painter->translate ( mXOffset , mYOffset );
367
- painter->translate ( xTopLeftShift, yTopLeftShift );
368
- painter->rotate ( mEvaluatedMapRotation );
369
- painter->translate ( xShiftMM, -yShiftMM );
370
351
painter->scale ( scale, scale );
371
352
painter->drawImage ( 0 , 0 , mCacheImage );
372
353
@@ -397,32 +378,17 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
397
378
drawBackground ( painter );
398
379
}
399
380
400
- QgsRectangle requestRectangle;
401
- requestedExtent ( requestRectangle );
402
-
403
381
QgsRectangle cExtent = *currentMapExtent ();
404
382
405
- QSizeF theSize ( requestRectangle.width () * mapUnitsToMM (), requestRectangle.height () * mapUnitsToMM () );
406
-
407
- QgsPoint rotationPoint = QgsPoint (( cExtent.xMaximum () + cExtent.xMinimum () ) / 2.0 , ( cExtent.yMaximum () + cExtent.yMinimum () ) / 2.0 );
408
-
409
- // shift such that rotation point is at 0/0 point in the coordinate system
410
- double yShiftMM = ( requestRectangle.yMaximum () - rotationPoint.y () ) * mapUnitsToMM ();
411
- double xShiftMM = ( requestRectangle.xMinimum () - rotationPoint.x () ) * mapUnitsToMM ();
383
+ QSizeF theSize ( cExtent.width () * mapUnitsToMM (), cExtent.height () * mapUnitsToMM () );
412
384
413
- // shift such that top left point of the extent at point 0/0 in item coordinate system
414
- double xTopLeftShift = ( rotationPoint.x () - cExtent.xMinimum () ) * mapUnitsToMM ();
415
- double yTopLeftShift = ( cExtent.yMaximum () - rotationPoint.y () ) * mapUnitsToMM ();
416
385
painter->save ();
417
386
painter->translate ( mXOffset , mYOffset );
418
- painter->translate ( xTopLeftShift, yTopLeftShift );
419
- painter->rotate ( mEvaluatedMapRotation );
420
- painter->translate ( xShiftMM, -yShiftMM );
421
387
422
388
double dotsPerMM = thePaintDevice->logicalDpiX () / 25.4 ;
423
389
theSize *= dotsPerMM; // output size will be in dots (pixels)
424
390
painter->scale ( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
425
- draw ( painter, requestRectangle , theSize, thePaintDevice->logicalDpiX () );
391
+ draw ( painter, cExtent , theSize, thePaintDevice->logicalDpiX () );
426
392
427
393
// restore rotation
428
394
painter->restore ();
0 commit comments