Skip to content

Commit 03c6340

Browse files
author
mhugent
committed
Create a better fake rendercontext for symbol previews
git-svn-id: http://svn.osgeo.org/qgis/trunk@12763 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7505309 commit 03c6340

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/core/symbology-ng/qgssymbollayerv2utils.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,19 @@ double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext& c, QgsSymb
660660
return c.rasterScaleFactor() / c.mapToPixel().mapUnitsPerPixel();
661661
}
662662
}
663+
664+
QgsRenderContext QgsSymbolLayerV2Utils::createRenderContext( QPainter* p )
665+
{
666+
QgsRenderContext context;
667+
context.setPainter( p );
668+
context.setRasterScaleFactor( 1.0 );
669+
if ( p && p->device() )
670+
{
671+
context.setScaleFactor( p->device()->logicalDpiX() / 25.4 );
672+
}
673+
else
674+
{
675+
context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
676+
}
677+
return context;
678+
}

src/core/symbology-ng/qgssymbollayerv2utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
7373
static double lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
7474
/**Returns scale factor painter units -> pixel dimensions*/
7575
static double pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
76+
/**Creates a render context for a pixel based device*/
77+
static QgsRenderContext createRenderContext( QPainter* p );
7678
};
7779

7880
class QPolygonF;

src/core/symbology-ng/qgssymbolv2.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ QColor QgsSymbolV2::color()
160160

161161
void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
162162
{
163-
QgsRenderContext context;
164-
context.setPainter( painter );
163+
QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( painter );
165164
QgsSymbolV2RenderContext symbolContext( context, mOutputUnit );
166165
for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
167166
{
@@ -186,9 +185,7 @@ QImage QgsSymbolV2::bigSymbolPreviewImage()
186185
p.drawLine( 50, 0, 50, 100 );
187186
}
188187

189-
QgsRenderContext context;
190-
context.setPainter( &p );
191-
188+
QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( &p );
192189
startRender( context );
193190

194191
if ( mType == QgsSymbolV2::Line )
@@ -248,7 +245,7 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
248245
////////////////////
249246

250247
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
251-
: mRenderContext( c ), mOutputUnit( u )
248+
: mRenderContext( c ), mOutputUnit( u )
252249
{
253250

254251
}
@@ -258,12 +255,12 @@ QgsSymbolV2RenderContext::~QgsSymbolV2RenderContext()
258255

259256
}
260257

261-
double QgsSymbolV2RenderContext::outputLineWidth(double width) const
258+
double QgsSymbolV2RenderContext::outputLineWidth( double width ) const
262259
{
263260
return width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( mRenderContext, mOutputUnit );
264261
}
265262

266-
double QgsSymbolV2RenderContext::outputPixelSize(double size) const
263+
double QgsSymbolV2RenderContext::outputPixelSize( double size ) const
267264
{
268265
return size * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( mRenderContext, mOutputUnit );
269266
}

0 commit comments

Comments
 (0)