[QGIS Commit] r12763 - trunk/qgis/src/core/symbology-ng
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Jan 14 16:36:36 EST 2010
Author: mhugent
Date: 2010-01-14 16:36:35 -0500 (Thu, 14 Jan 2010)
New Revision: 12763
Modified:
trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
Log:
Create a better fake rendercontext for symbol previews
Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp 2010-01-14 18:33:24 UTC (rev 12762)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp 2010-01-14 21:36:35 UTC (rev 12763)
@@ -660,3 +660,19 @@
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;
+}
Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h 2010-01-14 18:33:24 UTC (rev 12762)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.h 2010-01-14 21:36:35 UTC (rev 12763)
@@ -73,6 +73,8 @@
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;
Modified: trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp 2010-01-14 18:33:24 UTC (rev 12762)
+++ trunk/qgis/src/core/symbology-ng/qgssymbolv2.cpp 2010-01-14 21:36:35 UTC (rev 12763)
@@ -160,8 +160,7 @@
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 )
{
@@ -186,9 +185,7 @@
p.drawLine( 50, 0, 50, 100 );
}
- QgsRenderContext context;
- context.setPainter( &p );
-
+ QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( &p );
startRender( context );
if ( mType == QgsSymbolV2::Line )
@@ -248,7 +245,7 @@
////////////////////
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u )
- : mRenderContext( c ), mOutputUnit( u )
+ : mRenderContext( c ), mOutputUnit( u )
{
}
@@ -258,12 +255,12 @@
}
-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 );
}
More information about the QGIS-commit
mailing list