Skip to content

Commit 23b6523

Browse files
ahuarte47m-kuhn
authored andcommitted
#8725-R: FeatureIterator and other minor changes
1 parent faebcce commit 23b6523

7 files changed

+73
-23
lines changed

src/app/qgsvectorlayerproperties.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,21 @@ void QgsVectorLayerProperties::syncToLayer( void )
396396
const QgsVectorSimplifyMethod& simplifyMethod = layer->simplifyMethod();
397397
mSimplifyDrawingGroupBox->setChecked( simplifyMethod.simplifyHints() != QgsVectorLayer::NoSimplification );
398398
mSimplifyDrawingSlider->setValue(( int )( 5.0f * ( simplifyMethod.threshold() - 1 ) ) );
399-
mSimplifyDrawingAtProvider->setChecked( !simplifyMethod.forceLocalOptimization() );
400399
mSimplifyDrawingPanel->setVisible( mSimplifyDrawingSlider->value() > 0 );
401400
mSimplifyDrawingPx->setText( QString( "(%1 px)" ).arg( 1.0f + 0.2f * mSimplifyDrawingSlider->value() ) );
402401

402+
if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )
403+
{
404+
mSimplifyDrawingAtProvider->setChecked( false );
405+
mSimplifyDrawingAtProvider->setEnabled( false );
406+
mSimplifyDrawingAtProvider->setText( QString( "%1 (%2)" ).arg( mSimplifyDrawingAtProvider->text(), tr( "Not supported" ) ) );
407+
}
408+
else
409+
{
410+
mSimplifyDrawingAtProvider->setChecked( !simplifyMethod.forceLocalOptimization() );
411+
mSimplifyDrawingAtProvider->setEnabled( mSimplifyDrawingGroupBox->isChecked() );
412+
}
413+
403414
// load appropriate symbology page (V1 or V2)
404415
updateSymbologyPage();
405416

@@ -1094,3 +1105,15 @@ void QgsVectorLayerProperties::on_mSimplifyDrawingSlider_valueChanged( int value
10941105
mSimplifyDrawingPanel->setVisible( value > 0 );
10951106
mSimplifyDrawingPx->setText( QString( "(%1 px)" ).arg( 1.0f + 0.2f * value ) );
10961107
}
1108+
1109+
void QgsVectorLayerProperties::on_mSimplifyDrawingGroupBox_toggled( bool checked )
1110+
{
1111+
if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )
1112+
{
1113+
mSimplifyDrawingAtProvider->setEnabled( false );
1114+
}
1115+
else
1116+
{
1117+
mSimplifyDrawingAtProvider->setEnabled( mSimplifyDrawingGroupBox->isChecked() );
1118+
}
1119+
}

src/app/qgsvectorlayerproperties.h

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
120120
void on_mMaximumScaleSetCurrentPushButton_clicked();
121121

122122
void on_mSimplifyDrawingSlider_valueChanged( int value );
123+
void on_mSimplifyDrawingGroupBox_toggled( bool checked );
123124

124125
signals:
125126

src/core/qgsfeatureiterator.cpp

+35-21
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@ QgsAbstractFeatureIterator::QgsAbstractFeatureIterator( const QgsFeatureRequest&
2525
, refs( 0 )
2626
, mGeometrySimplifier( NULL )
2727
{
28-
const QgsSimplifyMethod& simplifyMethod = request.simplifyMethod();
29-
30-
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
31-
{
32-
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
33-
34-
if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
35-
{
36-
int simplifyFlags = QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope;
37-
mGeometrySimplifier = new QgsMapToPixelSimplifier( simplifyFlags, simplifyMethod.tolerance() );
38-
}
39-
else
40-
if ( methodType == QgsSimplifyMethod::PreserveTopology )
41-
{
42-
mGeometrySimplifier = new QgsTopologyPreservingSimplifier( simplifyMethod.tolerance() );
43-
}
44-
else
45-
{
46-
QgsDebugMsg( QString( "Simplification method type (%1) is not recognised" ).arg( methodType ) );
47-
}
48-
}
4928
}
5029

5130
QgsAbstractFeatureIterator::~QgsAbstractFeatureIterator()
@@ -122,6 +101,41 @@ void QgsAbstractFeatureIterator::deref()
122101
delete this;
123102
}
124103

104+
bool QgsAbstractFeatureIterator::prepareLocalSimplification()
105+
{
106+
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
107+
108+
if ( mGeometrySimplifier )
109+
{
110+
delete mGeometrySimplifier;
111+
mGeometrySimplifier = NULL;
112+
}
113+
114+
// setup the local simplification of geometries to fetch, it uses the settings of current FeatureRequest
115+
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
116+
{
117+
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
118+
119+
if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
120+
{
121+
int simplifyFlags = QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope;
122+
mGeometrySimplifier = new QgsMapToPixelSimplifier( simplifyFlags, simplifyMethod.tolerance() );
123+
return true;
124+
}
125+
else
126+
if ( methodType == QgsSimplifyMethod::PreserveTopology )
127+
{
128+
mGeometrySimplifier = new QgsTopologyPreservingSimplifier( simplifyMethod.tolerance() );
129+
return true;
130+
}
131+
else
132+
{
133+
QgsDebugMsg( QString( "Simplification method type (%1) is not recognised" ).arg( methodType ) );
134+
}
135+
}
136+
return false;
137+
}
138+
125139
///////
126140

127141
QgsFeatureIterator& QgsFeatureIterator::operator=( const QgsFeatureIterator & other )

src/core/qgsfeatureiterator.h

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class CORE_EXPORT QgsAbstractFeatureIterator
8787
void deref(); //!< remove reference, delete if refs == 0
8888
friend class QgsFeatureIterator;
8989

90+
//! setup if required the local simplification of geometries to fetch, it uses the settings of current FeatureRequest
91+
virtual bool prepareLocalSimplification();
92+
9093
private:
9194
//! optional object to locally simplify geometries fetched by this feature iterator
9295
QgsAbstractGeometrySimplifier* mGeometrySimplifier;

src/core/qgsgeometrysimplifier.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CORE_EXPORT QgsTopologyPreservingSimplifier : public QgsAbstractGeometrySi
5353
QgsTopologyPreservingSimplifier( double tolerance );
5454
virtual ~QgsTopologyPreservingSimplifier();
5555

56-
private:
56+
protected:
5757
//! Distance tolerance for the simplification
5858
double mTolerance;
5959

src/core/qgsvectordataprovider.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ QString QgsVectorDataProvider::capabilitiesString() const
194194
QgsDebugMsg( "Capability: Change Geometries" );
195195
}
196196

197+
if ( abilities & QgsVectorDataProvider::SimplifyGeometries )
198+
{
199+
abilitiesList += tr( "Simplify Geometries" );
200+
QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature" );
201+
}
202+
197203
return abilitiesList.join( ", " );
198204

199205
}

src/core/qgsvectorlayerfeatureiterator.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayer* la
7777
mProviderIterator = L->dataProvider()->getFeatures( mProviderRequest );
7878
}
7979

80+
// setup if required the local simplification of geometries to fetch
81+
prepareLocalSimplification();
82+
8083
rewindEditBuffer();
8184
}
8285

0 commit comments

Comments
 (0)