mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Merge pull request #1094 from ahuarte47/Issue_8725R-maxscale
Feature #8725R: support for maximum scale at which the layer should be simplified
This commit is contained in:
commit
f2d0100d5d
@ -1013,7 +1013,7 @@ class QgsVectorLayer : QgsMapLayer
|
|||||||
const QgsVectorSimplifyMethod& simplifyMethod() const;
|
const QgsVectorSimplifyMethod& simplifyMethod() const;
|
||||||
|
|
||||||
/** Returns whether the VectorLayer can apply the specified simplification hint */
|
/** Returns whether the VectorLayer can apply the specified simplification hint */
|
||||||
bool simplifyDrawingCanbeApplied( int simplifyHint ) const;
|
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, int simplifyHint ) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
|
@ -26,4 +26,9 @@ class QgsVectorSimplifyMethod
|
|||||||
void setForceLocalOptimization( bool localOptimization );
|
void setForceLocalOptimization( bool localOptimization );
|
||||||
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
|
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
|
||||||
bool forceLocalOptimization();
|
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() );
|
mSimplifyDrawingSpinBox->setValue( settings.value( "/qgis/simplifyDrawingTol", QGis::DEFAULT_MAPTOPIXEL_THRESHOLD ).toFloat() );
|
||||||
mSimplifyDrawingAtProvider->setChecked( !settings.value( "/qgis/simplifyLocal", true ).toBool() );
|
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,
|
// Slightly awkard here at the settings value is true to use QImage,
|
||||||
// but the checkbox is true to use QPixmap
|
// but the checkbox is true to use QPixmap
|
||||||
chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) );
|
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/simplifyDrawingHints", simplifyHints );
|
||||||
settings.setValue( "/qgis/simplifyDrawingTol", mSimplifyDrawingSpinBox->value() );
|
settings.setValue( "/qgis/simplifyDrawingTol", mSimplifyDrawingSpinBox->value() );
|
||||||
settings.setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
|
settings.setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
|
||||||
|
settings.setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
|
||||||
|
|
||||||
// project
|
// project
|
||||||
settings.setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );
|
settings.setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );
|
||||||
|
@ -416,6 +416,11 @@ void QgsVectorLayerProperties::syncToLayer( void )
|
|||||||
mSimplifyDrawingGroupBox->setChecked( false );
|
mSimplifyDrawingGroupBox->setChecked( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
// load appropriate symbology page (V1 or V2)
|
||||||
updateSymbologyPage();
|
updateSymbologyPage();
|
||||||
|
|
||||||
@ -564,6 +569,7 @@ void QgsVectorLayerProperties::apply()
|
|||||||
simplifyMethod.setSimplifyHints( simplifyHints );
|
simplifyMethod.setSimplifyHints( simplifyHints );
|
||||||
simplifyMethod.setThreshold( mSimplifyDrawingSpinBox->value() );
|
simplifyMethod.setThreshold( mSimplifyDrawingSpinBox->value() );
|
||||||
simplifyMethod.setForceLocalOptimization( !mSimplifyDrawingAtProvider->isChecked() );
|
simplifyMethod.setForceLocalOptimization( !mSimplifyDrawingAtProvider->isChecked() );
|
||||||
|
simplifyMethod.setMaximumScale( 1.0 / mSimplifyMaximumScaleComboBox->scale() );
|
||||||
layer->setSimplifyMethod( simplifyMethod );
|
layer->setSimplifyMethod( simplifyMethod );
|
||||||
|
|
||||||
// update symbology
|
// update symbology
|
||||||
|
@ -187,6 +187,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
|
|||||||
mSimplifyMethod.setSimplifyHints( settings.value( "/qgis/simplifyDrawingHints", mSimplifyMethod.simplifyHints() ).toInt() );
|
mSimplifyMethod.setSimplifyHints( settings.value( "/qgis/simplifyDrawingHints", mSimplifyMethod.simplifyHints() ).toInt() );
|
||||||
mSimplifyMethod.setThreshold( settings.value( "/qgis/simplifyDrawingTol", mSimplifyMethod.threshold() ).toFloat() );
|
mSimplifyMethod.setThreshold( settings.value( "/qgis/simplifyDrawingTol", mSimplifyMethod.threshold() ).toFloat() );
|
||||||
mSimplifyMethod.setForceLocalOptimization( settings.value( "/qgis/simplifyLocal", mSimplifyMethod.forceLocalOptimization() ).toBool() );
|
mSimplifyMethod.setForceLocalOptimization( settings.value( "/qgis/simplifyLocal", mSimplifyMethod.forceLocalOptimization() ).toBool() );
|
||||||
|
mSimplifyMethod.setMaximumScale( settings.value( "/qgis/simplifyMaxScale", mSimplifyMethod.maximumScale() ).toFloat() );
|
||||||
|
|
||||||
} // QgsVectorLayer ctor
|
} // QgsVectorLayer ctor
|
||||||
|
|
||||||
@ -701,7 +702,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
|
|||||||
.setSubsetOfAttributes( attributes );
|
.setSubsetOfAttributes( attributes );
|
||||||
|
|
||||||
// enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
|
// enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
|
||||||
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification ) )
|
if ( simplifyDrawingCanbeApplied( rendererContext, QgsVectorLayer::GeometrySimplification ) )
|
||||||
{
|
{
|
||||||
QPainter* p = rendererContext.painter();
|
QPainter* p = rendererContext.painter();
|
||||||
double dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
|
double dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
|
||||||
@ -1256,9 +1257,19 @@ bool QgsVectorLayer::setSubsetString( QString subset )
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
|
bool QgsVectorLayer::simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, 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 ) && renderContext.useRenderingOptimization() )
|
||||||
|
{
|
||||||
|
double maximumSimplificationScale = mSimplifyMethod.maximumScale();
|
||||||
|
|
||||||
|
// check maximum scale at which generalisation should be carried out
|
||||||
|
if ( maximumSimplificationScale > 1 && renderContext.rendererScale() <= maximumSimplificationScale )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
|
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
|
||||||
@ -1873,6 +1884,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
|
|||||||
mSimplifyMethod.setSimplifyHints( e.attribute( "simplifyDrawingHints", "1" ).toInt() );
|
mSimplifyMethod.setSimplifyHints( e.attribute( "simplifyDrawingHints", "1" ).toInt() );
|
||||||
mSimplifyMethod.setThreshold( e.attribute( "simplifyDrawingTol", "1" ).toFloat() );
|
mSimplifyMethod.setThreshold( e.attribute( "simplifyDrawingTol", "1" ).toFloat() );
|
||||||
mSimplifyMethod.setForceLocalOptimization( e.attribute( "simplifyLocal", "1" ).toInt() );
|
mSimplifyMethod.setForceLocalOptimization( e.attribute( "simplifyLocal", "1" ).toInt() );
|
||||||
|
mSimplifyMethod.setMaximumScale( e.attribute( "simplifyMaxScale", "1" ).toFloat() );
|
||||||
|
|
||||||
//also restore custom properties (for labeling-ng)
|
//also restore custom properties (for labeling-ng)
|
||||||
readCustomProperties( node, "labeling" );
|
readCustomProperties( node, "labeling" );
|
||||||
@ -2211,6 +2223,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
|
|||||||
mapLayerNode.setAttribute( "simplifyDrawingHints", QString::number( mSimplifyMethod.simplifyHints() ) );
|
mapLayerNode.setAttribute( "simplifyDrawingHints", QString::number( mSimplifyMethod.simplifyHints() ) );
|
||||||
mapLayerNode.setAttribute( "simplifyDrawingTol", QString::number( mSimplifyMethod.threshold() ) );
|
mapLayerNode.setAttribute( "simplifyDrawingTol", QString::number( mSimplifyMethod.threshold() ) );
|
||||||
mapLayerNode.setAttribute( "simplifyLocal", mSimplifyMethod.forceLocalOptimization() ? 1 : 0 );
|
mapLayerNode.setAttribute( "simplifyLocal", mSimplifyMethod.forceLocalOptimization() ? 1 : 0 );
|
||||||
|
mapLayerNode.setAttribute( "simplifyMaxScale", QString::number( mSimplifyMethod.maximumScale() ) );
|
||||||
|
|
||||||
//save customproperties (for labeling ng)
|
//save customproperties (for labeling ng)
|
||||||
writeCustomProperties( node, doc );
|
writeCustomProperties( node, doc );
|
||||||
|
@ -1387,7 +1387,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
|||||||
inline const QgsVectorSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
|
inline const QgsVectorSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
|
||||||
|
|
||||||
/** Returns whether the VectorLayer can apply the specified simplification hint */
|
/** Returns whether the VectorLayer can apply the specified simplification hint */
|
||||||
bool simplifyDrawingCanbeApplied( int simplifyHint ) const;
|
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, int simplifyHint ) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@ QgsVectorSimplifyMethod::QgsVectorSimplifyMethod()
|
|||||||
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorLayer::FullSimplification : QgsVectorLayer::GeometrySimplification )
|
: mSimplifyHints( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD > 1 ? QgsVectorLayer::FullSimplification : QgsVectorLayer::GeometrySimplification )
|
||||||
, mThreshold( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
|
, mThreshold( QGis::DEFAULT_MAPTOPIXEL_THRESHOLD )
|
||||||
, mLocalOptimization( true )
|
, mLocalOptimization( true )
|
||||||
|
, mMaximumScale( 1 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,5 +35,6 @@ QgsVectorSimplifyMethod& QgsVectorSimplifyMethod::operator=( const QgsVectorSimp
|
|||||||
mSimplifyHints = rh.mSimplifyHints;
|
mSimplifyHints = rh.mSimplifyHints;
|
||||||
mThreshold = rh.mThreshold;
|
mThreshold = rh.mThreshold;
|
||||||
mLocalOptimization = rh.mLocalOptimization;
|
mLocalOptimization = rh.mLocalOptimization;
|
||||||
|
mMaximumScale = rh.mMaximumScale;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,11 @@ class CORE_EXPORT QgsVectorSimplifyMethod
|
|||||||
/** Gets where the simplification executes, after fetch the geometries from provider, or when supported, in provider before fetch the geometries */
|
/** 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; }
|
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:
|
private:
|
||||||
/** Simplification hints for fast rendering of features of the vector layer managed */
|
/** Simplification hints for fast rendering of features of the vector layer managed */
|
||||||
int mSimplifyHints;
|
int mSimplifyHints;
|
||||||
@ -49,6 +54,8 @@ class CORE_EXPORT QgsVectorSimplifyMethod
|
|||||||
float mThreshold;
|
float mThreshold;
|
||||||
/** Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
|
/** Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
|
||||||
bool mLocalOptimization;
|
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
|
#endif // QGSVECTORSIMPLIFYMETHOD_H
|
||||||
|
@ -188,7 +188,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
|
|||||||
p->setPen( context.selected() ? mSelPen : mPen );
|
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).
|
// 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( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
|
if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
|
||||||
{
|
{
|
||||||
p->setRenderHint( QPainter::Antialiasing, false );
|
p->setRenderHint( QPainter::Antialiasing, false );
|
||||||
p->drawPolyline( points );
|
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).
|
// 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( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
|
if ( points.size() <= 5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
|
||||||
{
|
{
|
||||||
p->setRenderHint( QPainter::Antialiasing, false );
|
p->setRenderHint( QPainter::Antialiasing, false );
|
||||||
p->drawRect( points.boundingRect() );
|
p->drawRect( points.boundingRect() );
|
||||||
|
@ -1710,6 +1710,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -958,6 +958,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user