Skip to content
Permalink
Browse files

#8725R: add maximum scale at which the layer should be simplified

  • Loading branch information
ahuarte47 committed Jan 21, 2014
1 parent 06b1fbc commit 653af3a459cf78b5f7c064a7c944bb3afd1da025
@@ -26,4 +26,9 @@ class QgsVectorSimplifyMethod
void setForceLocalOptimization( bool localOptimization );
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
bool forceLocalOptimization();

/** Sets the maximum scale at which the layer should be simplified */
void setMaximumScale( float maximumScale );
/** Gets the maximum scale at which the layer should be simplified */
float maximumScale() const;
};
@@ -570,6 +570,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
mSimplifyDrawingSpinBox->setValue( settings.value( "/qgis/simplifyDrawingTol", QGis::DEFAULT_MAPTOPIXEL_THRESHOLD ).toFloat() );
mSimplifyDrawingAtProvider->setChecked( !settings.value( "/qgis/simplifyLocal", true ).toBool() );

QStringList myScalesList = PROJECT_SCALES.split( "," );
myScalesList.append( "1:1" );
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
mSimplifyMaximumScaleComboBox->setScale( 1.0 / settings.value( "/qgis/simplifyMaxScale", 1 ).toFloat() );

// Slightly awkard here at the settings value is true to use QImage,
// but the checkbox is true to use QPixmap
chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) );
@@ -1111,6 +1116,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/simplifyDrawingHints", simplifyHints );
settings.setValue( "/qgis/simplifyDrawingTol", mSimplifyDrawingSpinBox->value() );
settings.setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
settings.setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );

// project
settings.setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );
@@ -409,6 +409,11 @@ void QgsVectorLayerProperties::syncToLayer( void )
mSimplifyDrawingAtProvider->setEnabled( mSimplifyDrawingGroupBox->isChecked() );
}

QStringList myScalesList = PROJECT_SCALES.split( "," );
myScalesList.append( "1:1" );
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
mSimplifyMaximumScaleComboBox->setScale( 1.0 / simplifyMethod.maximumScale() );

// load appropriate symbology page (V1 or V2)
updateSymbologyPage();

@@ -557,6 +562,7 @@ void QgsVectorLayerProperties::apply()
simplifyMethod.setSimplifyHints( simplifyHints );
simplifyMethod.setThreshold( mSimplifyDrawingSpinBox->value() );
simplifyMethod.setForceLocalOptimization( !mSimplifyDrawingAtProvider->isChecked() );
simplifyMethod.setMaximumScale( 1.0 / mSimplifyMaximumScaleComboBox->scale() );
layer->setSimplifyMethod( simplifyMethod );

// update symbology
@@ -187,6 +187,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
mSimplifyMethod.setSimplifyHints( settings.value( "/qgis/simplifyDrawingHints", 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() );

} // QgsVectorLayer ctor

@@ -701,6 +702,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.
mCurrentRendererContext = &rendererContext;
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification ) )
{
QPainter* p = rendererContext.painter();
@@ -747,6 +749,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
else
drawRendererV2( fit, rendererContext, labeling );

mCurrentRendererContext = NULL;
return true;
}

@@ -1258,7 +1261,17 @@ bool QgsVectorLayer::setSubsetString( QString subset )

bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
{
return mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QGis::Point ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && ( !mCurrentRendererContext || mCurrentRendererContext->useRenderingOptimization() );
if ( mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QGis::Point ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && ( !mCurrentRendererContext || mCurrentRendererContext->useRenderingOptimization() ) )
{
double maximumSimplificationScale = mSimplifyMethod.maximumScale();

// check maximum scale at which generalisation should be carried out
if ( mCurrentRendererContext && maximumSimplificationScale > 1 && mCurrentRendererContext->rendererScale() <= maximumSimplificationScale )
return false;

return true;
}
return false;
}

QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
@@ -1873,6 +1886,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mSimplifyMethod.setSimplifyHints( 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() );

//also restore custom properties (for labeling-ng)
readCustomProperties( node, "labeling" );
@@ -2211,6 +2225,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
mapLayerNode.setAttribute( "simplifyDrawingHints", QString::number( mSimplifyMethod.simplifyHints() ) );
mapLayerNode.setAttribute( "simplifyDrawingTol", QString::number( mSimplifyMethod.threshold() ) );
mapLayerNode.setAttribute( "simplifyLocal", mSimplifyMethod.forceLocalOptimization() ? 1 : 0 );
mapLayerNode.setAttribute( "simplifyMaxScale", QString::number( mSimplifyMethod.maximumScale() ) );

//save customproperties (for labeling ng)
writeCustomProperties( node, doc );
@@ -21,6 +21,7 @@ QgsVectorSimplifyMethod::QgsVectorSimplifyMethod()
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorLayer::FullSimplification : QgsVectorLayer::GeometrySimplification )
, mThreshold( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
, mLocalOptimization( true )
, mMaximumScale( 1 )
{
}

@@ -34,5 +35,6 @@ QgsVectorSimplifyMethod& QgsVectorSimplifyMethod::operator=( const QgsVectorSimp
mSimplifyHints = rh.mSimplifyHints;
mThreshold = rh.mThreshold;
mLocalOptimization = rh.mLocalOptimization;
mMaximumScale = rh.mMaximumScale;
return *this;
}
@@ -42,13 +42,20 @@ class CORE_EXPORT QgsVectorSimplifyMethod
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
inline bool forceLocalOptimization() const { return mLocalOptimization; }

/** Sets the maximum scale at which the layer should be simplified */
void setMaximumScale( float maximumScale ) { mMaximumScale = maximumScale; }
/** Gets the maximum scale at which the layer should be simplified */
inline float maximumScale() const { return mMaximumScale; }

private:
/** Simplification hints for fast rendering of features of the vector layer managed */
int mSimplifyHints;
/** Simplification threshold */
float mThreshold;
/** Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
bool mLocalOptimization;
/** Maximum scale at which the layer should be simplified (Maximum scale at which generalisation should be carried out) */
float mMaximumScale;
};

#endif // QGSVECTORSIMPLIFYMETHOD_H
@@ -1710,6 +1710,26 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="mSimplifyMaxScaleLabel">
<property name="text">
<string>Maximum scale at which the layer should be simplified (1:1 always simplifies): </string>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QgsScaleComboBox" name="mSimplifyMaximumScaleComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -958,6 +958,26 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="mSimplifyMaxScaleLabel">
<property name="text">
<string>Maximum scale at which the layer should be simplified (1:1 always simplifies): </string>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QgsScaleComboBox" name="mSimplifyMaximumScaleComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 653af3a

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