Skip to content

Commit

Permalink
Simple marker: use limit for cache image size. Fixes #8386
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Aug 15, 2013
1 parent 65dfdf1 commit 74367c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -200,7 +200,10 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex

if ( mUsingCache )
{
prepareCache( context );
if ( !prepareCache( context ) )
{
mUsingCache = false;
}
}
else
{
Expand All @@ -212,7 +215,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
}


void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context )
bool QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context )
{
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

Expand All @@ -221,6 +224,11 @@ void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& conte
int imageSize = (( int ) scaledSize + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width
double center = imageSize / 2.0;

if ( imageSize > mMaximumCacheWidth )
{
return false;
}

mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied );
mCache.fill( 0 );

Expand Down Expand Up @@ -263,6 +271,8 @@ void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& conte
drawMarker( &p, context );
p.end();
}

return true;
}

void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
Expand Down
7 changes: 6 additions & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -83,7 +83,9 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
bool prepareShape( QString name = QString() );
bool preparePath( QString name = QString() );

void prepareCache( QgsSymbolV2RenderContext& context );
/**Prepares cache image
@return true in case of success, false if cache image size too large*/
bool prepareCache( QgsSymbolV2RenderContext& context );

QColor mBorderColor;
double mOutlineWidth;
Expand All @@ -98,6 +100,9 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QBrush mSelBrush;
QImage mSelCache;
bool mUsingCache;

//Maximum width/height of cache image
static const int mMaximumCacheWidth = 3000;
};

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

0 comments on commit 74367c5

Please sign in to comment.