QGIS API Documentation  2.99.0-Master (c558d51)
qgsvectordataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectordataprovider.h - DataProvider Interface for vector layers
3  --------------------------------------
4  Date : 23-Sep-2004
5  Copyright : (C) 2004 by Marco Hugentobler
6  email : [email protected]
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 QGSVECTORDATAPROVIDER_H
16 #define QGSVECTORDATAPROVIDER_H
17 
18 class QTextCodec;
19 
20 #include <QList>
21 #include <QSet>
22 #include <QMap>
23 #include <QHash>
24 
25 //QGIS Includes
26 #include "qgis.h"
27 #include "qgsdataprovider.h"
28 #include "qgsfeature.h"
29 #include "qgsaggregatecalculator.h"
30 #include "qgsmaplayerdependency.h"
31 #include "qgsrelation.h"
32 
33 typedef QList<int> QgsAttributeList;
34 typedef QSet<int> QgsAttributeIds;
35 typedef QHash<int, QString> QgsAttrPalIndexNameHash;
36 
37 class QgsFeatureIterator;
38 class QgsTransaction;
39 class QgsFeedback;
40 
41 #include "qgsfeaturerequest.h"
42 
51 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
52 {
53  Q_OBJECT
54 
55  friend class QgsTransaction;
56 
57  public:
58 
59  // If you add to this, please also add to capabilitiesString()
60 
65  {
67  NoCapabilities = 0,
69  AddFeatures = 1,
71  DeleteFeatures = 1 << 1,
73  ChangeAttributeValues = 1 << 2,
75  AddAttributes = 1 << 3,
77  DeleteAttributes = 1 << 4,
79  CreateSpatialIndex = 1 << 6,
81  SelectAtId = 1 << 7,
83  ChangeGeometries = 1 << 8,
85  SelectEncoding = 1 << 13,
87  CreateAttributeIndex = 1 << 12,
89  SimplifyGeometries = 1 << 14,
91  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
93  TransactionSupport = 1 << 16,
95  CircularGeometries = 1 << 17,
96 
100  ChangeFeatures = 1 << 18,
102  RenameAttributes = 1 << 19,
103  };
104 
105  Q_DECLARE_FLAGS( Capabilities, Capability )
106 
107 
108  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
109  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
110  RenameAttributes;
111 
116  QgsVectorDataProvider( const QString& uri = QString() );
117 
121  virtual ~QgsVectorDataProvider();
122 
139  virtual QgsAbstractFeatureSource *featureSource() const = 0;
140 
144  virtual QString storageType() const;
145 
151  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) const = 0;
152 
156  virtual QgsWkbTypes::Type wkbType() const = 0;
157 
162  virtual long featureCount() const = 0;
163 
167  virtual QgsFields fields() const = 0;
168 
173  virtual QString dataComment() const;
174 
183  virtual QVariant minimumValue( int index ) const;
184 
193  virtual QVariant maximumValue( int index ) const;
194 
203  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 ) const;
204 
214  virtual QStringList uniqueStringsMatching( int index, const QString& substring, int limit = -1,
215  QgsFeedback* feedback = nullptr ) const;
216 
227  virtual QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
228  int index,
229  const QgsAggregateCalculator::AggregateParameters& parameters,
230  QgsExpressionContext* context,
231  bool& ok ) const;
232 
239  virtual void enumValues( int index, QStringList& enumList ) const { Q_UNUSED( index ); enumList.clear(); }
240 
245  virtual bool addFeatures( QgsFeatureList &flist );
246 
252  virtual bool deleteFeatures( const QgsFeatureIds &id );
253 
259  virtual bool addAttributes( const QList<QgsField> &attributes );
260 
266  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
267 
274  virtual bool renameAttributes( const QgsFieldNameMap& renamedAttributes );
275 
281  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
282 
291  virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
292  const QgsGeometryMap &geometry_map );
293 
305  virtual QVariant defaultValue( int fieldIndex ) const;
306 
314  virtual QString defaultValueClause( int fieldIndex ) const;
315 
322  QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
323 
331  virtual bool skipConstraintCheck( int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant& value = QVariant() ) const;
332 
340  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
341 
346  virtual bool createSpatialIndex();
347 
349  virtual bool createAttributeIndex( int field );
350 
356  virtual Capabilities capabilities() const;
357 
361  QString capabilitiesString() const;
362 
366  virtual void setEncoding( const QString& e );
367 
371  QString encoding() const;
372 
376  int fieldNameIndex( const QString& fieldName ) const;
377 
381  QMap<QString, int> fieldNameMap() const;
382 
386  virtual QgsAttributeList attributeIndexes() const;
387 
391  virtual QgsAttributeList pkAttributeIndexes() const;
392 
396  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const;
397 
401  bool supportedType( const QgsField &field ) const;
402 
403  struct NativeType
404  {
405  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0, QVariant::Type subType = QVariant::Invalid )
406  : mTypeDesc( typeDesc )
407  , mTypeName( typeName )
408  , mType( type )
409  , mMinLen( minLen )
410  , mMaxLen( maxLen )
411  , mMinPrec( minPrec )
412  , mMaxPrec( maxPrec )
413  , mSubType( subType )
414  {}
415 
416  QString mTypeDesc;
417  QString mTypeName;
418  QVariant::Type mType;
419  int mMinLen;
420  int mMaxLen;
421  int mMinPrec;
422  int mMaxPrec;
423  QVariant::Type mSubType;
424  };
425 
429  const QList< NativeType > &nativeTypes() const;
430 
435  virtual bool doesStrictFeatureTypeCheck() const { return true; }
436 
438  static QStringList availableEncodings();
439 
443  bool hasErrors() const;
444 
448  void clearErrors();
449 
453  QStringList errors() const;
454 
459  virtual bool isSaveAndLoadStyleToDBSupported() const;
460 
461  static QVariant convertValue( QVariant::Type type, const QString& value );
462 
466  virtual QgsTransaction* transaction() const;
467 
475  virtual void forceReload();
476 
480  virtual QSet<QgsMapLayerDependency> dependencies() const;
481 
489  virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer* self, const QList<QgsVectorLayer*>& layers ) const;
490 
495  virtual QVariantMap metadata() const { return QVariantMap(); };
496 
502  virtual QString translateMetadataKey( const QString& mdKey ) const { return mdKey; };
503 
510  virtual QString translateMetadataValue( const QString& mdKey, const QVariant& value ) const { Q_UNUSED( mdKey ); return value.toString(); };
511 
512  signals:
513 
519  void raiseError( const QString& msg ) const;
520 
521  protected:
522 
527  void clearMinMaxCache();
528 
532  void fillMinMaxCache() const;
533 
543  void pushError( const QString& msg ) const;
544 
549  QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const;
550 
557  void setNativeTypes( const QList<NativeType>& nativeTypes );
558 
564  QTextCodec* textEncoding() const;
565 
566  private:
567  mutable bool mCacheMinMaxDirty;
568  mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
569 
571  QTextCodec* mEncoding;
572 
574  QgsAttributeList mAttributesToFetch;
575 
577  QList< NativeType > mNativeTypes;
578 
580  QMap<QString, QVariant::Type> mOldTypeList;
581 
583  mutable QStringList mErrors;
584 
585  static QStringList smEncodings;
586 
590  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
591 
592 };
593 
594 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorDataProvider::Capabilities )
595 
596 #endif
QMap< int, QString > QgsFieldNameMap
Definition: qgsfeature.h:358
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:353
static unsigned index
virtual QString translateMetadataKey(const QString &mdKey) const
Get the translated metadata key.
Constraint
Constraints which may be present on a field.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:360
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:36
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
Container of fields for a vector layer.
Definition: qgsfields.h:36
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
Abstract base class for spatial data provider implementations.
QList< int > QgsAttributeList
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:40
QSet< int > QgsAttributeIds
NativeType(const QString &typeDesc, const QString &typeName, QVariant::Type type, int minLen=0, int maxLen=0, int minPrec=0, int maxPrec=0, QVariant::Type subType=QVariant::Invalid)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Capability
enumeration with capabilities that providers might implement
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:47
Base class that can be used for any class that is capable of returning features.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:350
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
virtual QString translateMetadataValue(const QString &mdKey, const QVariant &value) const
Get the translated metadata value.
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
QHash< int, QString > QgsAttrPalIndexNameHash
virtual QVariantMap metadata() const
Get metadata, dependent on the provider type, that will be display in the metadata tab of the layer p...