QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsvectorlayerfeatureiterator.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerfeatureiterator.cpp
3  ---------------------
4  begin : Dezember 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
16 
18 #include "qgsgeometrysimplifier.h"
19 #include "qgsmaplayerregistry.h"
20 #include "qgssimplifymethod.h"
21 #include "qgsvectordataprovider.h"
23 #include "qgsvectorlayer.h"
25 
27 {
29  mFields = layer->pendingFields();
32 
33  mCanBeSimplified = layer->hasGeometryType() && layer->geometryType() != QGis::Point;
34 
35  mHasEditBuffer = layer->editBuffer();
36  if ( mHasEditBuffer )
37  {
38 #if 0
39  // TODO[MD]: after merge
40  if ( request.filterType() == QgsFeatureRequest::FilterFid )
41  {
42 
43  // only copy relevant parts
44  if ( L->editBuffer()->addedFeatures().contains( request.filterFid() ) )
45  mAddedFeatures.insert( request.filterFid(), L->editBuffer()->addedFeatures()[ request.filterFid()] );
46 
47  if ( L->editBuffer()->changedGeometries().contains( request.filterFid() ) )
48  mChangedGeometries.insert( request.filterFid(), L->editBuffer()->changedGeometries()[ request.filterFid()] );
49 
50  if ( L->editBuffer()->deletedFeatureIds().contains( request.filterFid() ) )
51  mDeletedFeatureIds.insert( request.filterFid() );
52 
53  if ( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
54  mChangedAttributeValues.insert( request.filterFid(), L->editBuffer()->changedAttributeValues()[ request.filterFid()] );
55 
56  if ( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
57  mChangedFeaturesRequest.setFilterFids( QgsFeatureIds() << request.filterFid() );
58  }
59  else
60  {
61 #endif
66  mAddedAttributes = QList<QgsField>( layer->editBuffer()->addedAttributes() );
68 #if 0
69  }
70 #endif
71  }
72 }
73 
75 {
76  delete mJoinBuffer;
79 }
80 
82 {
83  // return feature iterator that does not own this source
84  return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( this, false, request ) );
85 }
86 
87 
89  : QgsAbstractFeatureIteratorFromSource( source, ownSource, request )
90  , mEditGeometrySimplifier( 0 )
91 {
92 
93  // prepare joins: may add more attributes to fetch (in order to allow join)
95  prepareJoins();
96 
98 
99  // by default provider's request is the same
101 
103  {
104  // prepare list of attributes to match provider fields
105  QgsAttributeList providerSubset;
107  int nPendingFields = mSource->mFields.count();
108  for ( int i = 0; i < subset.count(); ++i )
109  {
110  int attrIndex = subset[i];
111  if ( attrIndex < 0 || attrIndex >= nPendingFields ) continue;
112  if ( mSource->mFields.fieldOrigin( attrIndex ) == QgsFields::OriginProvider )
113  providerSubset << mSource->mFields.fieldOriginIndex( attrIndex );
114  }
115  mProviderRequest.setSubsetOfAttributes( providerSubset );
116  }
117 
118  if ( mSource->mHasEditBuffer )
119  {
122  }
123 
124  if ( request.filterType() == QgsFeatureRequest::FilterFid )
125  {
126  mFetchedFid = false;
127  }
128  else // no filter or filter by rect
129  {
130  if ( mSource->mHasEditBuffer )
131  {
133  }
134  else
135  {
137  }
138 
140  }
141 
143  {
145  }
146 }
147 
148 
150 {
153 
154  qDeleteAll( mExpressionFieldInfo.values() );
155 
156  close();
157 }
158 
159 
160 
162 {
163  f.setValid( false );
164 
165  if ( mClosed )
166  return false;
167 
169  {
170  if ( mFetchedFid )
171  return false;
172  bool res = nextFeatureFid( f );
173  mFetchedFid = true;
174  return res;
175  }
176 
178  {
179  if ( fetchNextChangedGeomFeature( f ) )
180  return true;
181 
182  // no more changed geometries
183  }
184 
186  {
188  return true;
189 
190  // no more changed features
191  }
192 
193  while ( fetchNextAddedFeature( f ) )
194  {
195  return true;
196  }
197  // no more added features
198 
199  if ( mProviderIterator.isClosed() )
200  {
203  }
204 
205  while ( mProviderIterator.nextFeature( f ) )
206  {
207  if ( mFetchConsidered.contains( f.id() ) )
208  continue;
209 
210  // TODO[MD]: just one resize of attributes
211  f.setFields( &mSource->mFields );
212 
213  // update attributes
215 
217 
218  // update geometry
219  // TODO[MK]: FilterRect check after updating the geometry
222 
223  return true;
224  }
225  // no more provider features
226 
227  close();
228  return false;
229 }
230 
231 
232 
234 {
235  if ( mClosed )
236  return false;
237 
239  {
240  mFetchedFid = false;
241  }
242  else
243  {
246  }
247 
248  return true;
249 }
250 
252 {
253  if ( mClosed )
254  return false;
255 
257 
258  iteratorClosed();
259 
260  mClosed = true;
261  return true;
262 }
263 
264 
265 
266 
268 {
269  while ( mFetchAddedFeaturesIt-- != mSource->mAddedFeatures.constBegin() )
270  {
272 
273  if ( mFetchConsidered.contains( fid ) )
274  // must have changed geometry outside rectangle
275  continue;
276 
278  // skip features which are not accepted by the filter
279  continue;
280 
282 
283  return true;
284  }
285 
287  return false; // no more added features
288 }
289 
290 
292 {
293  f.setFeatureId( src.id() );
294  f.setValid( true );
295  f.setFields( &mSource->mFields );
296 
297  if ( src.geometry() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
298  {
299  f.setGeometry( *src.geometry() );
300 
301  // simplify the edited geometry using its simplifier configured
303  {
304  QgsGeometry* geometry = f.geometry();
305  QGis::GeometryType geometryType = geometry->type();
306  if ( geometryType == QGis::Line || geometryType == QGis::Polygon ) mEditGeometrySimplifier->simplifyGeometry( geometry );
307  }
308  }
309 
310  // TODO[MD]: if subset set just some attributes
311 
312  f.setAttributes( src.attributes() );
313 
315 }
316 
317 
318 
320 {
321  // check if changed geometries are in rectangle
323  {
324  QgsFeatureId fid = mFetchChangedGeomIt.key();
325 
326  if ( mFetchConsidered.contains( fid ) )
327  // skip deleted features
328  continue;
329 
330  mFetchConsidered << fid;
331 
332  if ( !mFetchChangedGeomIt->intersects( mRequest.filterRect() ) )
333  // skip changed geometries not in rectangle and don't check again
334  continue;
335 
337 
338  // return complete feature
340  return true;
341  }
342 
343  return false; // no more changed geometries
344 }
345 
347 {
349  {
350  mFetchConsidered << f.id();
351 
353 
355 
357  {
358  if ( mRequest.filterExpression()->evaluate( &f ).toBool() )
359  {
360  return true;
361  }
362  }
363  else
364  {
365  return true;
366  }
367  }
368 
369  return false;
370 }
371 
372 
374 {
375  f.setFeatureId( fid );
376  f.setValid( true );
377  f.setFields( &mSource->mFields );
378 
380  {
381  f.setGeometry( geom );
382 
383  // simplify the edited geometry using its simplifier configured
385  {
386  QgsGeometry* geometry = f.geometry();
387  QGis::GeometryType geometryType = geometry->type();
388  if ( geometryType == QGis::Line || geometryType == QGis::Polygon ) mEditGeometrySimplifier->simplifyGeometry( geometry );
389  }
390  }
391 
392  bool subsetAttrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes );
393  if ( !subsetAttrs || ( subsetAttrs && mRequest.subsetOfAttributes().count() > 0 ) )
394  {
395  // retrieve attributes from provider
396  QgsFeature tmp;
397  //mDataProvider->featureAtId( fid, tmp, false, mFetchProvAttributes );
398  QgsFeatureRequest request;
400  if ( subsetAttrs )
401  {
403  }
405  if ( fi.nextFeature( tmp ) )
406  {
408  f.setAttributes( tmp.attributes() );
409  }
410  }
411 
413 }
414 
415 
416 
418 {
420 
423 }
424 
425 
426 
428 {
430  QgsAttributeList sourceJoinFields; // attributes that also need to be fetched from this layer in order to have joins working
431 
432  mFetchJoinInfo.clear();
433 
434  for ( QgsAttributeList::const_iterator attIt = fetchAttributes.constBegin(); attIt != fetchAttributes.constEnd(); ++attIt )
435  {
436  if ( !mSource->mFields.exists( *attIt ) )
437  continue;
438 
439  if ( mSource->mFields.fieldOrigin( *attIt ) != QgsFields::OriginJoin )
440  continue;
441 
442  int sourceLayerIndex;
443  const QgsVectorJoinInfo* joinInfo = mSource->mJoinBuffer->joinForFieldIndex( *attIt, mSource->mFields, sourceLayerIndex );
444  Q_ASSERT( joinInfo );
445 
446  QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinInfo->joinLayerId ) );
447  Q_ASSERT( joinLayer );
448 
449  if ( !mFetchJoinInfo.contains( joinLayer ) )
450  {
451  FetchJoinInfo info;
452  info.joinInfo = joinInfo;
453  info.joinLayer = joinLayer;
454 
455  if ( joinInfo->targetFieldName.isEmpty() )
456  info.targetField = joinInfo->targetFieldIndex; //for compatibility with 1.x
457  else
459 
460  if ( joinInfo->joinFieldName.isEmpty() )
461  info.joinField = joinInfo->joinFieldIndex; //for compatibility with 1.x
462  else
463  info.joinField = joinLayer->pendingFields().indexFromName( joinInfo->joinFieldName );
464 
465  info.indexOffset = *attIt - sourceLayerIndex;
466  if ( info.joinField < sourceLayerIndex )
467  info.indexOffset++;
468 
469  // for joined fields, we always need to request the targetField from the provider too
470  if ( !fetchAttributes.contains( info.targetField ) )
471  sourceJoinFields << info.targetField;
472 
473  mFetchJoinInfo.insert( joinLayer, info );
474  }
475 
476  // store field source index - we'll need it when fetching from provider
477  mFetchJoinInfo[ joinLayer ].attributes.push_back( sourceLayerIndex );
478  }
479 
480  // add sourceJoinFields if we're using a subset
483 }
484 
486 {
487  const QList<QgsExpressionFieldBuffer::ExpressionField> exps = mSource->mExpressionFieldBuffer->expressions();
488 
489  for ( int i = 0; i < mSource->mFields.count(); i++ )
490  {
492  {
493  // Only prepare if there is no subset defined or the subset contains this field
495  || mRequest.subsetOfAttributes().contains( i ) )
496  {
497  int oi = mSource->mFields.fieldOriginIndex( i );
498  QgsExpression* exp = new QgsExpression( exps[oi].expression );
499  exp->prepare( mSource->mFields );
500  mExpressionFieldInfo.insert( i, exp );
501 
503  {
504  QgsAttributeList attrs;
505  Q_FOREACH( const QString& col, exp->referencedColumns() )
506  {
507  attrs.append( mSource->mFields.fieldNameIndex( col ) );
508  }
509 
511  }
512 
513  if ( exp->needsGeometry() )
514  {
515  mRequest.setFlags( mRequest.flags() & ~QgsFeatureRequest::NoGeometry );
516  }
517  }
518  }
519  }
520 }
521 
523 {
524  QMap<QgsVectorLayer*, FetchJoinInfo>::const_iterator joinIt = mFetchJoinInfo.constBegin();
525  for ( ; joinIt != mFetchJoinInfo.constEnd(); ++joinIt )
526  {
527  const FetchJoinInfo& info = joinIt.value();
528  Q_ASSERT( joinIt.key() );
529 
530  QVariant targetFieldValue = f.attribute( info.targetField );
531  if ( !targetFieldValue.isValid() )
532  continue;
533 
534  const QHash< QString, QgsAttributes>& memoryCache = info.joinInfo->cachedAttributes;
535  if ( memoryCache.isEmpty() )
536  info.addJoinedAttributesDirect( f, targetFieldValue );
537  else
538  info.addJoinedAttributesCached( f, targetFieldValue );
539  }
540 }
541 
543 {
544  // make sure we have space for newly added attributes
545  f.attributes().resize( mSource->mFields.count() ); // Provider attrs count + joined attrs count + expression attrs count
546 
547  if ( !mFetchJoinInfo.isEmpty() )
548  addJoinedAttributes( f );
549 
550  if ( !mExpressionFieldInfo.isEmpty() )
551  {
552  QMap<int, QgsExpression*>::ConstIterator it = mExpressionFieldInfo.constBegin();
553 
554  for ( ; it != mExpressionFieldInfo.constEnd(); ++it )
555  {
556  QgsExpression* exp = it.value();
557  QVariant val = exp->evaluate( f );
558  f.setAttribute( it.key(), val );
559  }
560  }
561 }
562 
564 {
567 
568  // setup simplification for edited geometries to fetch
570  {
572  return mEditGeometrySimplifier != NULL;
573  }
574  return false;
575 }
576 
578 {
579 #if 0
580  // TODO[MD]: after merge
581  QgsVectorDataProvider* provider = L->dataProvider();
582 
583  if ( provider && methodType != QgsSimplifyMethod::NoSimplification )
584  {
585  int capabilities = provider->capabilities();
586 
587  if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
588  {
589  return ( capabilities & QgsVectorDataProvider::SimplifyGeometries );
590  }
591  else if ( methodType == QgsSimplifyMethod::PreserveTopology )
592  {
594  }
595  }
596 #endif
597  return false;
598 }
599 
600 
602 {
603  const QHash<QString, QgsAttributes>& memoryCache = joinInfo->cachedAttributes;
604  QHash<QString, QgsAttributes>::const_iterator it = memoryCache.find( joinValue.toString() );
605  if ( it == memoryCache.constEnd() )
606  return; // joined value not found -> leaving the attributes empty (null)
607 
608  int index = indexOffset;
609 
610  const QgsAttributes& featureAttributes = it.value();
611  for ( int i = 0; i < featureAttributes.count(); ++i )
612  {
613  // skip the join field to avoid double field names (fields often have the same name)
614  if ( i == joinField )
615  continue;
616 
617  f.setAttribute( index++, featureAttributes[i] );
618  }
619 }
620 
621 
622 
624 {
625  // no memory cache, query the joined values by setting substring
626  QString subsetString = joinLayer->dataProvider()->subsetString(); // provider might already have a subset string
627  QString bkSubsetString = subsetString;
628  if ( !subsetString.isEmpty() )
629  {
630  subsetString.prepend( "(" ).append( ") AND " );
631  }
632 
633  QString joinFieldName;
634  if ( joinInfo->joinFieldName.isEmpty() && joinInfo->joinFieldIndex >= 0 && joinInfo->joinFieldIndex < joinLayer->pendingFields().count() )
635  joinFieldName = joinLayer->pendingFields().field( joinInfo->joinFieldIndex ).name(); // for compatibility with 1.x
636  else
637  joinFieldName = joinInfo->joinFieldName;
638 
639  subsetString.append( QString( "\"%1\"" ).arg( joinFieldName ) );
640 
641  if ( joinValue.isNull() )
642  {
643  subsetString += " IS NULL";
644  }
645  else
646  {
647  QString v = joinValue.toString();
648  switch ( joinValue.type() )
649  {
650  case QVariant::Int:
651  case QVariant::LongLong:
652  case QVariant::Double:
653  break;
654 
655  default:
656  case QVariant::String:
657  v.replace( "'", "''" );
658  v.prepend( "'" ).append( "'" );
659  break;
660  }
661  subsetString += "=" + v;
662  }
663 
664  joinLayer->dataProvider()->setSubsetString( subsetString, false );
665 
666  // select (no geometry)
667  QgsFeatureRequest request;
669  request.setSubsetOfAttributes( attributes );
670  QgsFeatureIterator fi = joinLayer->getFeatures( request );
671 
672  // get first feature
673  QgsFeature fet;
674  if ( fi.nextFeature( fet ) )
675  {
676  int index = indexOffset;
677  const QgsAttributes& attr = fet.attributes();
678  for ( int i = 0; i < attr.count(); ++i )
679  {
680  if ( i == joinField )
681  continue;
682 
683  f.setAttribute( index++, attr[i] );
684  }
685  }
686  else
687  {
688  // no suitable join feature found, keeping empty (null) attributes
689  }
690 
691  joinLayer->dataProvider()->setSubsetString( bkSubsetString, false );
692 }
693 
694 
695 
696 
698 {
699  QgsFeatureId featureId = mRequest.filterFid();
700 
701  // deleted already?
702  if ( mSource->mDeletedFeatureIds.contains( featureId ) )
703  return false;
704 
705  // has changed geometry?
706  if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && mSource->mChangedGeometries.contains( featureId ) )
707  {
708  useChangedAttributeFeature( featureId, mSource->mChangedGeometries[featureId], f );
709  return true;
710  }
711 
712  // added features
713  for ( QgsFeatureMap::ConstIterator iter = mSource->mAddedFeatures.constBegin(); iter != mSource->mAddedFeatures.constEnd(); ++iter )
714  {
715  if ( iter->id() == featureId )
716  {
717  useAddedFeature( *iter, f );
718  return true;
719  }
720  }
721 
722  // regular features
724  if ( fi.nextFeature( f ) )
725  {
727 
729 
730  return true;
731  }
732 
733  return false;
734 }
735 
737 {
738  QgsAttributes& attrs = f.attributes();
739 
740  // remove all attributes that will disappear - from higher indices to lower
741  for ( int idx = mSource->mDeletedAttributeIds.count() - 1; idx >= 0; --idx )
742  {
743  attrs.remove( mSource->mDeletedAttributeIds[idx] );
744  }
745 
746  // adjust size to accommodate added attributes
747  attrs.resize( attrs.count() + mSource->mAddedAttributes.count() );
748 
749  // update changed attributes
750  if ( mSource->mChangedAttributeValues.contains( f.id() ) )
751  {
753  for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
754  attrs[it.key()] = it.value();
755  }
756 }
757 
759 {
760  if ( mSource->mChangedGeometries.contains( f.id() ) )
762 }
763 
QgsFeatureId id() const
Get the feature id for this feature.
Definition: qgsfeature.cpp:100
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
QgsAbstractFeatureSource * mProviderFeatureSource
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
Wrapper for iterator of features from vector data provider or vector layer.
void addJoinedAttributesDirect(QgsFeature &f, const QVariant &joinValue) const
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
static unsigned index
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
Filter using feature ID.
QgsVectorLayerJoinBuffer * mJoinBuffer
const Flags & flags() const
QString joinFieldName
Join field in the source layer.
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfield.h:171
QString targetFieldName
Join field in the target layer.
GeometryType
Definition: qgis.h:155
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
const QgsRectangle & filterRect() const
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:325
supports simplification of geometries on provider side according to a distance tolerance ...
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs...
Definition: qgsfield.cpp:186
QgsVectorLayerFeatureIterator(QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request)
int joinFieldIndex
Join field index in the source layer.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
Definition: qgsfeature.cpp:112
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QGis::GeometryType type()
Returns type of the vector.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)
const QgsAttributeList & subsetOfAttributes() const
void setAttributes(const QgsAttributes &attrs)
Definition: qgsfeature.h:144
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
Definition: qgsfeature.cpp:190
QMap< int, QgsExpression * > mExpressionFieldInfo
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
Definition: qgsfield.h:170
bool mClosed
Set to true, as soon as the iterator is closed.
int targetFieldIndex
Join field index in the target layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
const QList< ExpressionField > expressions() const
QgsVectorLayer * joinLayer
resolved pointer to the joined layer
bool isClosed() const
find out whether the iterator is still valid or closed already
Manages joined fields for a vector layer.
const QgsVectorJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
int joinField
index of field (of the joined layer) must have equal value
virtual bool simplifyGeometry(QgsGeometry *geometry) const =0
Simplifies the specified geometry.
virtual QgsAbstractFeatureSource * featureSource() const
Return feature source object that can be used for querying provider's data.
QMap< QgsVectorLayer *, FetchJoinInfo > mFetchJoinInfo
information about joins used in the current select() statement.
bool containsJoins() const
Quick way to test if there is any join at all.
void updateChangedAttributes(QgsFeature &f)
Update feature with uncommited attribute updates.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
Simplify using the map2pixel data to optimize the rendering of geometries.
bool exists(int i) const
Return if a field index is valid.
Definition: qgsfield.h:206
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object (deep copy)
Definition: qgsfeature.cpp:134
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
void iteratorClosed()
to be called by from subclass in close()
void useAddedFeature(const QgsFeature &src, QgsFeature &f)
QgsFeatureRequest & setFilterFids(QgsFeatureIds fids)
Set feature ID that should be fetched.
void setFeatureId(QgsFeatureId id)
Set the feature id for this feature.
Definition: qgsfeature.cpp:128
const QgsVectorJoinInfo * joinInfo
cannonical source of information about the join
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
virtual bool fetchFeature(QgsFeature &feature)
fetch next feature, return true on success
void updateFeatureGeometry(QgsFeature &f)
Update feature with uncommited geometry updates.
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
Definition: qgsfield.h:222
QStringList referencedColumns()
Get list of columns referenced by the expression.
virtual bool close()
end of iterating: free the resources / lock
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
const QgsFeatureIds deletedFeatureIds()
const QgsAttributes & attributes() const
Definition: qgsfeature.h:142
Filter using a rectangle, no need to set NoGeometry.
int count() const
Return number of items.
Definition: qgsfield.h:200
virtual bool rewind()
reset the iterator to the starting position
No simplification is applied.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
FilterType filterType() const
QgsExpressionFieldBuffer * mExpressionFieldBuffer
stores information about expression fields on this layer
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
QgsExpressionFieldBuffer * mExpressionFieldBuffer
void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
Definition: qgsfeature.cpp:161
const QList< QgsField > & addedAttributes()
added attributes fields which are not commited
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
Definition: qgsfield.h:227
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
QgsVectorLayerFeatureSource(QgsVectorLayer *layer)
const QgsFeatureId & filterFid() const
int indexOffset
at what position the joined fields start
supports topological simplification of geometries on provider side according to a distance tolerance ...
void useChangedAttributeFeature(QgsFeatureId fid, const QgsGeometry &geom, QgsFeature &f)
const QgsFeatureMap & addedFeatures()
New features which are not commited.
void setValid(bool validity)
Set the validity of the feature.
Definition: qgsfeature.cpp:176
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QgsFeatureRequest mRequest
A copy of the feature request.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
virtual bool providerCanSimplify(QgsSimplifyMethod::MethodType methodType) const
returns whether the iterator supports simplify geometries on provider side
int targetField
index of field (of this layer) that drives the join
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) ...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:230
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
QgsVectorLayerJoinBuffer * mJoinBuffer
QVector< QVariant > QgsAttributes
Definition: qgsfeature.h:100
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
Definition: qgsfield.h:220
static QgsAbstractGeometrySimplifier * createGeometrySimplifier(const QgsSimplifyMethod &simplifyMethod)
Creates a geometry simplifier according to specified method.
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
qint64 QgsFeatureId
Definition: qgsfeature.h:30
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
void addJoinedAttributesCached(QgsFeature &f, const QVariant &joinValue) const
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
Simplify using the Douglas-Peucker algorithm ensuring that the result is a valid geometry.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)=0
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool nextFeature(QgsFeature &f)
This is the base class for vector data providers.
QgsChangedAttributesMap mChangedAttributeValues
Geometry is not required. It may still be returned if e.g. required for a filter condition.
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod)
Setup the simplification of geometries to fetch using the specified simplify method.
Represents a vector layer which manages a vector based data sets.
const QgsAttributeList & deletedAttributeIds()
deleted attributes fields which are not commited.
field is calculated from an expression
Definition: qgsfield.h:173
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
QgsAbstractGeometrySimplifier * mEditGeometrySimplifier
optional object to locally simplify edited (changed or added) geometries fetched by this feature iter...
QString joinLayerId
Source layer.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
Definition: qgsfield.cpp:198
MethodType methodType() const
Gets the simplification type.
void addVirtualAttributes(QgsFeature &f)
Adds attributes that don't source from the provider but are added inside QGIS Includes.
helper template that cares of two things: 1.
QgsExpression * filterExpression() const