Skip to content

Commit

Permalink
Resolve some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent 128a226 commit 3f42395
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/app/qgsgeometryvalidationmodel.cpp
Expand Up @@ -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 );

Expand All @@ -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();
}

Expand All @@ -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();
Expand All @@ -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() )
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion src/app/qgsgeometryvalidationmodel.h
Expand Up @@ -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.