mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Move setRenderContext() method to mapcanvas item class
git-svn-id: http://svn.osgeo.org/qgis/trunk@13332 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
03855f5edb
commit
b24494c789
@ -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:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user