Skip to content

Commit

Permalink
Turn antialising render flag on when appropriate in QgsRenderContext:…
Browse files Browse the repository at this point in the history
…:fromQPainter()
  • Loading branch information
nirvn committed Apr 24, 2019
1 parent 50692fc commit 6df8ed2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ QgsRenderContext QgsRenderContext::fromQPainter( QPainter *painter )
{
context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
}
if ( painter && painter->renderHints() & QPainter::Antialiasing )
{
context.setFlag( QgsRenderContext::Antialiasing, true );
}
return context;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgsrendercontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ def testFromQPainter(self):
p = QPainter()
c = QgsRenderContext.fromQPainter(p)
self.assertEqual(c.painter(), p)
self.assertEqual(c.testFlag(QgsRenderContext.Antialiasing), False)
self.assertAlmostEqual(c.scaleFactor(), 88 / 25.4, 3)

im = QImage(1000, 600, QImage.Format_RGB32)
dots_per_m = 300 / 25.4 * 1000 # 300 dpi to dots per m
im.setDotsPerMeterX(dots_per_m)
im.setDotsPerMeterY(dots_per_m)
p = QPainter(im)
p.setRenderHint(QPainter.Antialiasing)
c = QgsRenderContext.fromQPainter(p)
self.assertEqual(c.painter(), p)
self.assertEqual(c.testFlag(QgsRenderContext.Antialiasing), True)
self.assertAlmostEqual(c.scaleFactor(), dots_per_m / 1000, 3) # scaleFactor should be pixels/mm

def testFromMapSettings(self):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6df8ed2

Please sign in to comment.