Skip to content
Permalink
Browse files

Use pointer instead of reference to QgsVectorLayer

  • Loading branch information
m-kuhn committed Sep 10, 2018
1 parent 41184bf commit ec21166e58fdd11456f9dd531f9855b9c480a61c
@@ -50,7 +50,7 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check,
const QgsPointXY &errorLocation, QgsVertexId vidx,
const QVariant &value, ValueType valueType )
: mCheck( check )
, mLayerId( layerFeature.layer().id() )
, mLayerId( layerFeature.layer()->id() )
, mFeatureId( layerFeature.feature().id() )
, mErrorLocation( errorLocation )
, mVidx( vidx )
@@ -43,23 +43,28 @@ namespace QgsGeometryCheckerUtils
{
delete mGeometry;
}
const QgsVectorLayer &LayerFeature::layer() const { return *mFeaturePool->layer(); }

QgsVectorLayer *LayerFeature::layer() const
{
return mFeaturePool->layer();
}

double LayerFeature::layerToMapUnits() const { return mFeaturePool->getLayerToMapUnits(); }
const QgsCoordinateTransform &LayerFeature::layerToMapTransform() const { return mFeaturePool->getLayerToMapTransform(); }

QString LayerFeature::id() const
{
return QString( "%1:%2" ).arg( layer().name() ).arg( mFeature.id() );
return QString( "%1:%2" ).arg( layer()->name() ).arg( mFeature.id() );
}

bool LayerFeature::operator==( const LayerFeature &other ) const
{
return layer().id() == other.layer().id() && feature().id() == other.feature().id();
return layer()->id() == other.layer()->id() && feature().id() == other.feature().id();
}

bool LayerFeature::operator!=( const LayerFeature &other ) const
{
return layer().id() != other.layer().id() || feature().id() != other.feature().id();
return layer()->id() != other.layer()->id() || feature().id() != other.feature().id();
}

/////////////////////////////////////////////////////////////////////////////
@@ -35,7 +35,7 @@ namespace QgsGeometryCheckerUtils
LayerFeature( const QgsFeaturePool *pool, const QgsFeature &feature, bool useMapCrs );
~LayerFeature();
const QgsFeature &feature() const { return mFeature; }
const QgsVectorLayer &layer() const;
QgsVectorLayer *layer() const;
double layerToMapUnits() const;
const QgsCoordinateTransform &layerToMapTransform() const;
const QgsAbstractGeometry *geometry() const { return mGeometry; }
@@ -30,7 +30,7 @@ class ANALYSIS_EXPORT QgsGeometryContainedCheckError : public QgsGeometryCheckEr
const QgsGeometryCheckerUtils::LayerFeature &containingFeature
)
: QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), containingFeature.id(), ValueOther )
, mContainingFeature( qMakePair( containingFeature.layer().id(), containingFeature.feature().id() ) )
, mContainingFeature( qMakePair( containingFeature.layer()->id(), containingFeature.feature().id() ) )
{ }
const QPair<QString, QgsFeatureId> &containingFeature() const { return mContainingFeature; }

@@ -47,7 +47,7 @@ void QgsGeometryDangleCheck::collectErrors( QList<QgsGeometryCheckError *> &erro
}

