|
17 | 17 |
|
18 | 18 | #include "qgsmapcanvasitem.h"
|
19 | 19 | #include "qgsmapcanvas.h"
|
| 20 | +#include "qgsmaprenderer.h" |
20 | 21 | #include "qgsmaptopixel.h"
|
| 22 | +#include "qgsrendercontext.h" |
21 | 23 | #include <QGraphicsScene>
|
22 | 24 | #include <QRect>
|
23 | 25 | #include <QPen>
|
@@ -101,6 +103,44 @@ void QgsMapCanvasItem::updateCanvas()
|
101 | 103 | //mMapCanvas->scene()->update(); //Contents();
|
102 | 104 | }
|
103 | 105 |
|
| 106 | +bool QgsMapCanvasItem::setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const |
| 107 | +{ |
| 108 | + if ( !mMapCanvas || !p ) |
| 109 | + { |
| 110 | + return false; |
| 111 | + } |
| 112 | + QgsMapRenderer* mapRenderer = mMapCanvas->mapRenderer(); |
| 113 | + if ( !mapRenderer ) |
| 114 | + { |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
| 118 | + context.setPainter( p ); |
| 119 | + context.setRendererScale( mMapCanvas->scale() ); |
| 120 | + |
| 121 | + int dpi = mapRenderer->outputDpi(); |
| 122 | + int painterDpi = p->device()->logicalDpiX(); |
| 123 | + double scaleFactor = 1.0; |
| 124 | + double rasterScaleFactor = 1.0; |
| 125 | + |
| 126 | + //little trick to find out if painting origines from composer or main map canvas |
| 127 | + if ( data( 0 ).toString() == "composer" ) |
| 128 | + { |
| 129 | + rasterScaleFactor = painterDpi / 25.4; |
| 130 | + scaleFactor = dpi / 25.4; |
| 131 | + } |
| 132 | + else |
| 133 | + { |
| 134 | + if ( mapRenderer->outputUnits() == QgsMapRenderer::Millimeters ) |
| 135 | + { |
| 136 | + scaleFactor = dpi / 25.4; |
| 137 | + } |
| 138 | + } |
| 139 | + context.setScaleFactor( scaleFactor ); |
| 140 | + context.setRasterScaleFactor( rasterScaleFactor ); |
| 141 | + return true; |
| 142 | +} |
| 143 | + |
104 | 144 | void QgsMapCanvasItem::updatePosition()
|
105 | 145 | {
|
106 | 146 | // default implementation: recalculate position of the item
|
|
0 commit comments