@@ -1432,21 +1432,45 @@ void QgsComposerMap::drawGrid( QPainter* p )
1432
1432
QRectF thisPaintRect = QRectF ( 0 , 0 , QGraphicsRectItem::rect ().width (), QGraphicsRectItem::rect ().height () );
1433
1433
p->setClipRect ( thisPaintRect );
1434
1434
1435
+ QPaintDevice* thePaintDevice = p->device ();
1436
+ if ( !thePaintDevice )
1437
+ {
1438
+ return ;
1439
+ }
1440
+
1435
1441
// set the blend mode for drawing grid lines
1436
1442
p->save ();
1437
1443
p->setCompositionMode ( mGridBlendMode );
1444
+ p->setRenderHint ( QPainter::Antialiasing );
1445
+
1446
+ // setup painter scaling to dots so that raster symbology is drawn to scale
1447
+ double dotsPerMM = thePaintDevice->logicalDpiX () / 25.4 ;
1448
+ p->scale ( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
1449
+
1450
+ // setup render context
1451
+ QgsMapSettings ms = mComposition ->mapSettings ();
1452
+ // context units should be in dots
1453
+ ms.setOutputSize ( QSizeF ( rect ().width () * dotsPerMM, rect ().height () * dotsPerMM ).toSize () );
1454
+ ms.setExtent ( *currentMapExtent () );
1455
+ ms.setOutputDpi ( p->device ()->logicalDpiX () );
1456
+ QgsRenderContext context = QgsRenderContext::fromMapSettings ( ms );
1457
+ context.setPainter ( p );
1438
1458
1439
1459
// simpler approach: draw vertical lines first, then horizontal ones
1440
1460
if ( mGridStyle == QgsComposerMap::Solid )
1441
1461
{
1462
+ // need to scale line to dots, rather then mm, since the painter has been scaled to dots
1463
+ QLineF line;
1442
1464
for ( ; vIt != verticalLines.constEnd (); ++vIt )
1443
1465
{
1444
- drawGridLine ( vIt->second , p );
1466
+ line = QLineF ( vIt->second .p1 () * dotsPerMM, vIt->second .p2 () * dotsPerMM ) ;
1467
+ drawGridLine ( line, context );
1445
1468
}
1446
1469
1447
1470
for ( ; hIt != horizontalLines.constEnd (); ++hIt )
1448
1471
{
1449
- drawGridLine ( hIt->second , p );
1472
+ line = QLineF ( hIt->second .p1 () * dotsPerMM, hIt->second .p2 () * dotsPerMM ) ;
1473
+ drawGridLine ( line, context );
1450
1474
}
1451
1475
}
1452
1476
else // cross
@@ -1456,7 +1480,7 @@ void QgsComposerMap::drawGrid( QPainter* p )
1456
1480
{
1457
1481
// start mark
1458
1482
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( vIt->second .p1 (), vIt->second .p2 (), mCrossLength );
1459
- drawGridLine ( QLineF ( vIt->second .p1 (), crossEnd1 ), p );
1483
+ drawGridLine ( QLineF ( vIt->second .p1 (), crossEnd1 ), context );
1460
1484
1461
1485
// test for intersection with every horizontal line
1462
1486
hIt = horizontalLines.constBegin ();
@@ -1466,20 +1490,20 @@ void QgsComposerMap::drawGrid( QPainter* p )
1466
1490
{
1467
1491
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( intersectionPoint, vIt->second .p1 (), mCrossLength );
1468
1492
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( intersectionPoint, vIt->second .p2 (), mCrossLength );
1469
- drawGridLine ( QLineF ( crossEnd1, crossEnd2 ), p );
1493
+ drawGridLine ( QLineF ( crossEnd1, crossEnd2 ), context );
1470
1494
}
1471
1495
}
1472
1496
// end mark
1473
1497
QPointF crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( vIt->second .p2 (), vIt->second .p1 (), mCrossLength );
1474
- drawGridLine ( QLineF ( vIt->second .p2 (), crossEnd2 ), p );
1498
+ drawGridLine ( QLineF ( vIt->second .p2 (), crossEnd2 ), context );
1475
1499
}
1476
1500
1477
1501
hIt = horizontalLines.constBegin ();
1478
1502
for ( ; hIt != horizontalLines.constEnd (); ++hIt )
1479
1503
{
1480
1504
// start mark
1481
1505
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( hIt->second .p1 (), hIt->second .p2 (), mCrossLength );
1482
- drawGridLine ( QLineF ( hIt->second .p1 (), crossEnd1 ), p );
1506
+ drawGridLine ( QLineF ( hIt->second .p1 (), crossEnd1 ), context );
1483
1507
1484
1508
vIt = verticalLines.constBegin ();
1485
1509
for ( ; vIt != verticalLines.constEnd (); ++vIt )
@@ -1488,12 +1512,12 @@ void QgsComposerMap::drawGrid( QPainter* p )
1488
1512
{
1489
1513
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( intersectionPoint, hIt->second .p1 (), mCrossLength );
1490
1514
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( intersectionPoint, hIt->second .p2 (), mCrossLength );
1491
- drawGridLine ( QLineF ( crossEnd1, crossEnd2 ), p );
1515
+ drawGridLine ( QLineF ( crossEnd1, crossEnd2 ), context );
1492
1516
}
1493
1517
}
1494
1518
// end mark
1495
1519
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance ( hIt->second .p2 (), hIt->second .p1 (), mCrossLength );
1496
- drawGridLine ( QLineF ( hIt->second .p2 (), crossEnd1 ), p );
1520
+ drawGridLine ( QLineF ( hIt->second .p2 (), crossEnd1 ), context );
1497
1521
}
1498
1522
}
1499
1523
// reset composition mode
@@ -1529,25 +1553,16 @@ void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLi
1529
1553
drawGridFrameBorder ( p, bottomGridFrame, QgsComposerMap::Bottom );
1530
1554
}
1531
1555
1532
- void QgsComposerMap::drawGridLine ( const QLineF& line, QPainter* p )
1556
+ void QgsComposerMap::drawGridLine ( const QLineF& line, QgsRenderContext& context )
1533
1557
{
1534
- if ( !mGridLineSymbol || !p )
1558
+ if ( !mGridLineSymbol )
1535
1559
{
1536
1560
return ;
1537
1561
}
1538
-
1539
- // setup render context
1540
- QgsRenderContext context;
1541
- context.setPainter ( p );
1542
1562
if ( mPreviewMode == Rectangle )
1543
1563
{
1544
1564
return ;
1545
1565
}
1546
- else
1547
- {
1548
- context.setScaleFactor ( 1.0 );
1549
- context.setRasterScaleFactor ( mComposition ->printResolution () / 25.4 );
1550
- }
1551
1566
1552
1567
QPolygonF poly;
1553
1568
poly << line.p1 () << line.p2 ();
@@ -2556,22 +2571,33 @@ void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
2556
2571
QgsRectangle thisExtent = *currentMapExtent ();
2557
2572
QgsRectangle intersectRect = thisExtent.intersect ( &otherExtent );
2558
2573
2559
- QgsRenderContext context;
2574
+ // setup painter scaling to dots so that raster symbology is drawn to scale
2575
+ double dotsPerMM = p->device ()->logicalDpiX () / 25.4 ;
2576
+
2577
+ // setup render context
2578
+ QgsMapSettings ms = mComposition ->mapSettings ();
2579
+ // context units should be in dots
2580
+ ms.setOutputSize ( QSizeF ( rect ().width () * dotsPerMM, rect ().height () * dotsPerMM ).toSize () );
2581
+ ms.setExtent ( *currentMapExtent () );
2582
+ ms.setOutputDpi ( p->device ()->logicalDpiX () );
2583
+ QgsRenderContext context = QgsRenderContext::fromMapSettings ( ms );
2560
2584
context.setPainter ( p );
2561
- context.setScaleFactor ( 1.0 );
2562
- context.setRasterScaleFactor ( mComposition ->printResolution () / 25.4 );
2563
2585
2564
2586
p->save ();
2565
2587
p->setCompositionMode ( mOverviewBlendMode );
2566
2588
p->translate ( mXOffset , mYOffset );
2589
+ p->scale ( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
2590
+ p->setRenderHint ( QPainter::Antialiasing );
2591
+
2567
2592
mOverviewFrameMapSymbol ->startRender ( context );
2568
2593
2569
2594
// construct a polygon corresponding to the intersecting map extent
2595
+ // need to scale line to dots, rather then mm, since the painter has been scaled to dots
2570
2596
QPolygonF intersectPolygon;
2571
- double x = ( intersectRect.xMinimum () - thisExtent.xMinimum () ) / thisExtent.width () * rect ().width ();
2572
- double y = ( thisExtent.yMaximum () - intersectRect.yMaximum () ) / thisExtent.height () * rect ().height ();
2573
- double width = intersectRect.width () / thisExtent.width () * rect ().width ();
2574
- double height = intersectRect.height () / thisExtent.height () * rect ().height ();
2597
+ double x = dotsPerMM * ( intersectRect.xMinimum () - thisExtent.xMinimum () ) / thisExtent.width () * rect ().width ();
2598
+ double y = dotsPerMM * ( thisExtent.yMaximum () - intersectRect.yMaximum () ) / thisExtent.height () * rect ().height ();
2599
+ double width = dotsPerMM * intersectRect.width () / thisExtent.width () * rect ().width ();
2600
+ double height = dotsPerMM * intersectRect.height () / thisExtent.height () * rect ().height ();
2575
2601
intersectPolygon << QPointF ( x, y ) << QPointF ( x + width, y ) << QPointF ( x + width, y + height ) << QPointF ( x, y + height ) << QPointF ( x, y );
2576
2602
2577
2603
QList<QPolygonF> rings; // empty list
0 commit comments