440 changes: 438 additions & 2 deletions src/core/qgsfeaturerequest.cpp

Large diffs are not rendered by default.

55 changes: 52 additions & 3 deletions src/core/qgsfeaturerequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

#include <QFlags>

#include "qgsmaprequest.h"
#include "qgsfeature.h"
#include "qgsrectangle.h"
#include "qgsexpression.h"

#include "qgscoordinatetransform.h"
#include "qgsmaptopixel.h"

#include <QList>
typedef QList<int> QgsAttributeList;

Expand Down Expand Up @@ -54,7 +56,7 @@ typedef QList<int> QgsAttributeList;
* QgsFeatureRequest().setFilterFid(45)
*
*/
class CORE_EXPORT QgsFeatureRequest : public QgsMapRequest
class CORE_EXPORT QgsFeatureRequest
{
public:
enum Flag
Expand All @@ -63,7 +65,7 @@ class CORE_EXPORT QgsFeatureRequest : public QgsMapRequest
NoGeometry = 1, //!< Geometry is not required. It may still be returned if e.g. required for a filter condition.
SubsetOfAttributes = 2, //!< Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
ExactIntersect = 4, //!< Use exact geometry intersection (slower) instead of bounding boxes
SimplifyGeometries = 8 //!< Simplify the geometry using the current map2pixel context
SimplifyGeometries = 8 //!< Simplify the geometry using the current map2pixel context (e.g. for fast rendering...)
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down Expand Up @@ -135,6 +137,15 @@ class CORE_EXPORT QgsFeatureRequest : public QgsMapRequest
// void setFilterNativeExpression(con QString& expr); // using provider's SQL (if supported)
// void setLimit(int limit);

const QgsCoordinateTransform* coordinateTransform() const { return mMapCoordTransform; }
QgsFeatureRequest& setCoordinateTransform( const QgsCoordinateTransform* ct );

const QgsMapToPixel* mapToPixel() const { return mMapToPixel; }
QgsFeatureRequest& setMapToPixel( const QgsMapToPixel* mtp );

float mapToPixelTol() const { return mMapToPixelTol; }
QgsFeatureRequest& setMapToPixelTol( float map2pixelTol );

protected:
FilterType mFilter;
QgsRectangle mFilterRect;
Expand All @@ -143,6 +154,44 @@ class CORE_EXPORT QgsFeatureRequest : public QgsMapRequest
QgsExpression* mFilterExpression;
Flags mFlags;
QgsAttributeList mAttrs;

//! For transformation between coordinate systems from current layer to map target. Can be 0 if on-the-fly reprojection is not used
const QgsCoordinateTransform* mMapCoordTransform;
//! For transformation between map coordinates and device coordinates
const QgsMapToPixel* mMapToPixel;
//! Factor tolterance to apply in transformation between map coordinates and device coordinates
float mMapToPixelTol;

// Map2pixel simplification for fast rendering
public:
//! Default Threshold of map2pixel simplification between map coordinates and device coordinates for fast rendering
static float const MAPTOPIXEL_THRESHOLD_DEFAULT;

//! Returns whether the device-geometry can be replaced by its BBOX when is applied the specified map2pixel tolerance
static bool canbeGeneralizedByWndBoundingBox( const QgsRectangle& envelope, float mapToPixelTol = 1.0f );
//! Returns whether the device-geometry can be replaced by its BBOX when is applied the specified map2pixel tolerance
static bool canbeGeneralizedByWndBoundingBox( const QVector<QPointF>& points, float mapToPixelTol = 1.0f );

//! Returns whether the envelope can be replaced by its BBOX when is applied the map2pixel context
static bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope,
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol = 1.0f );