// Check whether endpoints line on another line in the layer
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, QList<QString>() << layerFeature.layer().id(), line->boundingBox(), {QgsWkbTypes::LineGeometry} );
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, QList<QString>() << layerFeature.layer()->id(), line->boundingBox(), {QgsWkbTypes::LineGeometry} );
for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures )
{
const QgsAbstractGeometry *testGeom = checkFeature.geometry();
@@ -45,7 +45,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
{
// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
layerIds.removeOne( layerFeatureA.layer().id() );
layerIds.removeOne( layerFeatureA.layer()->id() );

QgsRectangle bboxA = layerFeatureA.geometry()->boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
@@ -57,19 +57,19 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
QMap<QString, QList<QgsFeatureId>> duplicates;

QgsWkbTypes::GeometryType geomType = layerFeatureA.feature().geometry().type();
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer().id() << layerIds, bboxA, {geomType} );
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer()->id() << layerIds, bboxA, {geomType} );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
{
// > : only report overlaps within same layer once
if ( layerFeatureA.layer().id() == layerFeatureB.layer().id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
if ( layerFeatureA.layer()->id() == layerFeatureB.layer()->id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
{
continue;
}
QString errMsg;
QgsAbstractGeometry *diffGeom = geomEngineA->symDifference( layerFeatureB.geometry(), &errMsg );
if ( errMsg.isEmpty() && diffGeom && diffGeom->isEmpty() )
{
duplicates[layerFeatureB.layer().id()].append( layerFeatureB.feature().id() );
duplicates[layerFeatureB.layer()->id()].append( layerFeatureB.feature().id() );
}
else if ( !errMsg.isEmpty() )
{
@@ -49,7 +49,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( QList<QgsGeometryCheckErro
const QgsAbstractGeometry *geom = layerFeature.geometry();

// The geometry to crs of the check layer
QgsCoordinateTransform crst( layerFeature.layer().crs(), mCheckLayer->crs(), QgsProject::instance() );
QgsCoordinateTransform crst( layerFeature.layer()->crs(), mCheckLayer->crs(), QgsProject::instance() );
QgsGeometry geomt( geom->clone() );
geomt.transform( crst );

@@ -100,7 +100,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
{
if ( QgsGeometryCheckerUtils::sharedEdgeLength( gapGeom.get(), layerFeature.geometry(), mContext->reducedTolerance ) > 0 )
{
neighboringIds[layerFeature.layer().id()].insert( layerFeature.feature().id() );
neighboringIds[layerFeature.layer()->id()].insert( layerFeature.feature().id() );
gapAreaBBox.combineExtentWith( layerFeature.geometry()->boundingBox() );
}
}
@@ -25,7 +25,7 @@ void QgsGeometryLineIntersectionCheck::collectErrors( QList<QgsGeometryCheckErro
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
{
// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
layerIds.removeOne( layerFeatureA.layer().id() );
layerIds.removeOne( layerFeatureA.layer()->id() );

const QgsAbstractGeometry *geom = layerFeatureA.geometry();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
@@ -38,11 +38,11 @@ void QgsGeometryLineIntersectionCheck::collectErrors( QList<QgsGeometryCheckErro
}

// Check whether the line intersects with any other lines
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer().id() << layerIds, line->boundingBox(), {QgsWkbTypes::LineGeometry} );
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer()->id() << layerIds, line->boundingBox(), {QgsWkbTypes::LineGeometry} );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
{
// > : only report intersections within same layer once
if ( layerFeatureA.layer().id() == layerFeatureB.layer().id() && layerFeatureB.feature().id() > layerFeatureA.feature().id() )
if ( layerFeatureA.layer()->id() == layerFeatureB.layer()->id() && layerFeatureB.feature().id() > layerFeatureA.feature().id() )
{
continue;
}
@@ -27,7 +27,7 @@ void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError *> &err
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
{
// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
layerIds.removeOne( layerFeatureA.layer().id() );
layerIds.removeOne( layerFeatureA.layer()->id() );

QgsRectangle bboxA = layerFeatureA.geometry()->boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
@@ -37,11 +37,11 @@ void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError *> &err
continue;
}

const QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer().id() << layerIds, bboxA, mCompatibleGeometryTypes );
const QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, QList<QString>() << layerFeatureA.layer()->id() << layerIds, bboxA, mCompatibleGeometryTypes );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
{
// > : only report overlaps within same layer once
if ( layerFeatureA.layer().id() == layerFeatureB.layer().id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
if ( layerFeatureA.layer()->id() == layerFeatureB.layer()->id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
{
continue;
}
@@ -30,8 +30,8 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
const QgsPointXY &errorLocation,
const QVariant &value,
const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature )
: QgsGeometryCheckError( check, layerFeature.layer().id(), layerFeature.feature().id(), geometry, errorLocation, QgsVertexId(), value, ValueArea )
, mOverlappedFeature( qMakePair( overlappedFeature.layer().id(), overlappedFeature.feature().id() ) )
: QgsGeometryCheckError( check, layerFeature.layer()->id(), layerFeature.feature().id(), geometry, errorLocation, QgsVertexId(), value, ValueArea )
, mOverlappedFeature( qMakePair( overlappedFeature.layer()->id(), overlappedFeature.feature().id() ) )
{ }
const QPair<QString, QgsFeatureId> &overlappedFeature() const { return mOverlappedFeature; }

0 comments on commit ec21166

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