QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
79  static const QString AllAttributes;
80 
84  explicit QgsFeatureRequest( QgsFeatureId fid );
86  explicit QgsFeatureRequest( const QgsRectangle& rect );
88  explicit QgsFeatureRequest( const QgsExpression& expr );
91 
92  QgsFeatureRequest& operator=( const QgsFeatureRequest& rh );
93 
95 
96  FilterType filterType() const { return mFilter; }
97 
100  QgsFeatureRequest& setFilterRect( const QgsRectangle& rect );
101  const QgsRectangle& filterRect() const { return mFilterRect; }
102 
104  QgsFeatureRequest& setFilterFid( QgsFeatureId fid );
105  const QgsFeatureId& filterFid() const { return mFilterFid; }
106 
108  QgsFeatureRequest& setFilterFids( QgsFeatureIds fids );
109  const QgsFeatureIds& filterFids() const { return mFilterFids; }
110 
112  QgsFeatureRequest& setFilterExpression( const QString& expression );
113  QgsExpression* filterExpression() const { return mFilterExpression; }
114 
116  QgsFeatureRequest& setFlags( Flags flags );
117  const Flags& flags() const { return mFlags; }
118 
121  QgsFeatureRequest& setSubsetOfAttributes( const QgsAttributeList& attrs );
122  const QgsAttributeList& subsetOfAttributes() const { return mAttrs; }
123 
125  QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );
126 
129  QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
132  const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
133 
143  bool acceptFeature( const QgsFeature& feature );
144 
145  // TODO: in future
146  // void setFilterNativeExpression(con QString& expr); // using provider's SQL (if supported)
147  // void setLimit(int limit);
148 
149  protected:
155  Flags mFlags;
158 };
159 
160 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
161 
162 
163 class QgsFeatureIterator;
165 
169 class CORE_EXPORT QgsAbstractFeatureSource
170 {
171  public:
172  virtual ~QgsAbstractFeatureSource();
173 
174  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) = 0;
175 
176  protected:
177  void iteratorOpened( QgsAbstractFeatureIterator* it );
178  void iteratorClosed( QgsAbstractFeatureIterator* it );
179 
180  QSet< QgsAbstractFeatureIterator* > mActiveIterators;
181 
182  template<typename> friend class QgsAbstractFeatureIteratorFromSource;
183 };
184 
185 #endif // QGSFEATUREREQUEST_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QgsFeatureIds mFilterFids
Definition: qgsfeaturerequest.h:153
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:139
const QgsSimplifyMethod & simplifyMethod() const
Get simplification method for geometries that will be fetched.
Definition: qgsfeaturerequest.h:132
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Filter using feature ID.
Definition: qgsfeaturerequest.h:74
const Flags & flags() const
Definition: qgsfeaturerequest.h:117
QgsSimplifyMethod mSimplifyMethod
Definition: qgsfeaturerequest.h:157
QgsExpression * mFilterExpression
Definition: qgsfeaturerequest.h:154
FilterType mFilter
Definition: qgsfeaturerequest.h:150
const QgsRectangle & filterRect() const
Definition: qgsfeaturerequest.h:101
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:325
const QgsFeatureIds & filterFids() const
Definition: qgsfeaturerequest.h:109
Container of fields for a vector layer.
Definition: qgsfield.h:163
const QgsAttributeList & subsetOfAttributes() const
Definition: qgsfeaturerequest.h:122
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QSet< QgsAbstractFeatureIterator * > mActiveIterators
Definition: qgsfeaturerequest.h:180
Flags mFlags
Definition: qgsfeaturerequest.h:155
Internal feature iterator to be implemented within data providers.
Definition: qgsfeatureiterator.h:26
Filter using expression.
Definition: qgsfeaturerequest.h:75
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Definition: qgsfeaturerequest.h:58
QList< int > QgsAttributeList
Definition: qgsfeaturerequest.h:26
static const QString AllAttributes
Definition: qgsfeaturerequest.h:79
Filter using a rectangle, no need to set NoGeometry.
Definition: qgsfeaturerequest.h:73
QgsRectangle mFilterRect
Definition: qgsfeaturerequest.h:151
FilterType filterType() const
Definition: qgsfeaturerequest.h:96
base class that can be used for any class that is capable of returning features
Definition: qgsfeaturerequest.h:169
QgsFeatureId mFilterFid
Definition: qgsfeaturerequest.h:152
const QgsFeatureId & filterFid() const
Definition: qgsfeaturerequest.h:105
No filter is applied.
Definition: qgsfeaturerequest.h:72
FilterType
Definition: qgsfeaturerequest.h:70
QgsAttributeList mAttrs
Definition: qgsfeaturerequest.h:156
qint64 QgsFeatureId
Definition: qgsfeature.h:30
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
Definition: qgssimplifymethod.h:25
Flag
Definition: qgsfeaturerequest.h:61
helper template that cares of two things: 1.
Definition: qgsfeatureiterator.h:110
QgsExpression * filterExpression() const
Definition: qgsfeaturerequest.h:113