//! Returns whether the envelope can be replaced by its BBOX when is applied the map2pixel context
inline bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope ) const { return canbeGeneralizedByMapBoundingBox( envelope, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }

//! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
static bool simplifyGeometry( QgsGeometry* geometry,
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol = 1.0f );

//! Simplify the specified geometry (Removing duplicated points) when is applied the map2pixel context
inline bool simplifyGeometry( QgsGeometry* geometry ) const { return simplifyGeometry( geometry, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }

//! Simplify the specified point stream (Removing duplicated points) when is applied a map2pixel context
static bool simplifyGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount,
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol = 1.0f );

//! Simplify the specified point stream (Removing duplicated points) when is applied the map2pixel context
inline bool simplifyGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount ) const { return simplifyGeometry( geometryType, envelope, xptr, xStride, yptr, yStride, pointCount, pointSimplifiedCount, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
//so must be false at every new render operation
mRenderContext.setRenderingStopped( false );

// Gets the configured Tolerance for simplify transformations between map coordinates and device coordinates
QSettings mySettings2;
mRenderContext.setMapToPixelTol( mySettings2.value( "Map/map2pixelTol", 1.0f ).toFloat() );

// set selection color
QgsProject* prj = QgsProject::instance();
int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
Expand Down
461 changes: 0 additions & 461 deletions src/core/qgsmaprequest.cpp

This file was deleted.

89 changes: 0 additions & 89 deletions src/core/qgsmaprequest.h

This file was deleted.

8 changes: 1 addition & 7 deletions src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ QgsRenderContext::QgsRenderContext()
mScaleFactor( 1.0 ),
mRasterScaleFactor( 1.0 ),
mRendererScale( 1.0 ),
mLabelingEngine( NULL ),
mMapToPixelTol( 1.0f )
mLabelingEngine( NULL )
{

}
Expand All @@ -42,8 +41,3 @@ void QgsRenderContext::setCoordinateTransform( const QgsCoordinateTransform* t )
{
mCoordTransform = t;
}

void QgsRenderContext::setMapToPixelTol( float map2pixelTol )
{
mMapToPixelTol = map2pixelTol;
}
5 changes: 0 additions & 5 deletions src/core/qgsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class CORE_EXPORT QgsRenderContext
//! Added in QGIS v2.0
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }

float mapToPixelTol() const { return mMapToPixelTol; }
void setMapToPixelTol( float map2pixelTol );

private:

/**Painter for rendering operations*/
Expand All @@ -118,8 +115,6 @@ class CORE_EXPORT QgsRenderContext
bool mUseAdvancedEffects;

QgsMapToPixel mMapToPixel;
/** Tolerance for simplify transformations between map coordinates and device coordinates*/
float mMapToPixelTol;

/**True if the rendering has been canceled*/
bool mRenderingStopped;
Expand Down
15 changes: 10 additions & 5 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mValidExtent( false )
, mSymbolFeatureCounted( false )
, mCurrentRendererContext( 0 )
, mSimplifyDrawingTol( QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT )
, mSimplifyDrawing( true )

{
mActions = new QgsAttributeAction( this );
Expand Down Expand Up @@ -692,10 +694,13 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
.setSubsetOfAttributes( attributes );

// Enable the simplification of the geometries before fetch the features using the current map2pixel context.
featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::SimplifyGeometries );
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
featureRequest.setMapToPixelTol( rendererContext.mapToPixelTol() );
if ( mSimplifyDrawing )
{
featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::SimplifyGeometries );
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
featureRequest.setMapToPixelTol( mSimplifyDrawingTol );
}

QgsFeatureIterator fit = getFeatures( featureRequest );

Expand Down Expand Up @@ -1216,7 +1221,7 @@ QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request
if ( !mDataProvider )
return QgsFeatureIterator();

if ( request.flags() & QgsFeatureRequest::SimplifyGeometries )
if ( mSimplifyDrawing && request.flags() & QgsFeatureRequest::SimplifyGeometries )
return QgsFeatureIterator( new QgsSimplifiedVectorLayerFeatureIterator( this, request ) );

return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( this, request ) );
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** @note not available in python bindings */
inline QgsGeometryCache* cache() { return mCache; }

/** Set the Map2pixel simplification threshold for fast rendering of features */
void setSimplifyDrawingTol( float simplifyDrawingTol ) { mSimplifyDrawingTol = simplifyDrawingTol; }
/** Returns the Map2pixel simplification threshold for fast rendering of features */
float simplifyDrawingTol() const { return mSimplifyDrawingTol; }

/** Enable the Map2pixel simplification for fast rendering of features */
void setSimplifyDrawing( bool simplifyDrawing ) { mSimplifyDrawing = simplifyDrawing; }
/** Returns whether is enabled the map2pixel simplification of geometries for fast rendering of features */
bool simplifyDrawing() const { return mSimplifyDrawing; }

public slots:
/**
Expand Down Expand Up @@ -1632,6 +1641,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Renderer object which holds the information about how to display the features */
QgsFeatureRendererV2 *mRendererV2;

/** Map2pixel simplification threshold for fast rendering of features */
float mSimplifyDrawingTol;
/** Enable map2pixel simplification of geometries for fast rendering of features */
bool mSimplifyDrawing;

/** Label */
QgsLabel *mLabel;

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ 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 && QgsMapRequest::canbeGeneralizedByWndBoundingBox( points, context.renderContext().mapToPixelTol() ) && p->renderHints() & QPainter::Antialiasing )
if ( points.size()<=2 && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer() ? context.layer()->simplifyDrawingTol() : QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT ) && p->renderHints() & QPainter::Antialiasing )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolyline ( points );
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
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 && QgsMapRequest::canbeGeneralizedByWndBoundingBox( points, context.renderContext().mapToPixelTol() ) && p->renderHints() & QPainter::Antialiasing )
if ( points.size()<=5 && QgsFeatureRequest::canbeGeneralizedByWndBoundingBox( points, context.layer() ? context.layer()->simplifyDrawingTol() : QgsFeatureRequest::MAPTOPIXEL_THRESHOLD_DEFAULT ) && p->renderHints() & QPainter::Antialiasing )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolygon( points );
Expand Down