Skip to content

Commit 653af3a

Browse files
committed
#8725R: add maximum scale at which the layer should be simplified
1 parent 06b1fbc commit 653af3a

8 files changed

+82
-1
lines changed

python/core/qgsvectorsimplifymethod.sip

+5
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ class QgsVectorSimplifyMethod
2626
void setForceLocalOptimization( bool localOptimization );
2727
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
2828
bool forceLocalOptimization();
29+
30+
/** Sets the maximum scale at which the layer should be simplified */
31+
void setMaximumScale( float maximumScale );
32+
/** Gets the maximum scale at which the layer should be simplified */
33+
float maximumScale() const;
2934
};

src/app/qgsoptions.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
570570
mSimplifyDrawingSpinBox->setValue( settings.value( "/qgis/simplifyDrawingTol", QGis::DEFAULT_MAPTOPIXEL_THRESHOLD ).toFloat() );
571571
mSimplifyDrawingAtProvider->setChecked( !settings.value( "/qgis/simplifyLocal", true ).toBool() );
572572

573+
QStringList myScalesList = PROJECT_SCALES.split( "," );
574+
myScalesList.append( "1:1" );
575+
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
576+
mSimplifyMaximumScaleComboBox->setScale( 1.0 / settings.value( "/qgis/simplifyMaxScale", 1 ).toFloat() );
577+
573578
// Slightly awkard here at the settings value is true to use QImage,
574579
// but the checkbox is true to use QPixmap
575580
chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) );
@@ -1111,6 +1116,7 @@ void QgsOptions::saveOptions()
11111116
settings.setValue( "/qgis/simplifyDrawingHints", simplifyHints );
11121117
settings.setValue( "/qgis/simplifyDrawingTol", mSimplifyDrawingSpinBox->value() );
11131118
settings.setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
1119+
settings.setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
11141120

11151121
// project
11161122
settings.setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );

src/app/qgsvectorlayerproperties.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ void QgsVectorLayerProperties::syncToLayer( void )
409409
mSimplifyDrawingAtProvider->setEnabled( mSimplifyDrawingGroupBox->isChecked() );
410410
}
411411

412+
QStringList myScalesList = PROJECT_SCALES.split( "," );
413+
myScalesList.append( "1:1" );
414+
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
415+
mSimplifyMaximumScaleComboBox->setScale( 1.0 / simplifyMethod.maximumScale() );
416+
412417
// load appropriate symbology page (V1 or V2)
413418
updateSymbologyPage();
414419

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

562568
// update symbology

src/core/qgsvectorlayer.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
187187
mSimplifyMethod.setSimplifyHints( settings.value( "/qgis/simplifyDrawingHints", mSimplifyMethod.simplifyHints() ).toInt() );
188188
mSimplifyMethod.setThreshold( settings.value( "/qgis/simplifyDrawingTol", mSimplifyMethod.threshold() ).toFloat() );
189189
mSimplifyMethod.setForceLocalOptimization( settings.value( "/qgis/simplifyLocal", mSimplifyMethod.forceLocalOptimization() ).toBool() );
190+
mSimplifyMethod.setMaximumScale( settings.value( "/qgis/simplifyMaxScale", mSimplifyMethod.maximumScale() ).toFloat() );
190191

191192
} // QgsVectorLayer ctor
192193

@@ -701,6 +702,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
701702
.setSubsetOfAttributes( attributes );
702703

703704
// enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
705+
mCurrentRendererContext = &rendererContext;
704706
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification ) )
705707
{
706708
QPainter* p = rendererContext.painter();
@@ -747,6 +749,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
747749
else
748750
drawRendererV2( fit, rendererContext, labeling );
749751

752+
mCurrentRendererContext = NULL;
750753
return true;
751754
}
752755

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

12591262
bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
12601263
{
1261-
return mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QGis::Point ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && ( !mCurrentRendererContext || mCurrentRendererContext->useRenderingOptimization() );
1264+
if ( mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QGis::Point ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && ( !mCurrentRendererContext || mCurrentRendererContext->useRenderingOptimization() ) )
1265+
{
1266+
double maximumSimplificationScale = mSimplifyMethod.maximumScale();
1267+
1268+
// check maximum scale at which generalisation should be carried out
1269+
if ( mCurrentRendererContext && maximumSimplificationScale > 1 && mCurrentRendererContext->rendererScale() <= maximumSimplificationScale )
1270+
return false;
1271+
1272+
return true;
1273+
}
1274+
return false;
12621275
}
12631276

