Skip to content

Commit 6df73d6

Browse files
committedOct 15, 2018
QgsVectorLayerFeaturePool needs to be aware of geometry changes
1 parent 76700cd commit 6df73d6

File tree

6 files changed

+43
-22
lines changed

6 files changed

+43
-22
lines changed
 

‎python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ To be used by implementations of ``deleteFeature``.
9090
%End
9191

9292

93+
9394
private:
9495
QgsFeaturePool( const QgsFeaturePool &other );
9596
};

‎src/analysis/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ SET(QGIS_ANALYSIS_MOC_HDRS
186186

187187
vector/geometry_checker/qgsgeometrychecker.h
188188
vector/geometry_checker/qgsgeometrycheck.h
189+
vector/geometry_checker/qgsvectorlayerfeaturepool.h
189190
)
190191

191192
INCLUDE_DIRECTORIES(SYSTEM ${SPATIALITE_INCLUDE_DIR})
@@ -252,7 +253,6 @@ SET(QGIS_ANALYSIS_HDRS
252253
vector/geometry_checker/qgsgeometrycheckerutils.h
253254
vector/geometry_checker/qgsfeaturepool.h
254255
vector/geometry_checker/qgsvectordataproviderfeaturepool.h
255-
vector/geometry_checker/qgsvectorlayerfeaturepool.h
256256

257257
interpolation/qgsinterpolator.h
258258
interpolation/qgsgridfilewriter.h

‎src/analysis/vector/geometry_checker/qgsfeaturepool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ void QgsFeaturePool::setFeatureIds( const QgsFeatureIds &ids )
140140
mFeatureIds = ids;
141141
}
142142

143+
bool QgsFeaturePool::isFeatureCached( QgsFeatureId fid )
144+
{
145+
return mFeatureCache.contains( fid );
146+
}
147+
143148
QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
144149
{
145150
return mCrs;

‎src/analysis/vector/geometry_checker/qgsfeaturepool.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
145145
*/
146146
void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;
147147

148+
/**
149+
* Checks if the feature \a fid is cached.
150+
*
151+
* \since QGIS 3.4
152+
* \note not available in Python bindings
153+
*/
154+
bool isFeatureCached( QgsFeatureId fid ) SIP_SKIP;
155+
148156
private:
149157
#ifdef SIP_RUN
150158
QgsFeaturePool( const QgsFeaturePool &other )

‎src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,14 @@ email : matthias@opengis.ch
1717
#include "qgsthreadingutils.h"
1818

1919
#include "qgsfeaturerequest.h"
20+
#include "qgsvectorlayer.h"
2021

2122
QgsVectorLayerFeaturePool::QgsVectorLayerFeaturePool( QgsVectorLayer *layer )
22-
: QgsFeaturePool( layer )
23+
: QObject()
24+
, QgsFeaturePool( layer )
2325
{
24-
// Build spatial index
25-
QgsFeature feature;
26-
QgsFeatureRequest req;
27-
QgsFeatureIds featureIds;
28-
29-
QgsFeatureIterator it = layer->getFeatures( req );
30-
while ( it.nextFeature( feature ) )
31-
{
32-
if ( feature.geometry() )
33-
{
34-
insertFeature( feature );
35-
featureIds.insert( feature.id() );
36-
}
37-
else
38-
{
39-
featureIds.remove( feature.id() );
40-
}
41-
}
42-
setFeatureIds( featureIds );
26+
connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayerFeaturePool::onFeatureDeleted );
27+
connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayerFeaturePool::onGeometryChanged );
4328
}
4429

4530
bool QgsVectorLayerFeaturePool::addFeature( QgsFeature &feature, Flags flags )
@@ -147,3 +132,19 @@ void QgsVectorLayerFeaturePool::deleteFeature( QgsFeatureId fid )
147132
}
148133
} );
149134
}
135+
136+
void QgsVectorLayerFeaturePool::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geometry )
137+
{
138+
if ( isFeatureCached( fid ) )
139+
{
140+
QgsFeature feature;
141+
getFeature( fid, feature );
142+
feature.setGeometry( geometry );
143+
updateFeature( feature );
144+
}
145+
}
146+
147+
void QgsVectorLayerFeaturePool::onFeatureDeleted( QgsFeatureId fid )
148+
{
149+
deleteFeature( fid );
150+
}

‎src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ email : matthias@opengis.ch
2727
*
2828
* \since QGIS 3.4
2929
*/
30-
class ANALYSIS_EXPORT QgsVectorLayerFeaturePool : public QgsFeaturePool
30+
class ANALYSIS_EXPORT QgsVectorLayerFeaturePool : public QObject, public QgsFeaturePool
3131
{
32+
Q_OBJECT
33+
3234
public:
3335
QgsVectorLayerFeaturePool( QgsVectorLayer *layer );
3436

3537
bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr ) override;
3638
bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override;
3739
void updateFeature( QgsFeature &feature ) override;
3840
void deleteFeature( QgsFeatureId fid ) override;
41+
42+
private slots:
43+
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geometry );
44+
void onFeatureDeleted( QgsFeatureId fid );
3945
};
4046

4147
#endif // QGSVECTORLAYERFEATUREPOOL_H

0 commit comments

Comments
 (0)
Please sign in to comment.