Skip to content
Permalink
Browse files

Comments and API improvements of simplification (no functional changes)

- moved QgsVectorLayer::SimplifyHint enum to QgsVectorSimplifyMethod
- use QFlags instead of int for hints
- added few notes about simplification being added in 2.2
  • Loading branch information
wonder-sk committed Feb 21, 2014
1 parent 10f2ac9 commit da1ebc269333988ecb07efe8fb58f5c3db8a90a2
@@ -65,7 +65,10 @@ class QgsFeatureRequest
QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );

//! Set a simplification method for geometries that will be fetched
//! @note added in 2.2

This comment has been minimized.

Copy link
@ahuarte47

ahuarte47 Feb 22, 2014

Contributor

Thank you very much @wonder-sk

QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
//! Get simplification method for geometries that will be fetched
//! @note added in 2.2
const QgsSimplifyMethod& simplifyMethod() const;

/**
@@ -1,5 +1,7 @@

/** This class contains information about how to simplify geometries fetched from a QgsFeatureIterator */
/** This class contains information about how to simplify geometries fetched from a QgsFeatureIterator
* @note added in 2.2
*/
class QgsSimplifyMethod
{
%TypeHeaderCode
@@ -1025,21 +1025,20 @@ class QgsVectorLayer : QgsMapLayer
/** @note not available in python bindings */
// inline QgsGeometryCache* cache();

/** Simplification flags for fast rendering of features */
enum SimplifyHint
{
NoSimplification = 0, //!< No simplification can be applied
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
AntialiasingSimplification = 2, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
FullSimplification = 3, //!< All simplification hints can be applied ( Geometry + AA-disabling )
};
/** Set the simplification settings for fast rendering of features */
/** Set the simplification settings for fast rendering of features
* @note added in 2.2
*/
void setSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod );
/** Returns the simplification settings for fast rendering of features */
/** Returns the simplification settings for fast rendering of features
* @note added in 2.2
*/
const QgsVectorSimplifyMethod& simplifyMethod() const;

/** Returns whether the VectorLayer can apply the specified simplification hint */
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, int simplifyHint ) const;
/** Returns whether the VectorLayer can apply the specified simplification hint
* @note Do not use in 3rd party code - may be removed in future version!
* @note added in 2.2
*/
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;

public slots:
/**
@@ -1,5 +1,7 @@

/** This class contains information how to simplify geometries fetched from a vector layer */
/** This class contains information how to simplify geometries fetched from a vector layer
* @note added in 2.2
*/
class QgsVectorSimplifyMethod
{
%TypeHeaderCode
@@ -12,10 +14,20 @@ class QgsVectorSimplifyMethod
//! copy constructor
QgsVectorSimplifyMethod( const QgsVectorSimplifyMethod& rh );

/** Simplification flags for fast rendering of features */
enum SimplifyHint
{
NoSimplification = 0, //!< No simplification can be applied
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
AntialiasingSimplification = 2, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
FullSimplification = 3, //!< All simplification hints can be applied ( Geometry + AA-disabling )
};
typedef QFlags<QgsVectorSimplifyMethod::SimplifyHint> SimplifyHints;

/** Sets the simplification hints of the vector layer managed */
void setSimplifyHints( int simplifyHints );
void setSimplifyHints( QFlags<QgsVectorSimplifyMethod::SimplifyHint> simplifyHints );
/** Gets the simplification hints of the vector layer managed */
int simplifyHints() const;
QFlags<QgsVectorSimplifyMethod::SimplifyHint> simplifyHints() const;

/** Sets the simplification threshold of the vector layer managed */
void setThreshold( float threshold );
@@ -32,3 +44,5 @@ class QgsVectorSimplifyMethod
/** Gets the maximum scale at which the layer should be simplified */
float maximumScale() const;
};

QFlags<QgsVectorSimplifyMethod::SimplifyHint> operator|( QgsVectorSimplifyMethod::SimplifyHint f1, QFlags<QgsVectorSimplifyMethod::SimplifyHint> f2 );
@@ -569,7 +569,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() );

