Skip to content

Commit 44c916f

Browse files
author
mhugent
committed
Move setRenderContext() method to mapcanvas item class
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13332 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 708dc7c commit 44c916f

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed

python/gui/qgsmapcanvasitem.sip

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class QgsMapCanvasItem : QGraphicsItem
2323
//! schedules map canvas for repaint
2424
void updateCanvas();
2525

26+
/**Sets render context parameters
27+
@param p painter for rendering
28+
@param context out: configured context
29+
@return true in case of success
30+
@note added in version 1.5*/
31+
bool setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const;
2632

2733
public:
2834

src/gui/qgsannotationitem.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "qgsannotationitem.h"
1919
#include "qgsmapcanvas.h"
20-
#include "qgsmaprenderer.h"
2120
#include "qgsrendercontext.h"
2221
#include "qgssymbollayerv2utils.h"
2322
#include "qgssymbolv2.h"
@@ -248,44 +247,6 @@ void QgsAnnotationItem::drawSelectionBoxes( QPainter* p )
248247
p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
249248
}
250249

251-
bool QgsAnnotationItem::setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const
252-
{
253-
if ( !mMapCanvas || !p )
254-
{
255-
return false;
256-
}
257-
QgsMapRenderer* mapRenderer = mMapCanvas->mapRenderer();
258-
if ( !mapRenderer )
259-
{
260-
return false;
261-
}
262-
263-
context.setPainter( p );
264-
context.setRendererScale( mMapCanvas->scale() );
265-
266-
int dpi = mapRenderer->outputDpi();
267-
int painterDpi = p->device()->logicalDpiX();
268-
double scaleFactor = 1.0;
269-
double rasterScaleFactor = 1.0;
270-
271-
//little trick to find out if painting origines from composer or main map canvas
272-
if ( data( 0 ).toString() == "composer" )
273-
{
274-
rasterScaleFactor = painterDpi / 25.4;
275-
scaleFactor = dpi / 25.4;
276-
}
277-
else
278-
{
279-
if ( mapRenderer->outputUnits() == QgsMapRenderer::Millimeters )
280-
{
281-
scaleFactor = dpi / 25.4;
282-
}
283-
}
284-
context.setScaleFactor( scaleFactor );
285-
context.setRasterScaleFactor( rasterScaleFactor );
286-
return true;
287-
}
288-
289250
QLineF QgsAnnotationItem::segment( int index )
290251
{
291252
switch ( index )

src/gui/qgsannotationitem.h

-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
class QDomDocument;
2424
class QDomElement;
2525
class QDialog;
26-
class QgsRenderContext;
2726
class QgsVectorLayer;
2827
class QgsMarkerSymbolV2;
2928

@@ -129,11 +128,6 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
129128
void drawFrame( QPainter* p );
130129
void drawMarkerSymbol( QPainter* p );
131130
void drawSelectionBoxes( QPainter* p );
132-
/**Sets render context parameters
133-
@param p painter for rendering
134-
@param context out: configured context
135-
@return true in case of success*/
136-
bool setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const;
137131
/**Returns frame width in painter units*/
138132
//double scaledFrameWidth( QPainter* p) const;
139133
/**Gets the frame line (0 is the top line, 1 right, 2 bottom, 3 left)*/

src/gui/qgsmapcanvasitem.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include "qgsmapcanvasitem.h"
1919
#include "qgsmapcanvas.h"
20+
#include "qgsmaprenderer.h"
2021
#include "qgsmaptopixel.h"
22+
#include "qgsrendercontext.h"
2123
#include <QGraphicsScene>
2224
#include <QRect>
2325
#include <QPen>
@@ -101,6 +103,44 @@ void QgsMapCanvasItem::updateCanvas()
101103
//mMapCanvas->scene()->update(); //Contents();
102104
}
103105

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+
104144
void QgsMapCanvasItem::updatePosition()
105145
{
106146
// default implementation: recalculate position of the item

src/gui/qgsmapcanvasitem.h

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsrectangle.h"
2222

2323
class QgsMapCanvas;
24+
class QgsRenderContext;
2425
class QPainter;
2526

2627
/** \ingroup gui
@@ -47,6 +48,13 @@ class GUI_EXPORT QgsMapCanvasItem : public QGraphicsItem
4748
//! schedules map canvas for repaint
4849
void updateCanvas();
4950

51+
/**Sets render context parameters
52+
@param p painter for rendering
53+
@param context out: configured context
54+
@return true in case of success
55+
@note added in version 1.5*/
56+
bool setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const;
57+
5058

5159
public:
5260

0 commit comments

Comments
 (0)