Skip to content
Permalink
Browse files

Resolve some TODOs

  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent 128a226 commit 3f42395baa653cb08877b8b3ec7e657420f3b1ab
Showing with 24 additions and 6 deletions.
  1. +19 −5 src/app/qgsgeometryvalidationmodel.cpp
  2. +5 −1 src/app/qgsgeometryvalidationmodel.h
@@ -78,7 +78,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
case DetailsRole:
{
const QgsFeatureId fid = topologyError->featureId();
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
const QgsFeature feature = getFeature( fid );
mExpressionContext.setFeature( feature );
const QVariant featureTitle = mDisplayExpression.evaluate( &mExpressionContext );

@@ -97,7 +97,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
const QgsFeatureId fid = topologyError->featureId();
if ( FID_IS_NULL( fid ) )
return QgsRectangle();
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
const QgsFeature feature = getFeature( fid );
return feature.geometry().boundingBox();
}

@@ -121,7 +121,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
const QgsFeatureId fid = topologyError->featureId();
if ( !FID_IS_NULL( fid ) )
{
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
const QgsFeature feature = getFeature( fid );
return feature.geometry();
}
return QgsGeometry();
@@ -147,7 +147,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
{
case Qt::DisplayRole:
{
QgsFeature feature = mCurrentLayer->getFeature( featureItem.fid ); // TODO: this should be cached!
QgsFeature feature = getFeature( featureItem.fid );
mExpressionContext.setFeature( feature );
QString featureTitle = mDisplayExpression.evaluate( &mExpressionContext ).toString();
if ( featureTitle.isEmpty() )
@@ -185,7 +185,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )

case FeatureExtentRole:
{
return mCurrentLayer->getFeature( featureItem.fid ).geometry().boundingBox();
return getFeature( featureItem.fid ).geometry().boundingBox();
}

case ErrorLocationGeometryRole:
@@ -232,11 +232,13 @@ void QgsGeometryValidationModel::setCurrentLayer( QgsVectorLayer *currentLayer )

beginResetModel();
mCurrentLayer = currentLayer;
mCachedFeature.setValid( false );
if ( mCurrentLayer )
{
mDisplayExpression = mCurrentLayer ? mCurrentLayer->displayExpression() : QString();
mExpressionContext = QgsExpressionContext( QgsExpressionContextUtils::globalProjectLayerScopes( mCurrentLayer ) );
mDisplayExpression.prepare( &mExpressionContext );
mRequiredAttributes = mDisplayExpression.referencedColumns().toList();
}
else
{
@@ -375,3 +377,15 @@ int QgsGeometryValidationModel::errorsForFeature( QgsVectorLayer *layer, QgsFeat
}
return -1;
}

QgsFeature QgsGeometryValidationModel::getFeature( QgsFeatureId fid ) const
{
if ( fid != mCachedFeature.id() || !mCachedFeature.isValid() )
{
QgsFeatureRequest request;
request.setFilterFid( fid );
request.setSubsetOfAttributes( mRequiredAttributes, mCurrentLayer->fields() );
mCachedFeature = mCurrentLayer->getFeature( fid );
}
return mCachedFeature;
}
@@ -68,19 +68,23 @@ class QgsGeometryValidationModel : public QAbstractItemModel
: fid( fid )
{}

QgsFeatureId fid; // TODO INITIALIZE PROPERLY
QgsFeatureId fid = FID_NULL;
QList<std::shared_ptr<QgsSingleGeometryCheckError>> errors;
};

int errorsForFeature( QgsVectorLayer *layer, QgsFeatureId fid );

QgsFeature getFeature( QgsFeatureId fid ) const;

QgsGeometryValidationService *mGeometryValidationService = nullptr;
QgsVectorLayer *mCurrentLayer = nullptr;
mutable QgsExpression mDisplayExpression;
mutable QStringList mRequiredAttributes;
mutable QgsExpressionContext mExpressionContext;

QMap<QgsVectorLayer *, QList< FeatureErrors > > mErrorStorage;
QMap<QgsVectorLayer *, QList< std::shared_ptr< QgsGeometryCheckError > > > mTopologyErrorStorage;
mutable QgsFeature mCachedFeature;
};

#endif // QGSGEOMETRYVALIDATIONMODEL_H

0 comments on commit 3f42395

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