QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 "qgsexpressioncontext.h"
24 #include "qgssimplifymethod.h"
25 
26 #include <QList>
28 
59 class CORE_EXPORT QgsFeatureRequest
60 {
61  public:
62  enum Flag
63  {
64  NoFlags = 0,
65  NoGeometry = 1,
66  SubsetOfAttributes = 2,
67  ExactIntersect = 4
68  };
69  Q_DECLARE_FLAGS( Flags, Flag )
70 
72  {
77  FilterFids
78  };
79 
80  static const QString AllAttributes;
81 
85  explicit QgsFeatureRequest( QgsFeatureId fid );
87  explicit QgsFeatureRequest( const QgsRectangle& rect );
89  explicit QgsFeatureRequest( const QgsExpression& expr, const QgsExpressionContext& context = QgsExpressionContext() );
92 
93  QgsFeatureRequest& operator=( const QgsFeatureRequest& rh );
94 
96 
97  FilterType filterType() const { if ( mFilter == FilterNone && !mFilterRect.isNull() ) return FilterRect; else return mFilter; }
98 
101  QgsFeatureRequest& setFilterRect( const QgsRectangle& rect );
102  const QgsRectangle& filterRect() const { return mFilterRect; }
103 
105  QgsFeatureRequest& setFilterFid( QgsFeatureId fid );
106  const QgsFeatureId& filterFid() const { return mFilterFid; }
107 
109  QgsFeatureRequest& setFilterFids( QgsFeatureIds fids );
110  const QgsFeatureIds& filterFids() const { return mFilterFids; }
111 
117  QgsFeatureRequest& setFilterExpression( const QString& expression );
118 
123  QgsExpression* filterExpression() const { return mFilterExpression; }
124 
130  QgsExpressionContext* expressionContext() { return &mExpressionContext; }
131 
137  QgsFeatureRequest& setExpressionContext( const QgsExpressionContext& context );
138 
147  QgsFeatureRequest& disableFilter() { mFilter = FilterNone; return *this; }
148 
150  QgsFeatureRequest& setFlags( Flags flags );
151  const Flags& flags() const { return mFlags; }
152 
155  QgsFeatureRequest& setSubsetOfAttributes( const QgsAttributeList& attrs );
156  const QgsAttributeList& subsetOfAttributes() const { return mAttrs; }
157 
159  QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );
160 
163  QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
166  const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
167 
177  bool acceptFeature( const QgsFeature& feature );
178 
179  // TODO: in future
180  // void setFilterNativeExpression(con QString& expr); // using provider's SQL (if supported)
181  // void setLimit(int limit);
182 
183  protected:
190  Flags mFlags;
193 };
194 
195 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
196 
197 
198 class QgsFeatureIterator;
200 
204 class CORE_EXPORT QgsAbstractFeatureSource
205 {
206  public:
207  virtual ~QgsAbstractFeatureSource();
208 
209  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) = 0;
210 
211  protected:
212  void iteratorOpened( QgsAbstractFeatureIterator* it );
213  void iteratorClosed( QgsAbstractFeatureIterator* it );
214 
216 
217  template<typename> friend class QgsAbstractFeatureIteratorFromSource;
218 };
219 
220 #endif // QGSFEATUREREQUEST_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:88
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
QgsExpressionContext * expressionContext()
Returns the expression context used to evaluate filter expressions.
const QgsFeatureIds & filterFids() const
Container of fields for a vector layer.
Definition: qgsfield.h:177
const QgsAttributeList & subsetOfAttributes() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
QgsExpressionContext mExpressionContext
QSet< QgsAbstractFeatureIterator * > mActiveIterators
QgsFeatureRequest & disableFilter()
Disables filter conditions.
Internal feature iterator to be implemented within data providers.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
static const QString AllAttributes
Obsolete, will be ignored. If a filterRect is set it will be used anyway. Filter using a rectangle...
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:31
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
Helper template that cares of two things: 1.
QgsExpression * filterExpression() const
Returns the filter expression if set.