Skip to content
Permalink
Browse files

QgsVectorLayerFeaturePool needs to be aware of geometry changes

  • Loading branch information
m-kuhn committed Oct 1, 2018
1 parent 76700cd commit 6df73d6d0729de95ae73f00668d8742c26f6a0a7
@@ -90,6 +90,7 @@ To be used by implementations of ``deleteFeature``.
%End



private:
QgsFeaturePool( const QgsFeaturePool &other );
};
@@ -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
@@ -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;
@@ -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 )
@@ -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 );
}
@@ -27,15 +27,21 @@ 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 );

bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr ) override;
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

0 comments on commit 6df73d6

Please sign in to comment.
You can’t perform that action at this time.