12641277
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
@@ -1873,6 +1886,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
18731886
mSimplifyMethod.setSimplifyHints( e.attribute( "simplifyDrawingHints", "1" ).toInt() );
18741887
mSimplifyMethod.setThreshold( e.attribute( "simplifyDrawingTol", "1" ).toFloat() );
18751888
mSimplifyMethod.setForceLocalOptimization( e.attribute( "simplifyLocal", "1" ).toInt() );
1889+
mSimplifyMethod.setMaximumScale( e.attribute( "simplifyMaxScale", "1" ).toFloat() );
18761890

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

22152230
//save customproperties (for labeling ng)
22162231
writeCustomProperties( node, doc );

src/core/qgsvectorsimplifymethod.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ QgsVectorSimplifyMethod::QgsVectorSimplifyMethod()
2121
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorLayer::FullSimplification : QgsVectorLayer::GeometrySimplification )
2222
, mThreshold( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
2323
, mLocalOptimization( true )
24+
, mMaximumScale( 1 )
2425
{
2526
}
2627

@@ -34,5 +35,6 @@ QgsVectorSimplifyMethod& QgsVectorSimplifyMethod::operator=( const QgsVectorSimp
3435
mSimplifyHints = rh.mSimplifyHints;
3536
mThreshold = rh.mThreshold;
3637
mLocalOptimization = rh.mLocalOptimization;
38+
mMaximumScale = rh.mMaximumScale;
3739
return *this;
3840
}

src/core/qgsvectorsimplifymethod.h

+7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ class CORE_EXPORT QgsVectorSimplifyMethod
4242
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
4343
inline bool forceLocalOptimization() const { return mLocalOptimization; }
4444

45+
/** Sets the maximum scale at which the layer should be simplified */
46+
void setMaximumScale( float maximumScale ) { mMaximumScale = maximumScale; }
47+
/** Gets the maximum scale at which the layer should be simplified */
48+
inline float maximumScale() const { return mMaximumScale; }
49+
4550
private:
4651
/** Simplification hints for fast rendering of features of the vector layer managed */
4752
int mSimplifyHints;
4853
/** Simplification threshold */
4954
float mThreshold;
5055
/** Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
5156
bool mLocalOptimization;
57+
/** Maximum scale at which the layer should be simplified (Maximum scale at which generalisation should be carried out) */
58+
float mMaximumScale;
5259
};
5360

5461
#endif // QGSVECTORSIMPLIFYMETHOD_H

src/ui/qgsoptionsbase.ui

+20
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,26 @@
17101710
</property>
17111711
</widget>
17121712
</item>
1713+
<item row="3" column="1">
1714+
<widget class="QLabel" name="mSimplifyMaxScaleLabel">
1715+
<property name="text">
1716+
<string>Maximum scale at which the layer should be simplified (1:1 always simplifies): </string>
1717+
</property>
1718+
<property name="margin">
1719+
<number>2</number>
1720+
</property>
1721+
</widget>
1722+
</item>
1723+
<item row="3" column="2">
1724+
<widget class="QgsScaleComboBox" name="mSimplifyMaximumScaleComboBox">
1725+
<property name="sizePolicy">
1726+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
1727+
<horstretch>0</horstretch>
1728+
<verstretch>0</verstretch>
1729+
</sizepolicy>
1730+
</property>
1731+
</widget>
1732+
</item>
17131733
</layout>
17141734
</widget>
17151735
</item>

src/ui/qgsvectorlayerpropertiesbase.ui

+20
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,26 @@
958958
</property>
959959
</widget>
960960
</item>
961+
<item row="3" column="1">
962+
<widget class="QLabel" name="mSimplifyMaxScaleLabel">
963+
<property name="text">
964+
<string>Maximum scale at which the layer should be simplified (1:1 always simplifies): </string>
965+
</property>
966+
<property name="margin">
967+
<number>2</number>
968+
</property>
969+
</widget>
970+
</item>
971+
<item row="3" column="2">
972+
<widget class="QgsScaleComboBox" name="mSimplifyMaximumScaleComboBox">
973+
<property name="sizePolicy">
974+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
975+
<horstretch>0</horstretch>
976+
<verstretch>0</verstretch>
977+
</sizepolicy>
978+
</property>
979+
</widget>
980+
</item>
961981
</layout>
962982
</widget>
963983
</item>

0 commit comments

Comments
 (0)