QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfeaturerequest.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturerequest.h
3  ---------------------
4  begin : Mai 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  ***************************************************************************/
15 #ifndef QGSFEATUREREQUEST_H
16 #define QGSFEATUREREQUEST_H
17 
18 #include <QFlags>
19 
20 #include "qgsfeature.h"
21 #include "qgsrectangle.h"
22 #include "qgsexpression.h"
23 #include "qgssimplifymethod.h"
24 
25 #include <QList>
26 typedef QList<int> QgsAttributeList;
27 
58 class CORE_EXPORT QgsFeatureRequest
59 {
60  public:
61  enum Flag
62  {
63  NoFlags = 0,
64  NoGeometry = 1,
65  SubsetOfAttributes = 2,
66  ExactIntersect = 4
67  };
68  Q_DECLARE_FLAGS( Flags, Flag )
69 
71  {
76  FilterFids
77  };
78 
82  explicit QgsFeatureRequest( QgsFeatureId fid );
84  explicit QgsFeatureRequest( const QgsRectangle& rect );
86  explicit QgsFeatureRequest( const QgsExpression& expr );
89 
90  QgsFeatureRequest& operator=( const QgsFeatureRequest& rh );
91 
93 
94  FilterType filterType() const { return mFilter; }
95 
98  QgsFeatureRequest& setFilterRect( const QgsRectangle& rect );
99  const QgsRectangle& filterRect() const { return mFilterRect; }
100 
102  QgsFeatureRequest& setFilterFid( QgsFeatureId fid );
103  const QgsFeatureId& filterFid() const { return mFilterFid; }
104 
106  QgsFeatureRequest& setFilterFids( QgsFeatureIds fids );
107  const QgsFeatureIds& filterFids() const { return mFilterFids; }
108 
110  QgsFeatureRequest& setFilterExpression( const QString& expression );
111  QgsExpression* filterExpression() const { return mFilterExpression; }
112 
114  QgsFeatureRequest& setFlags( Flags flags );
115  const Flags& flags() const { return mFlags; }
116 
119  QgsFeatureRequest& setSubsetOfAttributes( const QgsAttributeList& attrs );
120  const QgsAttributeList& subsetOfAttributes() const { return mAttrs; }
121 
123  QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );
124 
127  QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
130  const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
131 
141  bool acceptFeature( const QgsFeature& feature );
142 
143  // TODO: in future
144  // void setFilterNativeExpression(con QString& expr); // using provider's SQL (if supported)
145  // void setLimit(int limit);
146 
147  protected:
153  Flags mFlags;
156 };
157 
158 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
159 
160 
161 class QgsFeatureIterator;
163 
167 class CORE_EXPORT QgsAbstractFeatureSource
168 {
169  public:
170  virtual ~QgsAbstractFeatureSource();
171 
172  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) = 0;
173 
174  protected:
175  void iteratorOpened( QgsAbstractFeatureIterator* it );
176  void iteratorClosed( QgsAbstractFeatureIterator* it );
177 
178  QSet< QgsAbstractFeatureIterator* > mActiveIterators;
179 
180  template<typename> friend class QgsAbstractFeatureIteratorFromSource;
181 };
182 
183 #endif // QGSFEATUREREQUEST_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QgsFeatureIds mFilterFids
Wrapper for iterator of features from vector data provider or vector layer.
const QgsSimplifyMethod & simplifyMethod() const
Get simplification method for geometries that will be fetched.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Filter using feature ID.
const Flags & flags() const
QgsSimplifyMethod mSimplifyMethod
QgsExpression * mFilterExpression
const QgsRectangle & filterRect() const
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:326
const QgsFeatureIds & filterFids() const
Container of fields for a vector layer.
Definition: qgsfield.h:164
const QgsAttributeList & subsetOfAttributes() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
QSet< QgsAbstractFeatureIterator * > mActiveIterators
Internal feature iterator to be implemented within data providers.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
Filter using a rectangle, no need to set NoGeometry.
QgsRectangle mFilterRect
FilterType filterType() const
base class that can be used for any class that is capable of returning features
QgsFeatureId mFilterFid
const QgsFeatureId & filterFid() const
No filter is applied.
QgsAttributeList mAttrs
qint64 QgsFeatureId
Definition: qgsfeature.h:30
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
helper template that cares of two things: 1.
QgsExpression * filterExpression() const