// Default simplify drawing configuration
mSimplifyDrawingGroupBox->setChecked( settings.value( "/qgis/simplifyDrawingHints", ( int )QgsVectorLayer::GeometrySimplification ).toInt() != QgsVectorLayer::NoSimplification );
mSimplifyDrawingGroupBox->setChecked( settings.value( "/qgis/simplifyDrawingHints", ( int )QgsVectorSimplifyMethod::GeometrySimplification ).toInt() != QgsVectorSimplifyMethod::NoSimplification );
mSimplifyDrawingSpinBox->setValue( settings.value( "/qgis/simplifyDrawingTol", QGis::DEFAULT_MAPTOPIXEL_THRESHOLD ).toFloat() );
mSimplifyDrawingAtProvider->setChecked( !settings.value( "/qgis/simplifyLocal", true ).toBool() );

@@ -1110,13 +1110,13 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );

// Default simplify drawing configuration
int simplifyHints = QgsVectorLayer::NoSimplification;
QgsVectorSimplifyMethod::SimplifyHints simplifyHints = QgsVectorSimplifyMethod::NoSimplification;
if ( mSimplifyDrawingGroupBox->isChecked() )
{
simplifyHints |= QgsVectorLayer::GeometrySimplification;
if ( mSimplifyDrawingSpinBox->value() > 1 ) simplifyHints |= QgsVectorLayer::AntialiasingSimplification;
simplifyHints |= QgsVectorSimplifyMethod::GeometrySimplification;
if ( mSimplifyDrawingSpinBox->value() > 1 ) simplifyHints |= QgsVectorSimplifyMethod::AntialiasingSimplification;
}
settings.setValue( "/qgis/simplifyDrawingHints", simplifyHints );
settings.setValue( "/qgis/simplifyDrawingHints", ( int ) simplifyHints );
settings.setValue( "/qgis/simplifyDrawingTol", mSimplifyDrawingSpinBox->value() );
settings.setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
settings.setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
@@ -393,7 +393,7 @@ void QgsVectorLayerProperties::syncToLayer( void )

// get simplify drawing configuration
const QgsVectorSimplifyMethod& simplifyMethod = layer->simplifyMethod();
mSimplifyDrawingGroupBox->setChecked( simplifyMethod.simplifyHints() != QgsVectorLayer::NoSimplification );
mSimplifyDrawingGroupBox->setChecked( simplifyMethod.simplifyHints() != QgsVectorSimplifyMethod::NoSimplification );
mSimplifyDrawingSpinBox->setValue( simplifyMethod.threshold() );

if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )
@@ -558,11 +558,11 @@ void QgsVectorLayerProperties::apply()
layer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );

//layer simplify drawing configuration
int simplifyHints = QgsVectorLayer::NoSimplification;
QgsVectorSimplifyMethod::SimplifyHints simplifyHints = QgsVectorSimplifyMethod::NoSimplification;
if ( mSimplifyDrawingGroupBox->isChecked() )
{
simplifyHints |= QgsVectorLayer::GeometrySimplification;
if ( mSimplifyDrawingSpinBox->value() > 1 ) simplifyHints |= QgsVectorLayer::AntialiasingSimplification;
simplifyHints |= QgsVectorSimplifyMethod::GeometrySimplification;
if ( mSimplifyDrawingSpinBox->value() > 1 ) simplifyHints |= QgsVectorSimplifyMethod::AntialiasingSimplification;
}
QgsVectorSimplifyMethod simplifyMethod = layer->simplifyMethod();
simplifyMethod.setSimplifyHints( simplifyHints );
@@ -123,7 +123,10 @@ class CORE_EXPORT QgsFeatureRequest
QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );

//! Set a simplification method for geometries that will be fetched
//! @note added in 2.2
QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
//! Get simplification method for geometries that will be fetched
//! @note added in 2.2
const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }

