Skip to content
Permalink
Browse files

[Geometry checker] Drop feature id update logic now handled by freezi…

…ng repacking
  • Loading branch information
manisandro committed Sep 26, 2017
1 parent 767538b commit 816273ea899a88ea5fff6b2de304b514d20c13a6
@@ -57,7 +57,6 @@ QgsFeaturePool::QgsFeaturePool( QgsVectorLayer *layer, double layerToMapUnits, c
mFeatureIds.remove( feature.id() );
}
}
connect( mLayer->dataProvider(), SIGNAL( featureIdsChanged( QMap<QgsFeatureId, QgsFeatureId> ) ), this, SLOT( updateFeatureIds( QMap<QgsFeatureId, QgsFeatureId> ) ) );
}

bool QgsFeaturePool::get( QgsFeatureId id, QgsFeature &feature )
@@ -142,31 +141,3 @@ QgsFeatureIds QgsFeaturePool::getIntersects( const QgsRectangle &rect ) const
QMutexLocker lock( &mIndexMutex );
return QgsFeatureIds::fromList( mIndex.intersects( rect ) );
}

void QgsFeaturePool::updateFeatureIds( const QMap<QgsFeatureId, QgsFeatureId> &oldNewFid )
{
QList<QgsFeature *> changedFeatures;
QgsFeatureIds newIds;
for ( const QgsFeatureId &oldId : oldNewFid.keys() )
{
auto it = mFeatureIds.find( oldId );
if ( it != mFeatureIds.end() )
{
mFeatureIds.erase( it );
}
newIds.insert( oldNewFid[oldId] );
QgsFeature *feature = mFeatureCache.take( oldId );
if ( feature )
{
feature->setId( oldNewFid[oldId] );
changedFeatures.append( feature );
}
}
for ( QgsFeature *feature : changedFeatures )
{
Q_ASSERT( !mFeatureCache.contains( feature->id() ) );
mFeatureCache.insert( feature->id(), feature );
}
mFeatureIds.unite( newIds );
emit featureIdsChanged( mLayer->id(), oldNewFid );
}
@@ -45,8 +45,6 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QObject
bool getSelectedOnly() const { return mSelectedOnly; }
void clearLayer() { mLayer = nullptr; }

signals:
void featureIdsChanged( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFid );
private:
struct MapEntry
{
@@ -71,9 +69,6 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QObject
bool mSelectedOnly;

bool getTouchingWithSharedEdge( QgsFeature &feature, QgsFeatureId &touchingId, const double & ( *comparator )( const double &, const double & ), double init );

private slots:
void updateFeatureIds( const QMap<QgsFeatureId, QgsFeatureId> &oldNewFid );
};

#endif // QGS_FEATUREPOOL_H
@@ -143,17 +143,6 @@ bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &chan
return true;
}

bool QgsGeometryCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
{
if ( layerId == mLayerId )
{
QgsFeatureId oldId = mFeatureId;
mFeatureId = oldNewFidMap.value( mFeatureId, mFeatureId );
return oldId != mFeatureId;
}
return false;
}

QMap<QString, QgsFeatureIds> QgsGeometryCheck::allLayerFeatureIds() const
{
QMap<QString, QgsFeatureIds> featureIds;
@@ -160,7 +160,6 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
}

virtual bool handleChanges( const QgsGeometryCheck::Changes &changes );
virtual bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap );

protected:
// Users of this constructor must ensure geometry and errorLocation are in map coordinates
@@ -29,10 +29,6 @@ QgsGeometryChecker::QgsGeometryChecker( const QList<QgsGeometryCheck *> &checks,
: mChecks( checks )
, mContext( context )
{
for ( const QString &layerId : mContext->featurePools.keys() )
{
connect( mContext->featurePools[layerId], SIGNAL( featureIdsChanged( QString, QMap<QgsFeatureId, QgsFeatureId> ) ), this, SLOT( updateFeatureIds( QString, QMap<QgsFeatureId, QgsFeatureId> ) ) );
}
for ( const QgsFeaturePool *featurePool : mContext->featurePools.values() )
{
if ( featurePool->getLayer() )
@@ -299,14 +295,3 @@ void QgsGeometryChecker::runCheck( const QgsGeometryCheck *check )
emit errorAdded( error );
}
}

void QgsGeometryChecker::updateFeatureIds( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFid )
{
for ( QgsGeometryCheckError *error : mCheckErrors )
{
if ( error->handleFidChanges( layerId, oldNewFid ) )
{
emit errorUpdated( error, false );
}
}
}
@@ -72,7 +72,6 @@ class ANALYSIS_EXPORT QgsGeometryChecker : public QObject

private slots:
void emitProgressValue();
void updateFeatureIds( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFid );
};

