diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip index d8b694979810..5e74998428d0 100644 --- a/python/core/qgsfeature.sip +++ b/python/core/qgsfeature.sip @@ -14,6 +14,8 @@ typedef QMap QgsFieldNameMap; typedef QList QgsFeatureList; +typedef QMap QgsFieldMap; + class QgsFeature { diff --git a/python/core/qgsvectordataprovider.sip b/python/core/qgsvectordataprovider.sip index d24b839ef8bc..ce65c1b3d644 100644 --- a/python/core/qgsvectordataprovider.sip +++ b/python/core/qgsvectordataprovider.sip @@ -49,46 +49,22 @@ class QgsVectorDataProvider : QgsDataProvider */ virtual QString storageType() const; - /** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature. - * @param fetchAttributes list of attributes which should be fetched - * @param rect spatial filter - * @param fetchGeometry true if the feature geometry should be fetched - * @param useIntersect true if an accurate intersection test should be used, - * false if a test based on bounding box is sufficient - */ - virtual void select( QList fetchAttributes = QList(), - QgsRectangle rect = QgsRectangle(), - bool fetchGeometry = true, - bool useIntersect = false ) = 0; - /** - * This function does nothing useful, it's kept only for compatibility. - * @todo to be removed + * Query the provider for features specified in request. */ - virtual long updateFeatureCount() /Deprecated/; + virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0; - /** - * Gets the feature at the given feature ID. - * @param featureId id of the feature - * @param feature feature which will receive the data - * @param fetchGeometry if true, geometry will be fetched from the provider - * @param fetchAttributes a list containing the indexes of the attribute fields to copy - * @return True when feature was found, otherwise false - * - * Default implementation traverses all features until it finds the one with correct ID. - * In case the provider supports reading the feature directly, override this function. - */ - virtual bool featureAtId( qint64 featureId, - QgsFeature& feature, - bool fetchGeometry = true, - QList fetchAttributes = QList()); + // temporary + QgsFeatureIterator select( QList fetchAttributes = QList(), + QgsRectangle rect = QgsRectangle(), + bool fetchGeometry = true, + bool useIntersect = false ) /Deprecated/; /** - * Get the next feature resulting from a select operation. - * @param feature feature which will receive data from the provider - * @return true when there was a feature to fetch, false when end was hit + * This function does nothing useful, it's kept only for compatibility. + * @todo to be removed */ - virtual bool nextFeature( QgsFeature& feature ) = 0; + virtual long updateFeatureCount() /Deprecated/; /** * Get feature type. @@ -120,9 +96,6 @@ class QgsVectorDataProvider : QgsDataProvider */ virtual QString dataComment() const; - /** Restart reading features from previous select operation */ - virtual void rewind() = 0; - /** * Returns the minimum value of an attribute * @param index the index of the attribute diff --git a/src/core/composer/qgsatlascomposition.cpp b/src/core/composer/qgsatlascomposition.cpp index 96ca5db949d0..79dba823b680 100644 --- a/src/core/composer/qgsatlascomposition.cpp +++ b/src/core/composer/qgsatlascomposition.cpp @@ -69,9 +69,7 @@ void QgsAtlasComposition::beginRender() mTransform.setSourceCrs( coverage_crs ); mTransform.setDestCRS( destination_crs ); - QgsVectorDataProvider* provider = mCoverageLayer->dataProvider(); - - QgsFieldMap fieldmap = provider->fields(); + QgsFieldMap fieldmap = mCoverageLayer->pendingFields(); if ( mFilenamePattern.size() > 0 ) { @@ -88,12 +86,12 @@ void QgsAtlasComposition::beginRender() } // select all features with all attributes - provider->select( provider->attributeIndexes() ); + mCoverageLayer->select( mCoverageLayer->pendingAllAttributesList() ); // We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process // We thus store the feature ids for future extraction QgsFeature feat; - while ( provider->nextFeature( feat ) ) + while ( mCoverageLayer->nextFeature( feat ) ) { mFeatureIds.push_back( feat.id() ); } @@ -115,7 +113,7 @@ void QgsAtlasComposition::beginRender() // special columns for expressions QgsExpression::setSpecialColumn( "$numpages", QVariant( mComposition->numPages() ) ); - QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )provider->featureCount() ) ); + QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mCoverageLayer->pendingFeatureCount() ) ); } void QgsAtlasComposition::endRender() @@ -161,9 +159,8 @@ void QgsAtlasComposition::prepareForFeature( size_t featureI ) return; } - QgsVectorDataProvider* provider = mCoverageLayer->dataProvider(); // retrieve the next feature, based on its id - provider->featureAtId( mFeatureIds[ featureI ], mCurrentFeature, /* fetchGeometry = */ true, provider->attributeIndexes() ); + mCoverageLayer->featureAtId( mFeatureIds[ featureI ], mCurrentFeature, /* fetchGeometry = */ true, /* fetchAttributes = */ true ); if ( mFilenamePattern.size() > 0 ) { diff --git a/tests/src/core/testqgscomposerlabel.cpp b/tests/src/core/testqgscomposerlabel.cpp index 56db37fa9ae3..0b82d2e31056 100644 --- a/tests/src/core/testqgscomposerlabel.cpp +++ b/tests/src/core/testqgscomposerlabel.cpp @@ -125,13 +125,11 @@ void TestQgsComposerLabel::evaluation() void TestQgsComposerLabel::feature_evaluation() { - QgsVectorDataProvider* provider = mVectorLayer->dataProvider(); - - QgsAttributeList allAttrs = provider->attributeIndexes(); - provider->select( allAttrs ); + QgsAttributeList allAttrs = mVectorLayer->pendingAllAttributesList(); + mVectorLayer->select( allAttrs ); QgsFeature feat; - provider->nextFeature( feat ); + mVectorLayer->nextFeature( feat ); { // evaluation with a feature mComposerLabel->setExpressionContext( &feat, mVectorLayer ); @@ -140,7 +138,7 @@ void TestQgsComposerLabel::feature_evaluation() QString expected = "Basse-Normandie_ok"; QCOMPARE( evaluated, expected ); } - provider->nextFeature( feat ); + mVectorLayer->nextFeature( feat ); { // evaluation with a feature mComposerLabel->setExpressionContext( &feat, mVectorLayer );