Skip to content

Commit 3f42395

Browse files
committed
Resolve some TODOs
1 parent 128a226 commit 3f42395

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/app/qgsgeometryvalidationmodel.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
7878
case DetailsRole:
7979
{
8080
const QgsFeatureId fid = topologyError->featureId();
81-
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
81+
const QgsFeature feature = getFeature( fid );
8282
mExpressionContext.setFeature( feature );
8383
const QVariant featureTitle = mDisplayExpression.evaluate( &mExpressionContext );
8484

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

@@ -121,7 +121,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
121121
const QgsFeatureId fid = topologyError->featureId();
122122
if ( !FID_IS_NULL( fid ) )
123123
{
124-
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
124+
const QgsFeature feature = getFeature( fid );
125125
return feature.geometry();
126126
}
127127
return QgsGeometry();
@@ -147,7 +147,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
147147
{
148148
case Qt::DisplayRole:
149149
{
150-
QgsFeature feature = mCurrentLayer->getFeature( featureItem.fid ); // TODO: this should be cached!
150+
QgsFeature feature = getFeature( featureItem.fid );
151151
mExpressionContext.setFeature( feature );
152152
QString featureTitle = mDisplayExpression.evaluate( &mExpressionContext ).toString();
153153
if ( featureTitle.isEmpty() )
@@ -185,7 +185,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
185185

186186
case FeatureExtentRole:
187187
{
188-
return mCurrentLayer->getFeature( featureItem.fid ).geometry().boundingBox();
188+
return getFeature( featureItem.fid ).geometry().boundingBox();
189189
}
190190

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

233233
beginResetModel();
234234
mCurrentLayer = currentLayer;
235+
mCachedFeature.setValid( false );
235236
if ( mCurrentLayer )
236237
{
237238
mDisplayExpression = mCurrentLayer ? mCurrentLayer->displayExpression() : QString();
238239
mExpressionContext = QgsExpressionContext( QgsExpressionContextUtils::globalProjectLayerScopes( mCurrentLayer ) );
239240
mDisplayExpression.prepare( &mExpressionContext );
241+
mRequiredAttributes = mDisplayExpression.referencedColumns().toList();
240242
}
241243
else
242244
{
@@ -375,3 +377,15 @@ int QgsGeometryValidationModel::errorsForFeature( QgsVectorLayer *layer, QgsFeat
375377
}
376378
return -1;
377379
}
380+
381+
QgsFeature QgsGeometryValidationModel::getFeature( QgsFeatureId fid ) const
382+
{
383+
if ( fid != mCachedFeature.id() || !mCachedFeature.isValid() )
384+
{
385+
QgsFeatureRequest request;
386+
request.setFilterFid( fid );
387+
request.setSubsetOfAttributes( mRequiredAttributes, mCurrentLayer->fields() );
388+
mCachedFeature = mCurrentLayer->getFeature( fid );
389+
}
390+
return mCachedFeature;
391+
}

src/app/qgsgeometryvalidationmodel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,23 @@ class QgsGeometryValidationModel : public QAbstractItemModel
6868
: fid( fid )
6969
{}
7070

71-
QgsFeatureId fid; // TODO INITIALIZE PROPERLY
71+
QgsFeatureId fid = FID_NULL;
7272
QList<std::shared_ptr<QgsSingleGeometryCheckError>> errors;
7373
};
7474

7575
int errorsForFeature( QgsVectorLayer *layer, QgsFeatureId fid );
7676

77+
QgsFeature getFeature( QgsFeatureId fid ) const;
78+
7779
QgsGeometryValidationService *mGeometryValidationService = nullptr;
7880
QgsVectorLayer *mCurrentLayer = nullptr;
7981
mutable QgsExpression mDisplayExpression;
82+
mutable QStringList mRequiredAttributes;
8083
mutable QgsExpressionContext mExpressionContext;
8184

8285
QMap<QgsVectorLayer *, QList< FeatureErrors > > mErrorStorage;
8386
QMap<QgsVectorLayer *, QList< std::shared_ptr< QgsGeometryCheckError > > > mTopologyErrorStorage;
87+
mutable QgsFeature mCachedFeature;
8488
};
8589

8690
#endif // QGSGEOMETRYVALIDATIONMODEL_H

0 commit comments

Comments
 (0)