Skip to content

Commit

Permalink
SimpleMarker symbol layer: do not cache marker symbol if the vector o…
Browse files Browse the repository at this point in the history
…utput is enforced, fixed scaling

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13419 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 4, 2010
1 parent d8c7a16 commit 521d9f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -77,6 +77,11 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation;
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale;

// use caching only when:
// - the size and rotation is not data-defined
// - drawing to screen (not printer)
mUsingCache = !hasDataDefinedRotation && !hasDataDefinedSize && !context.renderContext().forceVectorOutput();

// use either QPolygonF or QPainterPath for drawing
// TODO: find out whether drawing directly doesn't bring overhead - if not, use it for all shapes
if ( !prepareShape() ) // drawing as a polygon
Expand All @@ -101,7 +106,9 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
// scale the shape (if the size is not going to be modified)
if ( !hasDataDefinedSize )
{
double scaledSize = context.outputPixelSize( mSize );
double scaledSize = context.outputLineWidth( mSize );
if ( mUsingCache )
scaledSize *= context.renderContext().rasterScaleFactor();
double half = scaledSize / 2.0;
transform.scale( half, half );
}
Expand All @@ -117,10 +124,8 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
else
mPath = transform.map( mPath );

if ( !hasDataDefinedRotation && !hasDataDefinedSize )
if ( mUsingCache )
{
// we can use the cached marker
// TODO: use caching only when drawing to screen (not printer)
prepareCache( context );
}
else
Expand Down Expand Up @@ -324,10 +329,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
return;
}

bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation;
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale;

if ( !hasDataDefinedRotation && !hasDataDefinedSize )
if ( mUsingCache )
{
// we will use cached image
QImage &img = context.selected() ? mSelCache : mCache;
Expand All @@ -340,14 +342,17 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
{
QMatrix transform;

bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation;
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale;

// move to the desired position
transform.translate( point.x() + context.outputLineWidth( mOffset.x() ),
point.y() + context.outputLineWidth( mOffset.y() ) );

// resize if necessary
if ( hasDataDefinedSize )
{
double scaledSize = context.outputPixelSize( mSize );
double scaledSize = context.outputLineWidth( mSize );
double half = scaledSize / 2.0;
transform.scale( half, half );
}
Expand Down Expand Up @@ -655,9 +660,8 @@ QString QgsFontMarkerSymbolLayerV2::layerType() const

void QgsFontMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
double pixelSize = context.outputPixelSize( mSize );
mFont = QFont( mFontFamily );
mFont.setPixelSize( pixelSize / context.renderContext().rasterScaleFactor() );
mFont.setPixelSize( context.outputLineWidth( mSize ) );
QFontMetrics fm( mFont );
mChrOffset = QPointF( fm.width( mChr ) / 2, -fm.ascent() / 2 );

Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -68,6 +68,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QPen mSelPen;
QBrush mSelBrush;
QImage mSelCache;
bool mUsingCache;
};

//////////
Expand Down

0 comments on commit 521d9f3

Please sign in to comment.