Skip to content

Commit

Permalink
Create a better fake rendercontext for symbol previews
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12763 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 14, 2010
1 parent 7505309 commit 03c6340
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 16 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,19 @@ double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext& c, QgsSymb
return c.rasterScaleFactor() / c.mapToPixel().mapUnitsPerPixel();
}
}

QgsRenderContext QgsSymbolLayerV2Utils::createRenderContext( QPainter* p )
{
QgsRenderContext context;
context.setPainter( p );
context.setRasterScaleFactor( 1.0 );
if ( p && p->device() )
{
context.setScaleFactor( p->device()->logicalDpiX() / 25.4 );
}
else
{
context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
}
return context;
}
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static double lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
/**Returns scale factor painter units -> pixel dimensions*/
static double pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
/**Creates a render context for a pixel based device*/
static QgsRenderContext createRenderContext( QPainter* p );
};

class QPolygonF;
Expand Down
13 changes: 5 additions & 8 deletions src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ QColor QgsSymbolV2::color()

void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
{
QgsRenderContext context;
context.setPainter( painter );
QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( painter );
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
Expand All @@ -186,9 +185,7 @@ QImage QgsSymbolV2::bigSymbolPreviewImage()
p.drawLine( 50, 0, 50, 100 );
}

QgsRenderContext context;
context.setPainter( &p );

QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( &p );
startRender( context );

if ( mType == QgsSymbolV2::Line )
Expand Down Expand Up @@ -248,7 +245,7 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
////////////////////

QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
: mRenderContext( c ), mOutputUnit( u )
: mRenderContext( c ), mOutputUnit( u )
{

}
Expand All @@ -258,12 +255,12 @@ QgsSymbolV2RenderContext::~QgsSymbolV2RenderContext()

}

double QgsSymbolV2RenderContext::outputLineWidth(double width) const
double QgsSymbolV2RenderContext::outputLineWidth( double width ) const
{
return width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( mRenderContext, mOutputUnit );
}

double QgsSymbolV2RenderContext::outputPixelSize(double size) const
double QgsSymbolV2RenderContext::outputPixelSize( double size ) const
{
return size * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( mRenderContext, mOutputUnit );
}
Expand Down

0 comments on commit 03c6340

Please sign in to comment.