QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
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
18class QTextCodec;
19
20#include "qgis_core.h"
21#include <QList>
22#include <QSet>
23#include <QMap>
24#include <QHash>
25
26//QGIS Includes
27#include "qgis_sip.h"
28#include "qgsdataprovider.h"
29#include "qgsfeature.h"
32#include "qgsrelation.h"
33#include "qgsfeaturesink.h"
34#include "qgsfeaturesource.h"
35#include "qgsfeaturerequest.h"
37
38typedef QList<int> QgsAttributeList SIP_SKIP;
39typedef QSet<int> QgsAttributeIds SIP_SKIP;
40typedef QHash<int, QString> QgsAttrPalIndexNameHash;
41
43class QgsTransaction;
44class QgsFeedback;
47
48
58class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeatureSink, public QgsFeatureSource
59{
60 Q_OBJECT
61
62 friend class QgsTransaction;
64
65 public:
66
68 static const int EditingCapabilities = static_cast< int >( Qgis::VectorProviderCapability::EditingCapabilities );
69
77 QgsVectorDataProvider( const QString &uri = QString(),
80
97
101 virtual QString storageType() const;
102
108 QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override = 0;
109
113 Qgis::WkbType wkbType() const override = 0;
114
119 long long featureCount() const override = 0;
120
126 virtual bool empty() const;
127
137 virtual bool isSqlQuery() const;
138
145 virtual Qgis::VectorLayerTypeFlags vectorLayerTypeFlags() const;
146
157 Qgis::FeatureAvailability hasFeatures() const override;
158
162 QgsFields fields() const override = 0;
163
165 QgsRectangle sourceExtent() const override;
166 QgsBox3D sourceExtent3D() const override;
167 QString sourceName() const override { return QString(); }
168
173 virtual QString dataComment() const override;
174
183 QVariant minimumValue( int index ) const override;
184
193 QVariant maximumValue( int index ) const override;
194
204 virtual QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
205 QgsFeedback *feedback = nullptr ) const;
206
218 virtual QVariant aggregate( Qgis::Aggregate aggregate,
219 int index,
221 QgsExpressionContext *context,
222 bool &ok,
223 QgsFeatureIds *fids = nullptr ) const;
224
231 virtual void enumValues( int index, QStringList &enumList SIP_OUT ) const { Q_UNUSED( index ) enumList.clear(); }
232
234 QString lastError() const override;
235
242 virtual bool deleteFeatures( const QgsFeatureIds &id );
243
250 virtual bool truncate();
251
258 virtual bool cancelReload();
259
265 virtual bool addAttributes( const QList<QgsField> &attributes );
266
274 virtual bool deleteAttributes( const QgsAttributeIds &attributes );
275
283 virtual bool renameAttributes( const QgsFieldNameMap &renamedAttributes );
284
293 virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
294
306 virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
307 const QgsGeometryMap &geometry_map );
308
320 virtual QVariant defaultValue( int fieldIndex ) const;
321
328 virtual QString defaultValueClause( int fieldIndex ) const;
329
335 QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
336
343 virtual bool skipConstraintCheck( int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value = QVariant() ) const;
344
352 virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
353
358 virtual bool createSpatialIndex();
359
361 virtual bool createAttributeIndex( int field );
362
371 Q_INVOKABLE virtual Qgis::VectorProviderCapabilities capabilities() const;
372
376 QString capabilitiesString() const;
377
384 virtual Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities() const;
385
398 virtual void setEncoding( const QString &e );
399
405 QString encoding() const;
406
410 int fieldNameIndex( const QString &fieldName ) const;
411
415 QMap<QString, int> fieldNameMap() const;
416
420 virtual QgsAttributeList attributeIndexes() const;
421
425 virtual QgsAttributeList pkAttributeIndexes() const;
426
432 virtual QString geometryColumnName() const;
433
439 Q_DECL_DEPRECATED QgsAttrPalIndexNameHash palAttributeIndexNames() const SIP_DEPRECATED;
440
444 bool supportedType( const QgsField &field ) const;
445
447 {
448 NativeType( const QString &typeDesc, const QString &typeName, QMetaType::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0, QMetaType::Type subType = QMetaType::Type::UnknownType )
449 : mTypeDesc( typeDesc )
450 , mTypeName( typeName )
451 , mType( type )
452 , mMinLen( minLen )
453 , mMaxLen( maxLen )
454 , mMinPrec( minPrec )
455 , mMaxPrec( maxPrec )
456 , mSubType( subType )
457 {}
458
459 Q_DECL_DEPRECATED 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::Type::Invalid )
460 : mTypeDesc( typeDesc )
461 , mTypeName( typeName )
462 , mType( QgsVariantUtils::variantTypeToMetaType( type ) )
463 , mMinLen( minLen )
464 , mMaxLen( maxLen )
465 , mMinPrec( minPrec )
466 , mMaxPrec( maxPrec )
467 , mSubType( QgsVariantUtils::variantTypeToMetaType( subType ) ) SIP_DEPRECATED
468 {}
469
470
471 QString mTypeDesc;
472 QString mTypeName;
473 QMetaType::Type mType;
478 QMetaType::Type mSubType;
479 };
480
484 QList< QgsVectorDataProvider::NativeType > nativeTypes() const;
485
490 virtual bool doesStrictFeatureTypeCheck() const { return true; }
491
493 static QStringList availableEncodings();
494
498 bool hasErrors() const;
499
503 void clearErrors();
504
508 QStringList errors() const;
509
525 virtual QgsFeatureRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
526
542 virtual QgsAbstractVectorLayerLabeling *createLabeling( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
543
547 static QVariant convertValue( QMetaType::Type type, const QString &value );
548
554 Q_DECL_DEPRECATED static QVariant convertValue( QVariant::Type type, const QString &value ) SIP_DEPRECATED;
555
559 virtual QgsTransaction *transaction() const;
560
564 Q_DECL_DEPRECATED virtual void forceReload() SIP_DEPRECATED { reloadData(); }
565
569 virtual QSet<QgsMapLayerDependency> dependencies() const;
570
577 virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer *target, const QList<QgsVectorLayer *> &layers ) const;
578
583 virtual QVariantMap metadata() const { return QVariantMap(); }
584
590 virtual QString translateMetadataKey( const QString &mdKey ) const { return mdKey; }
591
598 virtual QString translateMetadataValue( const QString &mdKey, const QVariant &value ) const { Q_UNUSED( mdKey ) return value.toString(); }
599
606 virtual bool hasMetadata() const { return true; }
607
614 virtual void handlePostCloneOperations( QgsVectorDataProvider *source );
615
618
619 QgsDataProviderElevationProperties *elevationProperties() override;
620 const QgsDataProviderElevationProperties *elevationProperties() const override SIP_SKIP;
621
622 signals:
623
628 void raiseError( const QString &msg ) const;
629
630 protected:
631
636 void clearMinMaxCache();
637
641 void fillMinMaxCache() const;
642
651 void pushError( const QString &msg ) const;
652
658 QgsGeometry convertToProviderType( const QgsGeometry &geom ) const;
659
665 void setNativeTypes( const QList<QgsVectorDataProvider::NativeType> &nativeTypes );
666
667#ifdef SIP_PYQT5_RUN
668
673 QTextCodec *textEncoding() const;
674#endif
675
681 static QgsGeometry convertToProviderType( const QgsGeometry &geometry, Qgis::WkbType providerGeometryType );
682
683
684 private:
685 mutable bool mCacheMinMaxDirty = true;
686 mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
687
689 QTextCodec *mEncoding = nullptr;
690
692 QgsAttributeList mAttributesToFetch;
693
695 QList< NativeType > mNativeTypes;
696
698 mutable QStringList mErrors;
699
700 std::unique_ptr< QgsVectorDataProviderTemporalCapabilities > mTemporalCapabilities;
701 std::unique_ptr< QgsDataProviderElevationProperties > mElevationProperties;
702
703 static QStringList sEncodings;
704
708 virtual void setTransaction( QgsTransaction * /*transaction*/ ) {}
709};
710
711#endif
@ EditingCapabilities
Bitmask of all editing capabilities.
QFlags< VectorLayerTypeFlag > VectorLayerTypeFlags
Vector layer type flags.
Definition qgis.h:395
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
FeatureAvailability
Possible return value for QgsFeatureSource::hasFeatures() to determine if a source is empty.
Definition qgis.h:541
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:500
Aggregate
Available aggregates to calculate.
Definition qgis.h:5477
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:566
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
Base class that can be used for any class that is capable of returning features.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
This class represents a coordinate reference system (CRS).
Base class for handling elevation related properties for a data provider.
Abstract base class for spatial data provider implementations.
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
virtual QgsDataProviderTemporalCapabilities * temporalCapabilities()
Returns the provider's temporal capabilities.
virtual void reloadData()
Reloads the data from the source for providers with data caches to synchronize, changes in the data s...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
Abstract base class for all 2D vector feature renderers.
This class wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which accept features via addFeature(s) methods.
virtual QString lastError() const
Returns the most recent error encountered by the sink, e.g.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())=0
Adds a list of features to the sink.
QFlags< Flag > Flags
An interface for objects which provide features via a getFeatures method.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
virtual Qgis::FeatureAvailability hasFeatures() const
Determines if there are any features available in the source.
virtual QVariant minimumValue(int fieldIndex) const
Returns the minimum value for an attribute column or an invalid variant in case of error.
virtual QVariant maximumValue(int fieldIndex) const
Returns the maximum value for an attribute column or an invalid variant in case of error.
virtual QgsRectangle sourceExtent() const
Returns the extent of all geometries from the source.
virtual QgsBox3D sourceExtent3D() const
Returns the 3D extent of all geometries from the source.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Constraint
Constraints which may be present on a field.
QFlags< Constraint > Constraints
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Contains utility functions for working with QVariants and QVariant types.
Implementation of data provider temporal properties for QgsVectorDataProviders.
This is the base class for vector data providers.
virtual void enumValues(int index, QStringList &enumList) const
Returns the possible enum values of an attribute.
QString sourceName() const override
Returns a friendly display name for the source.
virtual QString translateMetadataValue(const QString &mdKey, const QVariant &value) const
Gets the translated metadata value.
long long featureCount() const override=0
Number of features in the layer.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
virtual QgsAbstractFeatureSource * featureSource() const =0
Returns feature source object that can be used for querying provider's data.
virtual bool hasMetadata() const
Returns true if the data source has metadata, false otherwise.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
Qgis::WkbType wkbType() const override=0
Returns the geometry type which is returned by this layer.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
Query the provider for features specified in request.
virtual QString translateMetadataKey(const QString &mdKey) const
Gets the translated metadata key.
virtual QVariantMap metadata() const
Gets metadata, dependent on the provider type, that will be display in the metadata tab of the layer ...
Stores queued vector layer edit operations prior to committing changes to the layer's data provider.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_INOUT
Definition qgis_sip.h:71
QMap< int, QString > QgsFieldNameMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
Definition qgsfield.h:27
QList< int > QgsAttributeList
QSet< int > QgsAttributeIds
QHash< int, QString > QgsAttrPalIndexNameHash
const QString & typeName
const QgsAttributeList & attributeIndexes
A bundle of parameters controlling aggregate calculation.
Setting options for creating vector data providers.
NativeType(const QString &typeDesc, const QString &typeName, QMetaType::Type type, int minLen=0, int maxLen=0, int minPrec=0, int maxPrec=0, QMetaType::Type subType=QMetaType::Type::UnknownType)
Q_DECL_DEPRECATED 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::Type::Invalid)