Skip to content

Commit

Permalink
Merge remote-tracking branch 'alvaro/Simplification_MTR'
Browse files Browse the repository at this point in the history
Conflicts:
	python/core/qgsmapsettings.sip
  • Loading branch information
wonder-sk committed May 30, 2014
2 parents ecdb6de + 83eec4a commit 04dc5d8
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsmapsettings.sip
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class QgsMapSettings
DrawEditingInfo = 0x02,
ForceVectorOutput = 0x04,
UseAdvancedEffects = 0x08,
DrawLabeling = 0x10
DrawLabeling = 0x10,
UseRenderingOptimization = 0x20
// TODO: ignore scale-based visibility (overview)
};
typedef QFlags<QgsMapSettings::Flag> Flags;
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsrendercontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ class QgsRenderContext
/**Returns true if the rendering optimization (geometry simplification) can be executed*/
bool useRenderingOptimization() const;
void setUseRenderingOptimization( bool enabled );

//! Added in QGIS v2.4
const QgsVectorSimplifyMethod& vectorSimplifyMethod() const;
void setVectorSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod );
};
6 changes: 3 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
jobMapSettings.setCrsTransformEnabled( ms.hasCrsTransformEnabled() );
jobMapSettings.setFlags( ms.flags() );
/* TODO[MD] fix after merge

if ( mComposition->plotStyle() == QgsComposition::Print ||
mComposition->plotStyle() == QgsComposition::Postscript )
{
//if outputing composer, disable optimisations like layer simplification
theRendererContext->setUseRenderingOptimization( false );
}*/
jobMapSettings.setFlag( QgsMapSettings::UseRenderingOptimization, false );
}

//update $map variable. Use QgsComposerItem's id since that is user-definable
QgsExpression::setSpecialColumn( "$map", QgsComposerItem::id() );
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmapsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class CORE_EXPORT QgsMapSettings
DrawEditingInfo = 0x02,
ForceVectorOutput = 0x04,
UseAdvancedEffects = 0x08,
DrawLabeling = 0x10
DrawLabeling = 0x10,
UseRenderingOptimization = 0x20,
// TODO: ignore scale-based visibility (overview)
};
Q_DECLARE_FLAGS( Flags, Flag )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QgsRenderContext::QgsRenderContext()
mLabelingEngine( NULL ),
mUseRenderingOptimization( true )
{

mVectorSimplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
}

QgsRenderContext::~QgsRenderContext()
Expand All @@ -48,6 +48,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings& mapSet
ctx.setDrawEditingInformation( mapSettings.testFlag( QgsMapSettings::DrawEditingInfo ) );
ctx.setForceVectorOutput( mapSettings.testFlag( QgsMapSettings::ForceVectorOutput ) );
ctx.setUseAdvancedEffects( mapSettings.testFlag( QgsMapSettings::UseAdvancedEffects ) );
ctx.setUseRenderingOptimization( mapSettings.testFlag( QgsMapSettings::UseRenderingOptimization ) );
ctx.setCoordinateTransform( 0 );
ctx.setSelectionColor( mapSettings.selectionColor() );
ctx.setRasterScaleFactor( 1.0 );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgscoordinatetransform.h"
#include "qgsmaptopixel.h"
#include "qgsrectangle.h"
#include "qgsvectorsimplifymethod.h"

class QPainter;

Expand Down Expand Up @@ -104,6 +105,10 @@ class CORE_EXPORT QgsRenderContext
bool useRenderingOptimization() const { return mUseRenderingOptimization; }
void setUseRenderingOptimization( bool enabled ) { mUseRenderingOptimization = enabled; }

//! Added in QGIS v2.4
const QgsVectorSimplifyMethod& vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
void setVectorSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod ) { mVectorSimplifyMethod = simplifyMethod; }

private:

/**Painter for rendering operations*/
Expand Down Expand Up @@ -145,6 +150,9 @@ class CORE_EXPORT QgsRenderContext

/**True if the rendering optimization (geometry simplification) can be executed*/
bool mUseRenderingOptimization;

/**Simplification object which holds the information about how to simplify the features for fast rendering */
QgsVectorSimplifyMethod mVectorSimplifyMethod;
};

#endif
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ bool QgsVectorLayerRenderer::render()
simplifyMethod.setForceLocalOptimization( mSimplifyMethod.forceLocalOptimization() );

featureRequest.setSimplifyMethod( simplifyMethod );

QgsVectorSimplifyMethod vectorMethod = mSimplifyMethod;
mContext.setVectorSimplifyMethod( vectorMethod );
}
else
{
QgsVectorSimplifyMethod vectorMethod;
vectorMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mContext.setVectorSimplifyMethod( vectorMethod );
}

QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
Expand Down
4 changes: 1 addition & 3 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,13 @@ 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 0 // TODO[MD]: after merge
if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
if ( points.size() <= 2 && ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolyline( points );
p->setRenderHint( QPainter::Antialiasing, true );
return;
}
#endif

if ( offset == 0 )
{
Expand Down
4 changes: 1 addition & 3 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,13 @@ 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 0 // TODO[MD]: after merge
if ( points.size() <= 5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
if ( points.size() <= 5 && ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawRect( points.boundingRect() );
p->setRenderHint( QPainter::Antialiasing, true );
return;
}
#endif

if ( rings == NULL )
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
this, SLOT( writeProject( QDomDocument & ) ) );

mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
mSettings.setFlag( QgsMapSettings::UseRenderingOptimization );

// class that will sync most of the changes between canvas and (legacy) map renderer
// it is parented to map canvas, will be deleted automatically
Expand Down

0 comments on commit 04dc5d8

Please sign in to comment.