Skip to content
Permalink
Browse files

Move setRenderContext() method to mapcanvas item class

git-svn-id: http://svn.osgeo.org/qgis/trunk@13332 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Apr 20, 2010
1 parent 03855f5 commit b24494c7894791fdff1725c31e7de80c371d07b1
@@ -23,6 +23,12 @@ class QgsMapCanvasItem : QGraphicsItem
//! schedules map canvas for repaint
void updateCanvas();

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

public:

@@ -17,7 +17,6 @@

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

bool QgsAnnotationItem::setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const
{
if ( !mMapCanvas || !p )
{
return false;
}
QgsMapRenderer* mapRenderer = mMapCanvas->mapRenderer();
if ( !mapRenderer )
{
return false;
}

context.setPainter( p );
context.setRendererScale( mMapCanvas->scale() );

int dpi = mapRenderer->outputDpi();
int painterDpi = p->device()->logicalDpiX();
double scaleFactor = 1.0;
double rasterScaleFactor = 1.0;

//little trick to find out if painting origines from composer or main map canvas
if ( data( 0 ).toString() == "composer" )
{
rasterScaleFactor = painterDpi / 25.4;
scaleFactor = dpi / 25.4;
}
else
{
if ( mapRenderer->outputUnits() == QgsMapRenderer::Millimeters )
{
scaleFactor = dpi / 25.4;
}
}
context.setScaleFactor( scaleFactor );
context.setRasterScaleFactor( rasterScaleFactor );
return true;
}

QLineF QgsAnnotationItem::segment( int index )
{
switch ( index )
@@ -23,7 +23,6 @@
class QDomDocument;
class QDomElement;
class QDialog;
class QgsRenderContext;
class QgsVectorLayer;
class QgsMarkerSymbolV2;

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

#include "qgsmapcanvasitem.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
#include "qgsmaptopixel.h"
#include "qgsrendercontext.h"
#include <QGraphicsScene>
#include <QRect>
#include <QPen>
@@ -101,6 +103,44 @@ void QgsMapCanvasItem::updateCanvas()
//mMapCanvas->scene()->update(); //Contents();
}

bool QgsMapCanvasItem::setRenderContextVariables( QPainter* p, QgsRenderContext& context ) const
{
if ( !mMapCanvas || !p )
{
return false;
}
QgsMapRenderer* mapRenderer = mMapCanvas->mapRenderer();
if ( !mapRenderer )
{
return false;
}

context.setPainter( p );
context.setRendererScale( mMapCanvas->scale() );

int dpi = mapRenderer->outputDpi();
int painterDpi = p->device()->logicalDpiX();
double scaleFactor = 1.0;
double rasterScaleFactor = 1.0;

//little trick to find out if painting origines from composer or main map canvas
if ( data( 0 ).toString() == "composer" )
{
rasterScaleFactor = painterDpi / 25.4;
scaleFactor = dpi / 25.4;
}
else
{
if ( mapRenderer->outputUnits() == QgsMapRenderer::Millimeters )
{
scaleFactor = dpi / 25.4;
}
}
context.setScaleFactor( scaleFactor );
context.setRasterScaleFactor( rasterScaleFactor );
return true;
}

void QgsMapCanvasItem::updatePosition()
{
// default implementation: recalculate position of the item
@@ -21,6 +21,7 @@
#include "qgsrectangle.h"

class QgsMapCanvas;
class QgsRenderContext;
class QPainter;

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

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


public:

0 comments on commit b24494c

Please sign in to comment.
You can’t perform that action at this time.