QgsVectorLayerFeaturePool needs to be aware of geometry changes

This commit is contained in:
Matthias Kuhn 2018-10-01 18:11:42 +02:00
parent 76700cda71
commit 6df73d6d07
No known key found for this signature in database
GPG Key ID: 7A7F1A1C90C3E6A7
6 changed files with 43 additions and 22 deletions

View File

@ -90,6 +90,7 @@ To be used by implementations of ``deleteFeature``.
%End
private:
QgsFeaturePool( const QgsFeaturePool &other );
};

View File

@ -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

View File

@ -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;

View File

@ -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 )

View File

@ -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 );
}

View File

@ -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