Skip to content

Commit

Permalink
Feature #8725: 'AA' disabling uses layer cfg
Browse files Browse the repository at this point in the history
'AA' disabling for '1-pixel geometries' uses the layer simplification
configuration
  • Loading branch information
ahuarte47 committed Nov 4, 2013
1 parent 709781a commit f30f229
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -694,7 +694,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
.setSubsetOfAttributes( attributes );

// Enable the simplification of the geometries before fetch the features using the current map2pixel context.
if ( mSimplifyDrawing && !mEditBuffer && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( simplifyDrawingCanbeApplied() && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) )
{
QPainter* p = rendererContext.painter();
float dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1372,6 +1372,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Returns whether is enabled the map2pixel simplification of geometries for fast rendering of features */
bool simplifyDrawing() const { return mSimplifyDrawing; }

/** Returns whether the VectorLayer can apply geometry simplification in FeatureRequests */
bool simplifyDrawingCanbeApplied() const { return mSimplifyDrawing && !mEditBuffer; }

public slots:
/**
* Select feature by its ID
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -181,10 +181,10 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
p->setPen( context.selected() ? mSelPen : mPen );

// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
if ( points.size()<=2 && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer() ? context.layer()->simplifyDrawingTol() : QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT ) && p->renderHints() & QPainter::Antialiasing )
if ( points.size()<=2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied() && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolyline ( points );
p->drawPolyline( points );
p->setRenderHint( QPainter::Antialiasing, true );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -332,7 +332,7 @@ void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points,
}

// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
if ( points.size()<=5 && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer() ? context.layer()->simplifyDrawingTol() : QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT ) && p->renderHints() & QPainter::Antialiasing )
if ( points.size()<=5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied() && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer()->simplifyDrawingTol() ) && p->renderHints() & QPainter::Antialiasing )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawConvexPolygon( points );
Expand Down
19 changes: 17 additions & 2 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -34,7 +34,7 @@
#include <cmath>

QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
: mType( type ), mLayers( layers ), mAlpha( 1.0 ), mRenderHints( 0 )
: mType( type ), mLayers( layers ), mAlpha( 1.0 ), mRenderHints( 0 ), mLayer( NULL )
{

// check they're all correct symbol layers
Expand Down Expand Up @@ -215,17 +215,24 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )

void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsVectorLayer* layer )
{
mLayer = layer;

QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
symbolContext.setLayer( layer );
symbolContext.setLayer( mLayer );

for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
( *it )->startRender( symbolContext );
}

void QgsSymbolV2::stopRender( QgsRenderContext& context )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
symbolContext.setLayer( mLayer );

for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
( *it )->stopRender( symbolContext );

mLayer = NULL;
}

void QgsSymbolV2::setColor( const QColor& color )
Expand All @@ -252,6 +259,8 @@ void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
{
QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( painter );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints );
symbolContext.setLayer( mLayer );

for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
{
if ( mType == Fill && ( *it )->type() == Line )
Expand Down Expand Up @@ -532,6 +541,8 @@ QgsSymbolV2::ScaleMethod QgsMarkerSymbolV2::scaleMethod()
void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
symbolContext.setLayer( mLayer );

if ( layer != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
Expand Down Expand Up @@ -600,6 +611,8 @@ double QgsLineSymbolV2::width()
void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
symbolContext.setLayer( mLayer );

if ( layer != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
Expand Down Expand Up @@ -635,6 +648,8 @@ QgsFillSymbolV2::QgsFillSymbolV2( QgsSymbolLayerV2List layers )
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f );
symbolContext.setLayer( mLayer );

if ( layer != -1 )
{
if ( layer >= 0 && layer < mLayers.count() )
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -128,6 +128,9 @@ class CORE_EXPORT QgsSymbolV2

QSet<QString> usedAttributes() const;

void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
const QgsVectorLayer* layer() const { return mLayer; }

protected:
QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated

Expand All @@ -145,6 +148,8 @@ class CORE_EXPORT QgsSymbolV2
qreal mAlpha;

int mRenderHints;

const QgsVectorLayer* mLayer; //current vectorlayer
};

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

0 comments on commit f30f229

Please sign in to comment.