/**
@@ -20,6 +20,7 @@ class QgsAbstractGeometrySimplifier;

/**
* This class contains information about how to simplify geometries fetched from a QgsFeatureIterator
* @note added in 2.2
*/
class CORE_EXPORT QgsSimplifyMethod
{
@@ -186,7 +186,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,

// Default simplify drawing settings
QSettings settings;
mSimplifyMethod.setSimplifyHints( settings.value( "/qgis/simplifyDrawingHints", mSimplifyMethod.simplifyHints() ).toInt() );
mSimplifyMethod.setSimplifyHints( ( QgsVectorSimplifyMethod::SimplifyHints ) settings.value( "/qgis/simplifyDrawingHints", ( int ) mSimplifyMethod.simplifyHints() ).toInt() );
mSimplifyMethod.setThreshold( settings.value( "/qgis/simplifyDrawingTol", mSimplifyMethod.threshold() ).toFloat() );
mSimplifyMethod.setForceLocalOptimization( settings.value( "/qgis/simplifyLocal", mSimplifyMethod.forceLocalOptimization() ).toBool() );
mSimplifyMethod.setMaximumScale( settings.value( "/qgis/simplifyMaxScale", mSimplifyMethod.maximumScale() ).toFloat() );
@@ -704,7 +704,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
.setSubsetOfAttributes( attributes );

// enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
if ( simplifyDrawingCanbeApplied( rendererContext, QgsVectorLayer::GeometrySimplification ) )
if ( simplifyDrawingCanbeApplied( rendererContext, QgsVectorSimplifyMethod::GeometrySimplification ) )
{
QPainter* p = rendererContext.painter();
double dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
@@ -1290,7 +1290,7 @@ bool QgsVectorLayer::setSubsetString( QString subset )
return res;
}

bool QgsVectorLayer::simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, int simplifyHint ) const
bool QgsVectorLayer::simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const
{
if ( mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QGis::Point ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && renderContext.useRenderingOptimization() )
{
@@ -1907,7 +1907,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
}

// get the simplification drawing settings
mSimplifyMethod.setSimplifyHints( e.attribute( "simplifyDrawingHints", "1" ).toInt() );
mSimplifyMethod.setSimplifyHints( ( QgsVectorSimplifyMethod::SimplifyHints ) e.attribute( "simplifyDrawingHints", "1" ).toInt() );
mSimplifyMethod.setThreshold( e.attribute( "simplifyDrawingTol", "1" ).toFloat() );
mSimplifyMethod.setForceLocalOptimization( e.attribute( "simplifyLocal", "1" ).toInt() );
mSimplifyMethod.setMaximumScale( e.attribute( "simplifyMaxScale", "1" ).toFloat() );
@@ -1376,21 +1376,20 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** @note not available in python bindings */
inline QgsGeometryCache* cache() { return mCache; }

/** Simplification flags for fast rendering of features */
enum SimplifyHint
{
NoSimplification = 0, //!< No simplification can be applied
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
AntialiasingSimplification = 2, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
FullSimplification = 3, //!< All simplification hints can be applied ( Geometry + AA-disabling )
};
/** Set the simplification settings for fast rendering of features */
/** Set the simplification settings for fast rendering of features
* @note added in 2.2
*/
void setSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod ) { mSimplifyMethod = simplifyMethod; }
/** Returns the simplification settings for fast rendering of features */
/** Returns the simplification settings for fast rendering of features
* @note added in 2.2
*/
inline const QgsVectorSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }

/** Returns whether the VectorLayer can apply the specified simplification hint */
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, int simplifyHint ) const;
/** Returns whether the VectorLayer can apply the specified simplification hint
* @note Do not use in 3rd party code - may be removed in future version!
* @note added in 2.2
*/
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;

