mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
QgsVectorLayerFeaturePool needs to be aware of geometry changes
This commit is contained in:
parent
76700cda71
commit
6df73d6d07
@ -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,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user