QGIS API Documentation  2.8.2-Wien
 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 
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