public slots:
/**
@@ -18,7 +18,7 @@
#include "qgsvectorlayer.h"

QgsVectorSimplifyMethod::QgsVectorSimplifyMethod()
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorLayer::FullSimplification : QgsVectorLayer::GeometrySimplification )
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorSimplifyMethod::FullSimplification : QgsVectorSimplifyMethod::GeometrySimplification )
, mThreshold( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
, mLocalOptimization( true )
, mMaximumScale( 1 )
@@ -16,7 +16,11 @@
#ifndef QGSVECTORSIMPLIFYMETHOD_H
#define QGSVECTORSIMPLIFYMETHOD_H

/** This class contains information how to simplify geometries fetched from a vector layer */
#include <QFlags>

/** This class contains information how to simplify geometries fetched from a vector layer
* @note added in 2.2
*/
class CORE_EXPORT QgsVectorSimplifyMethod
{
public:
@@ -27,10 +31,20 @@ class CORE_EXPORT QgsVectorSimplifyMethod
//! assignment operator
QgsVectorSimplifyMethod& operator=( const QgsVectorSimplifyMethod& rh );

/** Simplification flags for fast rendering of features */
enum SimplifyHint
{
NoSimplification = 0, //!< No simplification can be applied
GeometrySimplification = 1, //!< The geometries can be simplified using the current map2pixel context state
AntialiasingSimplification = 2, //!< The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'
FullSimplification = 3, //!< All simplification hints can be applied ( Geometry + AA-disabling )
};
Q_DECLARE_FLAGS( SimplifyHints, SimplifyHint )

/** Sets the simplification hints of the vector layer managed */
void setSimplifyHints( int simplifyHints ) { mSimplifyHints = simplifyHints; }
void setSimplifyHints( SimplifyHints simplifyHints ) { mSimplifyHints = simplifyHints; }
/** Gets the simplification hints of the vector layer managed */
inline int simplifyHints() const { return mSimplifyHints; }
inline SimplifyHints simplifyHints() const { return mSimplifyHints; }

/** Sets the simplification threshold of the vector layer managed */
void setThreshold( float threshold ) { mThreshold = threshold; }
@@ -49,7 +63,7 @@ class CORE_EXPORT QgsVectorSimplifyMethod

private:
/** Simplification hints for fast rendering of features of the vector layer managed */
int mSimplifyHints;
SimplifyHints mSimplifyHints;
/** Simplification threshold */
float mThreshold;
/** Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
@@ -58,4 +72,6 @@ class CORE_EXPORT QgsVectorSimplifyMethod
float mMaximumScale;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorSimplifyMethod::SimplifyHints )

#endif // QGSVECTORSIMPLIFYMETHOD_H
@@ -188,7 +188,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 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolyline( points );
@@ -388,7 +388,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 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
if ( points.size() <= 5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawRect( points.boundingRect() );
@@ -81,7 +81,7 @@ void TestQgsAtlasComposition::initTestCase()
"ogr" );

QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorLayer::NoSimplification );
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mVectorLayer->setSimplifyMethod( simplifyMethod );

QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mVectorLayer );
@@ -89,7 +89,7 @@ void TestQgsBlendModes::initTestCase()
myPolyFileInfo.completeBaseName(), "ogr" );

QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorLayer::NoSimplification );
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );

mpPolysLayer->setSimplifyMethod( simplifyMethod );
QgsMapLayerRegistry::instance()->addMapLayers(
@@ -96,7 +96,7 @@ void TestQgsGradients::initTestCase()
myPolyFileInfo.completeBaseName(), "ogr" );

QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorLayer::NoSimplification );
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mpPolysLayer->setSimplifyMethod( simplifyMethod );

// Register the layer with the registry
@@ -250,7 +250,7 @@ void TestQgsGradients::gradientSymbolFromQml()
mReport += "<h2>Gradient symbol from QML test</h2>\n";
QVERIFY( setQml( "gradient" ) );
QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorLayer::NoSimplification );
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
mpPolysLayer->setSimplifyMethod( simplifyMethod );
QVERIFY( imageCheck( "gradient_from_qml" ) );
}

0 comments on commit da1ebc2

Please sign in to comment.
You can’t perform that action at this time.