32 QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
51 if ( L->editBuffer()->addedFeatures().contains( request.filterFid() ) )
52 mAddedFeatures.
insert( request.filterFid(), L->editBuffer()->addedFeatures()[ request.filterFid()] );
54 if ( L->editBuffer()->changedGeometries().contains( request.filterFid() ) )
57 if ( L->editBuffer()->deletedFeatureIds().contains( request.filterFid() ) )
60 if ( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
63 if ( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
64 mChangedFeaturesRequest.setFilterFids(
QgsFeatureIds() << request.filterFid() );
97 , mFetchedFid( false )
98 , mInterruptionChecker( nullptr )
135 Q_FOREACH (
int attrIndex, subset )
137 if ( attrIndex < 0 || attrIndex >= nPendingFields )
continue;
182 changedIds << attIt.key();
358 mInterruptionChecker = interruptionChecker;
512 int sourceLayerIndex;
514 Q_ASSERT( joinInfo );
517 Q_ASSERT( joinLayer );
547 mFetchJoinInfo[ joinInfo ].attributes.push_back( sourceLayerIndex );
576 if ( !mPreparedFields.
contains( dependentFieldIdx ) && !mFieldsToPrepare.
contains( dependentFieldIdx ) )
577 mFieldsToPrepare << dependentFieldIdx;
588 mPreparedFields.
clear();
589 mFieldsToPrepare.
clear();
599 while ( !mFieldsToPrepare.
isEmpty() )
601 int fieldIdx = mFieldsToPrepare.
takeFirst();
602 if ( mPreparedFields.
contains( fieldIdx ) )
605 mPreparedFields << fieldIdx;
638 Q_ASSERT( joinIt.
key() );
641 if ( !targetFieldValue.isValid() )
671 fetchedVirtualAttributes << joinIt->targetField;
684 if ( fetchedVirtualAttributes.
contains( it.
key() ) )
695 mExpressionContext->setFeature( f );
703 Q_UNUSED( simplifyMethod );
709 Q_UNUSED( methodType );
721 int index = indexOffset;
724 for (
int i = 0; i < featureAttributes.
count(); ++i )
738 if ( joinInfo->joinFieldName.isEmpty() && joinInfo->joinFieldIndex >= 0 && joinInfo->joinFieldIndex < joinLayer->fields().count() )
739 joinFieldName = joinLayer->fields().field( joinInfo->joinFieldIndex ).name();
741 joinFieldName = joinInfo->joinFieldName;
743 subsetString.
append(
QString(
"\"%1\"" ).arg( joinFieldName ) );
747 subsetString +=
" IS NULL";
752 switch ( joinValue.
type() )
755 case QVariant::LongLong:
756 case QVariant::Double:
760 case QVariant::String:
765 subsetString +=
'=' + v;
770 bool hasSubset = joinInfo->joinFieldNamesSubset();
787 int index = indexOffset;
791 for (
int i = 0; i < subsetIndices.
count(); ++i )
797 for (
int i = 0; i < attr.
count(); ++i )
799 if ( i == joinField )
833 if ( iter->id() == featureId )
875 for ( QgsAttributeMap::const_iterator it = map.
begin(); it != map.
end(); ++it )
876 attrs[it.key()] = it.
value();
889 Q_UNUSED( orderBys );
void setAreaUnits(QgsUnitTypes::AreaUnit unit)
Sets the desired areal units for calculations involving geomCalculator(), eg "$area".
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
QgsAbstractFeatureSource * mProviderFeatureSource
Class for parsing and evaluation of expressions (formerly called "search strings").
void addJoinedAttributesDirect(QgsFeature &f, const QVariant &joinValue) const
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
long limit() const
Returns the maximum number of features to request, or -1 if no limit set.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
QSet< QString > CORE_EXPORT usedAttributes() const
Returns a set of used attributes.
bool fetchNextAddedFeature(QgsFeature &f)
QString & append(QChar ch)
QgsVectorLayerJoinBuffer * mJoinBuffer
bool containsJoins() const
Quick way to test if there is any join at all.
QString joinFieldName
Join field in the source layer.
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
QgsAttributes attributes() const
Returns the feature's attributes.
virtual void setInterruptionChecker(QgsInterruptionChecker *interruptionChecker) override
Attach an object that can be queried regularly by the iterator to check if it must stopped...
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
bool fetchNextChangedGeomFeature(QgsFeature &f)
QString targetFieldName
Join field in the target layer.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
const Flags & flags() const
QgsFeatureIterator mProviderIterator
void addJoinedAttributes(QgsFeature &f)
void addExpressionAttribute(QgsFeature &f, int attrIndex)
Adds an expression based attribute to a feature.
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
bool exists(int i) const
Return if a field index is valid.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QSet< QgsFeatureId > QgsFeatureIds
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
QStringList referencedColumns() const
Get list of columns referenced by the expression.
QString & prepend(QChar ch)
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
QgsVectorLayerFeatureIterator(QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request)
QgsExpressionContext * expressionContext()
Returns the expression context used to evaluate filter expressions.
int joinFieldIndex
Join field index in the source layer.
const QgsVectorJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
const_iterator constBegin() const
QgsFeatureId filterFid() const
Get the feature ID that should be fetched.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool convertCompatible(QVariant &v) const
Converts the provided variant to a compatible format.
FilterType filterType() const
Return the filter type which is currently set on this request.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QMap< int, QgsExpression * > mExpressionFieldInfo
~QgsVectorLayerFeatureIterator()
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
QList< QgsField > mAddedAttributes
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
bool setEllipsoid(const QString &ellipsoid)
Sets ellipsoid by its acronym.
bool mClosed
Set to true, as soon as the iterator is closed.
int targetFieldIndex
Join field index in the target layer.
const_iterator insert(const T &value)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsVectorLayer * joinLayer
resolved pointer to the joined layer
const QgsRectangle & filterRect() const
Get the rectangle from which features will be taken.
int count() const
Return number of items.
const QList< ExpressionField > & expressions() const
it has not been specified where the field comes from
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QMap< const QgsVectorJoinInfo *, FetchJoinInfo > mFetchJoinInfo
Information about joins used in the current select() statement.
QgsFields fields() const
Returns the list of fields of this layer.
int joinedFieldsOffset(const QgsVectorJoinInfo *info, const QgsFields &fields)
Find out what is the first index of the join within fields.
int joinField
index of field (of the joined layer) must have equal value
QgsFeatureRequest mChangedFeaturesRequest
QgsExpression * filterExpression() const
Returns the filter expression if set.
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
virtual QgsAbstractFeatureSource * featureSource() const =0
Return feature source object that can be used for querying provider's data.
Interface that can be optionaly attached to an iterator so its nextFeature() implementaton can check ...
void updateChangedAttributes(QgsFeature &f)
Update feature with uncommited attribute updates.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
int count(const T &value) const
bool fetchNextChangedAttributeFeature(QgsFeature &f)
void iteratorClosed()
to be called by from subclass in close()
QgsVectorLayerFeatureSource * mSource
void useAddedFeature(const QgsFeature &src, QgsFeature &f)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
const_iterator constEnd() const
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
const QgsVectorJoinInfo * joinInfo
cannonical source of information about the join
QgsFeatureRequest & disableFilter()
Disables filter conditions.
void updateFeatureGeometry(QgsFeature &f)
Update feature with uncommited geometry updates.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod) override
Setup the simplification of geometries to fetch using the specified simplify method.
friend class QgsVectorLayerFeatureIterator
void addJoinedAttributesCached(QgsFeature &f, const QVariant &joinValue) const
const_iterator constEnd() const
virtual bool fetchFeature(QgsFeature &feature) override
fetch next feature, return true on success
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
QgsFeatureRequest mProviderRequest
const QgsFeatureIds deletedFeatureIds()
void prepareExpression(int fieldIdx)
Obsolete, will be ignored. If a filterRect is set it will be used anyway. Filter using a rectangle...
QgsGeometryMap mChangedGeometries
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
QgsFeatureIds mDeletedFeatureIds
QgsAttributeList mDeletedAttributeIds
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
QgsExpressionFieldBuffer * mExpressionFieldBuffer
void prepareField(int fieldIdx)
Q_DECL_DEPRECATED void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
const QList< QgsField > & addedAttributes()
Added attributes fields which are not commited.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QSet< QgsFeatureId > mFetchConsidered
const T value(const Key &key) const
QgsFeatureId id() const
Get the feature ID for this feature.
QgsAttributeList subsetOfAttributes() const
Return the subset of attributes which at least need to be fetched.
iterator find(const Key &key)
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name also looks up case-insensitive if there is no match otherwise...
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
bool nextFeatureFid(QgsFeature &f)
bool contains(const T &value) const
QgsVectorLayerFeatureSource(QgsVectorLayer *layer)
bool contains(const T &value) const
int indexOffset
at what position the joined fields start
void useChangedAttributeFeature(QgsFeatureId fid, const QgsGeometry &geom, QgsFeature &f)
const QgsFeatureMap & addedFeatures()
New features which are not commited.
const Key key(const T &value) const
General purpose distance and area calculator.
void setValid(bool validity)
Sets the validity of the feature.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QString & replace(int position, int n, QChar after)
QgsFeatureRequest mRequest
A copy of the feature request.
const T & at(int i) const
int targetField
index of field (of this layer) that drives the join
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
~QgsVectorLayerFeatureSource()
Buffers information about expression fields for a vector layer.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QHash< QString, QgsAttributes > cachedAttributes
Cache for joined attributes to provide fast lookup (size is 0 if no memory caching) ...
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Set feature IDs that should be fetched.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request) override
Get an iterator for features matching the specified request.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QgsFeatureMap mAddedFeatures
virtual bool rewind() override
reset the iterator to the starting position
static QgsProject * instance()
Returns the QgsProject singleton instance.
virtual bool close() override
end of iterating: free the resources / lock
static QVector< int > joinSubsetIndices(QgsVectorLayer *joinLayer, const QStringList &joinFieldsSubset)
Return a vector of indices for use in join based on field names from the layer.
int count(const T &value) const
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
void setDistanceUnits(QGis::UnitType unit)
Sets the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perim...
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
void setGeomCalculator(const QgsDistanceArea &calc)
Sets the geometry calculator used for distance and area calculations in expressions.
QList< T > toList() const
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
iterator insert(const Key &key, const T &value)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)=0
Get an iterator for features matching the specified request.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool nextFeature(QgsFeature &f)
long srsid() const
Returns the SrsId, if available.
bool mHasVirtualAttributes
QgsChangedAttributesMap mChangedAttributeValues
OrderBy orderBy() const
Return a list of order by clauses specified for this feature request.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
void prepareJoin(int fieldIdx)
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
const QgsAttributeList & deletedAttributeIds()
Deleted attributes fields which are not commited.
field is calculated from an expression
QString joinLayerId
Source layer.
bool isClosed() const
find out whether the iterator is still valid or closed already
void createJoinCaches()
Caches joined attributes if required (and not already done)
void setInterruptionChecker(QgsInterruptionChecker *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped...
void setEllipsoidalMode(bool flag)
Sets whether coordinates must be projected to ellipsoid before measuring.
QgsVectorLayerJoinBuffer * clone() const
Create a copy of the join buffer.
void addVirtualAttributes(QgsFeature &f)
Adds attributes that don't source from the provider but are added inside QGIS Includes.
QgsFeatureIterator mChangedFeaturesIterator
Helper template that cares of two things: 1.
const T value(const Key &key) const