#endif // QGS_GEOMETRY_CHECKER_H
@@ -18,18 +18,6 @@
#include "qgsfeaturepool.h"


bool QgsGeometryContainedCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
{
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
if ( mContainingFeature.first == layerId )
{
QgsFeatureId oldId = mContainingFeature.second;
mContainingFeature.second = oldNewFidMap.value( mContainingFeature.second, mContainingFeature.second );
changed |= ( oldId != mContainingFeature.second );
}
return changed;
}

void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
{
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;
@@ -39,7 +39,6 @@ class ANALYSIS_EXPORT QgsGeometryContainedCheckError : public QgsGeometryCheckEr
}

virtual QString description() const override { return QApplication::translate( "QgsGeometryContainedCheckError", "Within feature" ); }
bool handleFidChanges( const QString& layerId, const QMap<QgsFeatureId, QgsFeatureId>& oldNewFidMap) override;

private:
QPair<QString, QgsFeatureId> mContainingFeature;
@@ -19,23 +19,6 @@
#include "qgsgeometry.h"
#include "qgsfeaturepool.h"


bool QgsGeometryDuplicateCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
{
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
if ( mDuplicates.contains( layerId ) )
{
QList<QgsFeatureId> &fids = mDuplicates[layerId];
for ( int i = 0, n = fids.size(); i < n; ++i )
{
QgsFeatureId oldId = fids[i];
fids[i] = oldNewFidMap.value( fids[i], fids[i] );
changed |= ( oldId != fids[i] );
}
}
return changed;
}

QString QgsGeometryDuplicateCheckError::duplicatesString( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QList<QgsFeatureId>> &duplicates )
{
QStringList str;
@@ -38,7 +38,6 @@ class ANALYSIS_EXPORT QgsGeometryDuplicateCheckError : public QgsGeometryCheckEr
// static_cast: since other->checker() == checker is only true if the types are actually the same
static_cast<QgsGeometryDuplicateCheckError *>( other )->duplicates() == duplicates();
}
bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap ) override;

private:
QMap<QString, QList<QgsFeatureId>> mDuplicates;
@@ -18,30 +18,6 @@
#include "qgsgeometrycollection.h"
#include "qgsfeaturepool.h"

bool QgsGeometryGapCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
{
bool changed = false;
if ( mNeighbors.contains( layerId ) )
{
QgsFeatureIds &fids = mNeighbors[layerId];
QgsFeatureIds newIds;
for ( auto it = fids.begin(), itEnd = fids.end(); it != itEnd; ++it )
{
const QgsFeatureId &fid = *it;
QgsFeatureId newId = oldNewFidMap.value( fid, fid );
if ( fid != newId )
{
it = fids.erase( it );
newIds.insert( newId );
changed = true;
}
}
fids.unite( newIds );
}
return changed;
}


void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
@@ -66,8 +66,6 @@ class ANALYSIS_EXPORT QgsGeometryGapCheckError : public QgsGeometryCheckError
return mGapAreaBBox;
}

bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap ) override;

private:
QMap<QString, QgsFeatureIds> mNeighbors;
QgsRectangle mGapAreaBBox;
@@ -18,18 +18,6 @@
#include "qgsfeaturepool.h"


bool QgsGeometryOverlapCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
{
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
if ( mOverlappedFeature.first == layerId )
{
QgsFeatureId oldId = mOverlappedFeature.second;
mOverlappedFeature.second = oldNewFidMap.value( mOverlappedFeature.second, mOverlappedFeature.second );
changed |= ( oldId != mOverlappedFeature.second );
}
return changed;
}

void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
{
double overlapThreshold = mThresholdMapUnits;
@@ -51,7 +51,6 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
}

virtual QString description() const override { return QApplication::translate( "QgsGeometryTypeCheckError", "Overlap with %1:%2" ).arg( mOverlappedFeature.first ).arg( mOverlappedFeature.second ); }
bool handleFidChanges( const QString& layerId, const QMap<QgsFeatureId, QgsFeatureId>& oldNewFidMap) override;

private:
QPair<QString, QgsFeatureId> mOverlappedFeature;

0 comments on commit 816273e

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