diff --git a/python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in b/python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in index 3f4eb0313c7..2186cc9f41b 100644 --- a/python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in +++ b/python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in @@ -90,6 +90,7 @@ To be used by implementations of ``deleteFeature``. %End + private: QgsFeaturePool( const QgsFeaturePool &other ); }; diff --git a/src/analysis/CMakeLists.txt b/src/analysis/CMakeLists.txt index 15d4ca11a9d..6508afcfa30 100644 --- a/src/analysis/CMakeLists.txt +++ b/src/analysis/CMakeLists.txt @@ -186,6 +186,7 @@ SET(QGIS_ANALYSIS_MOC_HDRS vector/geometry_checker/qgsgeometrychecker.h vector/geometry_checker/qgsgeometrycheck.h + vector/geometry_checker/qgsvectorlayerfeaturepool.h ) INCLUDE_DIRECTORIES(SYSTEM ${SPATIALITE_INCLUDE_DIR}) @@ -252,7 +253,6 @@ SET(QGIS_ANALYSIS_HDRS vector/geometry_checker/qgsgeometrycheckerutils.h vector/geometry_checker/qgsfeaturepool.h vector/geometry_checker/qgsvectordataproviderfeaturepool.h - vector/geometry_checker/qgsvectorlayerfeaturepool.h interpolation/qgsinterpolator.h interpolation/qgsgridfilewriter.h diff --git a/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp b/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp index b96bc5f4612..daff03ea3a5 100644 --- a/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp +++ b/src/analysis/vector/geometry_checker/qgsfeaturepool.cpp @@ -140,6 +140,11 @@ void QgsFeaturePool::setFeatureIds( const QgsFeatureIds &ids ) mFeatureIds = ids; } +bool QgsFeaturePool::isFeatureCached( QgsFeatureId fid ) +{ + return mFeatureCache.contains( fid ); +} + QgsCoordinateReferenceSystem QgsFeaturePool::crs() const { return mCrs; diff --git a/src/analysis/vector/geometry_checker/qgsfeaturepool.h b/src/analysis/vector/geometry_checker/qgsfeaturepool.h index 920ed86adb2..f80a0036ff2 100644 --- a/src/analysis/vector/geometry_checker/qgsfeaturepool.h +++ b/src/analysis/vector/geometry_checker/qgsfeaturepool.h @@ -145,6 +145,14 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT */ void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP; + /** + * Checks if the feature \a fid is cached. + * + * \since QGIS 3.4 + * \note not available in Python bindings + */ + bool isFeatureCached( QgsFeatureId fid ) SIP_SKIP; + private: #ifdef SIP_RUN QgsFeaturePool( const QgsFeaturePool &other ) diff --git a/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.cpp b/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.cpp index 0c7a8a25bab..a6027c4c0b3 100644 --- a/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.cpp +++ b/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.cpp @@ -17,29 +17,14 @@ email : matthias@opengis.ch #include "qgsthreadingutils.h" #include "qgsfeaturerequest.h" +#include "qgsvectorlayer.h" QgsVectorLayerFeaturePool::QgsVectorLayerFeaturePool( QgsVectorLayer *layer ) - : QgsFeaturePool( layer ) + : QObject() + , QgsFeaturePool( layer ) { - // Build spatial index - QgsFeature feature; - QgsFeatureRequest req; - QgsFeatureIds featureIds; - - QgsFeatureIterator it = layer->getFeatures( req ); - while ( it.nextFeature( feature ) ) - { - if ( feature.geometry() ) - { - insertFeature( feature ); - featureIds.insert( feature.id() ); - } - else - { - featureIds.remove( feature.id() ); - } - } - setFeatureIds( featureIds ); + connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayerFeaturePool::onFeatureDeleted ); + connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayerFeaturePool::onGeometryChanged ); } bool QgsVectorLayerFeaturePool::addFeature( QgsFeature &feature, Flags flags ) @@ -147,3 +132,19 @@ void QgsVectorLayerFeaturePool::deleteFeature( QgsFeatureId fid ) } } ); } + +void QgsVectorLayerFeaturePool::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geometry ) +{ + if ( isFeatureCached( fid ) ) + { + QgsFeature feature; + getFeature( fid, feature ); + feature.setGeometry( geometry ); + updateFeature( feature ); + } +} + +void QgsVectorLayerFeaturePool::onFeatureDeleted( QgsFeatureId fid ) +{ + deleteFeature( fid ); +} diff --git a/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.h b/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.h index ceda6945a70..f285cf9a9e5 100644 --- a/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.h +++ b/src/analysis/vector/geometry_checker/qgsvectorlayerfeaturepool.h @@ -27,8 +27,10 @@ email : matthias@opengis.ch * * \since QGIS 3.4 */ -class ANALYSIS_EXPORT QgsVectorLayerFeaturePool : public QgsFeaturePool +class ANALYSIS_EXPORT QgsVectorLayerFeaturePool : public QObject, public QgsFeaturePool { + Q_OBJECT + public: QgsVectorLayerFeaturePool( QgsVectorLayer *layer ); @@ -36,6 +38,10 @@ class ANALYSIS_EXPORT QgsVectorLayerFeaturePool : public QgsFeaturePool bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override; void updateFeature( QgsFeature &feature ) override; void deleteFeature( QgsFeatureId fid ) override; + + private slots: + void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geometry ); + void onFeatureDeleted( QgsFeatureId fid ); }; #endif // QGSVECTORLAYERFEATUREPOOL_H