QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Classes | Public Types | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
QgsVectorDataProvider Class Referenceabstract

This is the base class for vector data providers. More...

#include <qgsvectordataprovider.h>

Inheritance diagram for QgsVectorDataProvider:
Inheritance graph
[legend]

Classes

struct  NativeType
 

Public Types

enum  Capability {
  NoCapabilities = 0 , AddFeatures = 1 , DeleteFeatures = 1 << 1 , ChangeAttributeValues = 1 << 2 ,
  AddAttributes = 1 << 3 , DeleteAttributes = 1 << 4 , CreateSpatialIndex = 1 << 6 , SelectAtId = 1 << 7 ,
  ChangeGeometries = 1 << 8 , SelectEncoding = 1 << 13 , CreateAttributeIndex = 1 << 12 , SimplifyGeometries = 1 << 14 ,
  SimplifyGeometriesWithTopologicalValidation = 1 << 15 , TransactionSupport = 1 << 16 , CircularGeometries = 1 << 17 , ChangeFeatures = 1 << 18 ,
  RenameAttributes = 1 << 19 , FastTruncate = 1 << 20 , ReadLayerMetadata = 1 << 21 , WriteLayerMetadata = 1 << 22 ,
  CancelSupport = 1 << 23 , CreateRenderer = 1 << 24 , CreateLabeling = 1 << 25 , ReloadData = 1 << 26 ,
  FeatureSymbology = 1 << 27
}
 enumeration with capabilities that providers might implement More...
 
- Public Types inherited from QgsDataProvider
enum  DataCapability {
  NoDataCapabilities = 0 , File = 1 , Dir = 1 << 1 , Database = 1 << 2 ,
  Net = 1 << 3
}
 Used in browser model to understand which items for which providers should be populated. More...
 
enum  ProviderProperty { EvaluateDefaultValues , CustomData = 3000 }
 Properties are used to pass custom configuration options into data providers. More...
 
enum  ReadFlag {
  FlagTrustDataSource = 1 << 0 , SkipFeatureCount = 1 << 1 , FlagLoadDefaultStyle = 1 << 2 , SkipGetExtent = 1 << 3 ,
  SkipFullScan = 1 << 4 , ForceReadOnly = 1 << 5 , SkipCredentialsRequest = 1 << 6 , ParallelThreadLoading = 1 << 7
}
 Flags which control dataprovider construction. More...
 
- Public Types inherited from QgsFeatureSink
enum  Flag { FastInsert = 1 << 1 , RollBackOnErrors = 1 << 2 }
 Flags controlling how features are added to a sink. More...
 
enum  SinkFlag { RegeneratePrimaryKey = 1 << 1 }
 Flags that can be set on a QgsFeatureSink. More...
 
- Public Types inherited from QgsFeatureSource
enum  FeatureAvailability { NoFeaturesAvailable , FeaturesAvailable , FeaturesMaybeAvailable }
 Possible return value for hasFeatures() to determine if a source is empty. More...
 
enum  SpatialIndexPresence { SpatialIndexUnknown = 0 , SpatialIndexNotPresent = 1 , SpatialIndexPresent = 2 }
 Enumeration of spatial index presence states. More...
 

Signals

void raiseError (const QString &msg) const
 Signals an error in this provider.
 
- Signals inherited from QgsDataProvider
void dataChanged ()
 Emitted whenever a change is made to the data provider which may have caused changes in the provider's data OUTSIDE of QGIS.
 
void fullExtentCalculated ()
 Emitted whenever a deferred extent calculation is completed by the provider.
 
void notify (const QString &msg)
 Emitted when the datasource issues a notification.
 

Public Member Functions

 QgsVectorDataProvider (const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
 Constructor for a vector data provider.
 
virtual bool addAttributes (const QList< QgsField > &attributes)
 Adds new attributes to the provider.
 
bool addFeatures (QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
 Adds a list of features to the sink.
 
virtual QVariant aggregate (QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids=nullptr) const
 Calculates an aggregated value from the layer's features.
 
virtual Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities () const
 Returns the provider's supported attribute editing capabilities.
 
virtual QgsAttributeList attributeIndexes () const
 Returns list of indexes to fetch all attributes in nextFeature()
 
virtual bool cancelReload ()
 Cancels the current reloading of data.
 
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities () const
 Returns flags containing the supported capabilities.
 
QString capabilitiesString () const
 Returns the above in friendly format.
 
virtual bool changeAttributeValues (const QgsChangedAttributesMap &attr_map)
 Changes attribute values of existing features.
 
virtual bool changeFeatures (const QgsChangedAttributesMap &attr_map, const QgsGeometryMap &geometry_map)
 Changes attribute values and geometries of existing features.
 
virtual bool changeGeometryValues (const QgsGeometryMap &geometry_map)
 Changes geometries of existing features.
 
void clearErrors ()
 Clear recorded errors.
 
virtual bool createAttributeIndex (int field)
 Create an attribute index on the datasource.
 
virtual QgsAbstractVectorLayerLabelingcreateLabeling (const QVariantMap &configuration=QVariantMap()) const
 Creates labeling settings, using provider backend specific information.
 
virtual QgsFeatureRenderercreateRenderer (const QVariantMap &configuration=QVariantMap()) const
 Creates a new vector layer feature renderer, using provider backend specific information.
 
virtual bool createSpatialIndex ()
 Creates a spatial index on the datasource (if supported by the provider type).
 
virtual QString dataComment () const override
 Returns a short comment for the data that this provider is providing access to (e.g.
 
virtual QVariant defaultValue (int fieldIndex) const
 Returns any literal default values which are present at the provider for a specified field index.
 
virtual QString defaultValueClause (int fieldIndex) const
 Returns any default value clauses which are present at the provider for a specified field index.
 
virtual bool deleteAttributes (const QgsAttributeIds &attributes)
 Deletes existing attributes from the provider.
 
virtual bool deleteFeatures (const QgsFeatureIds &id)
 Deletes one or more features from the provider.
 
virtual QSet< QgsMapLayerDependencydependencies () const
 Gets the list of layer ids on which this layer depends.
 
virtual QList< QgsRelationdiscoverRelations (const QgsVectorLayer *target, const QList< QgsVectorLayer * > &layers) const
 Discover the available relations with the given layers.
 
virtual bool doesStrictFeatureTypeCheck () const
 Returns true if the provider is strict about the type of inserted features (e.g.
 
virtual bool empty () const
 Returns true if the layer does not contain any feature.
 
QString encoding () const
 Returns the encoding which is used for accessing data.
 
virtual void enumValues (int index, QStringList &enumList) const
 Returns the possible enum values of an attribute.
 
QStringList errors () const
 Gets recorded errors.
 
long long featureCount () const override=0
 Number of features in the layer.
 
virtual QgsAbstractFeatureSourcefeatureSource () const =0
 Returns feature source object that can be used for querying provider's data.
 
QgsFieldConstraints::Constraints fieldConstraints (int fieldIndex) const
 Returns any constraints which are present at the provider for a specified field index.
 
int fieldNameIndex (const QString &fieldName) const
 Returns the index of a field name or -1 if the field does not exist.
 
QMap< QString, int > fieldNameMap () const
 Returns a map where the key is the name of the field and the value is its index.
 
QgsFields fields () const override=0
 Returns the fields associated with this data provider.
 
virtual Q_DECL_DEPRECATED void forceReload ()
 
QgsFeatureIterator getFeatures (const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
 Query the provider for features specified in request.
 
virtual void handlePostCloneOperations (QgsVectorDataProvider *source)
 Handles any post-clone operations required after this vector data provider was cloned from the source provider.
 
bool hasErrors () const
 Provider has errors to report.
 
QgsFeatureSource::FeatureAvailability hasFeatures () const override
 Will always return FeatureAvailability::FeaturesAvailable or FeatureAvailability::NoFeaturesAvailable.
 
virtual bool hasMetadata () const
 Returns true if the data source has metadata, false otherwise.
 
virtual bool isSqlQuery () const
 Returns true if the layer is a query (SQL) layer.
 
QString lastError () const override
 Returns the most recent error encountered by the sink, e.g.
 
QVariant maximumValue (int index) const override
 Returns the maximum value of an attribute.
 
virtual QVariantMap metadata () const
 Gets metadata, dependent on the provider type, that will be display in the metadata tab of the layer properties.
 
QVariant minimumValue (int index) const override
 Returns the minimum value of an attribute.
 
QList< QgsVectorDataProvider::NativeTypenativeTypes () const
 Returns the names of the supported types.
 
Q_DECL_DEPRECATED QgsAttrPalIndexNameHash palAttributeIndexNames () const
 Returns list of indexes to names for QgsPalLabeling fix.
 
virtual QgsAttributeList pkAttributeIndexes () const
 Returns list of indexes of fields that make up the primary key.
 
virtual bool renameAttributes (const QgsFieldNameMap &renamedAttributes)
 Renames existing attributes.
 
virtual void setEncoding (const QString &e)
 Set encoding used for accessing data from layer.
 
virtual bool skipConstraintCheck (int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value=QVariant()) const
 Returns true if a constraint check should be skipped for a specified field (e.g., if the value returned by defaultValue() is trusted implicitly.
 
QgsCoordinateReferenceSystem sourceCrs () const override
 Returns the coordinate reference system for features in the source.
 
QgsRectangle sourceExtent () const override
 Returns the extent of all geometries from the source.
 
QString sourceName () const override
 Returns a friendly display name for the source.
 
virtual QString storageType () const
 Returns the permanent storage type for this layer as a friendly name.
 
bool supportedType (const QgsField &field) const
 check if provider supports type of field
 
const QgsVectorDataProviderTemporalCapabilitiestemporalCapabilities () const override
 Returns the provider's temporal capabilities.
 
QgsVectorDataProviderTemporalCapabilitiestemporalCapabilities () override
 Returns the provider's temporal capabilities.
 
virtual QgsTransactiontransaction () const
 Returns the transaction this data provider is included in, if any.
 
virtual QString translateMetadataKey (const QString &mdKey) const
 Gets the translated metadata key.
 
virtual QString translateMetadataValue (const QString &mdKey, const QVariant &value) const
 Gets the translated metadata value.
 
virtual bool truncate ()
 Removes all features from the layer.
 
virtual QStringList uniqueStringsMatching (int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
 Returns unique string values of an attribute which contain a specified subset string.
 
virtual Qgis::VectorLayerTypeFlags vectorLayerTypeFlags () const
 Returns the vector layer type flags.
 
Qgis::WkbType wkbType () const override=0
 Returns the geometry type which is returned by this layer.
 
- Public Member Functions inherited from QgsDataProvider
 QgsDataProvider (const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
 Create a new dataprovider with the specified in the uri.
 
virtual QgsCoordinateReferenceSystem crs () const =0
 Returns the coordinate system for the data source.
 
virtual QString dataSourceUri (bool expandAuthConfig=false) const
 Gets the data source specification.
 
virtual QDateTime dataTimestamp () const
 Current time stamp of data source.
 
virtual QString description () const =0
 Returns description.
 
virtual QgsDataProviderElevationPropertieselevationProperties ()
 Returns the provider's elevation properties.
 
virtual const QgsDataProviderElevationPropertieselevationProperties () const
 Returns the provider's elevation properties.
 
virtual bool enterUpdateMode ()
 Enter update mode.
 
virtual QgsError error () const
 Gets current status error.
 
virtual QgsRectangle extent () const =0
 Returns the extent of the layer.
 
virtual QString fileRasterFilters () const
 Returns raster file filter string.
 
virtual QString fileVectorFilters () const
 Returns vector file filter string.
 
virtual Qgis::DataProviderFlags flags () const
 Returns the generic data provider flags.
 
virtual void invalidateConnections (const QString &connection)
 Invalidate connections corresponding to specified name.
 
virtual bool isValid () const =0
 Returns true if this is a valid layer.
 
virtual QgsLayerMetadata layerMetadata () const
 Returns layer metadata collected from the provider's source.
 
virtual bool leaveUpdateMode ()
 Leave update mode.
 
virtual QString name () const =0
 Returns a provider name.
 
QVariant providerProperty (int property, const QVariant &defaultValue) const
 Gets the current value of a certain provider property.
 
QVariant providerProperty (ProviderProperty property, const QVariant &defaultValue=QVariant()) const
 Gets the current value of a certain provider property.
 
virtual void reloadData ()
 Reloads the data from the source for providers with data caches to synchronize, changes in the data source, feature counts and other specific actions.
 
virtual bool renderInPreview (const QgsDataProvider::PreviewContext &context)
 Returns whether the layer must be rendered in preview jobs.
 
virtual void setDataSourceUri (const QString &uri)
 Set the data source specification.
 
virtual void setLayerOrder (const QStringList &layers)
 Reorder the list of layer names to be rendered by this provider (in order from bottom to top)
 
virtual void setListening (bool isListening)
 Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.
 
void setProviderProperty (int property, const QVariant &value)
 Allows setting arbitrary properties on the provider.
 
void setProviderProperty (ProviderProperty property, const QVariant &value)
 Allows setting arbitrary properties on the provider.
 
virtual void setSubLayerVisibility (const QString &name, bool vis)
 Set the visibility of the given sublayer name.
 
virtual bool setSubsetString (const QString &subset, bool updateFeatureCount=true)
 Set the subset string used to create a subset of features in the layer.
 
virtual void setTransformContext (const QgsCoordinateTransformContext &transformContext)
 Sets data coordinate transform context to transformContext.
 
void setUri (const QgsDataSourceUri &uri)
 Set the data source specification.
 
virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities () const
 Returns the style storage capabilities.
 
virtual uint subLayerCount () const
 Returns the number of layers for the current data source.
 
virtual QStringList subLayers () const
 Sub-layers handled by this provider, in order from bottom to top.
 
virtual QStringList subLayerStyles () const
 Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top.
 
virtual QString subsetString () const
 Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set.
 
virtual bool supportsSubsetString () const
 Returns true if the provider supports setting of subset strings.
 
virtual QDateTime timestamp () const
 Time stamp of data source in the moment when data/metadata were loaded by provider.
 
QgsCoordinateTransformContext transformContext () const
 Returns data provider coordinate transform context.
 
virtual void updateExtents ()
 Update the extents of the layer.
 
QgsDataSourceUri uri () const
 Gets the data source specification.
 
virtual bool writeLayerMetadata (const QgsLayerMetadata &metadata)
 Writes layer metadata to the underlying provider source.
 
- Public Member Functions inherited from QgsFeatureSink
virtual ~QgsFeatureSink ()=default
 
virtual bool addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
 Adds a single feature to the sink.
 
virtual bool addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
 Adds all features from the specified iterator to the sink.
 
virtual bool flushBuffer ()
 Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination.
 
- Public Member Functions inherited from QgsFeatureSource
virtual ~QgsFeatureSource ()=default
 
virtual QgsFeatureIds allFeatureIds () const
 Returns a list of all feature IDs for features present in the source.
 
virtual SpatialIndexPresence hasSpatialIndex () const
 Returns an enum value representing the presence of a valid spatial index on the source, if it can be determined.
 
QgsVectorLayermaterialize (const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
 Materializes a request (query) made against this feature source, by running it over the source and returning a new memory based vector layer containing the result.
 
virtual QSet< QVariant > uniqueValues (int fieldIndex, int limit=-1) const
 Returns the set of unique values contained within the specified fieldIndex from this source.
 

Static Public Member Functions

static QStringList availableEncodings ()
 Returns a list of available encodings.
 
static QVariant convertValue (QVariant::Type type, const QString &value)
 
- Static Public Member Functions inherited from QgsDataProvider
static QString sublayerSeparator ()
 String sequence used for separating components of sublayers strings.
 

Static Public Attributes

static const int EditingCapabilities
 Bitmask of all provider's editing capabilities.
 

Protected Member Functions

void clearMinMaxCache ()
 Invalidates the min/max cache.
 
QgsGeometry convertToProviderType (const QgsGeometry &geom) const
 Converts the geometry to the provider type if possible / necessary.
 
void fillMinMaxCache () const
 Populates the cache of minimum and maximum attribute values.
 
void pushError (const QString &msg) const
 Push a notification about errors that happened in this providers scope.
 
void setNativeTypes (const QList< QgsVectorDataProvider::NativeType > &nativeTypes)
 Set the list of native types supported by this provider.
 
QTextCodec * textEncoding () const
 Gets this providers encoding.
 
- Protected Member Functions inherited from QgsDataProvider
void appendError (const QgsErrorMessage &message)
 Add error message.
 
void setError (const QgsError &error)
 Sets error message.
 

Static Protected Member Functions

static QgsGeometry convertToProviderType (const QgsGeometry &geometry, Qgis::WkbType providerGeometryType)
 Converts the geometry to the provider geometry type providerGeometryType if possible / necessary.
 

Friends

class QgsTransaction
 
class QgsVectorLayerEditBuffer
 

Additional Inherited Members

- Protected Attributes inherited from QgsDataProvider
QgsError mError
 Error.
 
QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags()
 Read flags. It's up to the subclass to respect these when needed.
 
QDateTime mTimestamp
 Timestamp of data in the moment when the data were loaded by provider.
 

Detailed Description

This is the base class for vector data providers.

Data providers abstract the retrieval and writing (where supported) of feature and attribute information from a spatial datasource.

Definition at line 58 of file qgsvectordataprovider.h.

Member Enumeration Documentation

◆ Capability

enumeration with capabilities that providers might implement

Enumerator
NoCapabilities 

Provider has no capabilities.

AddFeatures 

Allows adding features.

DeleteFeatures 

Allows deletion of features.

ChangeAttributeValues 

Allows modification of attribute values.

AddAttributes 

Allows addition of new attributes (fields)

DeleteAttributes 

Allows deletion of attributes (fields)

CreateSpatialIndex 

Allows creation of spatial index.

SelectAtId 

Fast access to features using their ID.

ChangeGeometries 

Allows modifications of geometries.

SelectEncoding 

Allows user to select encoding.

CreateAttributeIndex 

Can create indexes on provider's fields.

SimplifyGeometries 

Supports simplification of geometries on provider side according to a distance tolerance.

SimplifyGeometriesWithTopologicalValidation 

Supports topological simplification of geometries on provider side according to a distance tolerance.

TransactionSupport 

Supports transactions.

CircularGeometries 

Supports circular geometry types (circularstring, compoundcurve, curvepolygon)

ChangeFeatures 

Supports joint updates for attributes and geometry. Providers supporting this should still define ChangeGeometries | ChangeAttributeValues.

RenameAttributes 

Supports renaming attributes (fields). Since QGIS 2.16.

FastTruncate 

Supports fast truncation of the layer (removing all features). Since QGIS 3.0.

ReadLayerMetadata 

Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata()

WriteLayerMetadata 

Provider can write layer metadata to the data store. Since QGIS 3.0. See QgsDataProvider::writeLayerMetadata()

CancelSupport 

Supports interruption of pending queries from a separated thread. Since QGIS 3.2.

CreateRenderer 

Provider can create feature renderers using backend-specific formatting information. Since QGIS 3.2. See QgsVectorDataProvider::createRenderer().

CreateLabeling 

Provider can set labeling settings using backend-specific formatting information. Since QGIS 3.6. See QgsVectorDataProvider::createLabeling().

ReloadData 

Provider is able to force reload data.

FeatureSymbology 

Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3.20.

Definition at line 72 of file qgsvectordataprovider.h.

Constructor & Destructor Documentation

◆ QgsVectorDataProvider()

QgsVectorDataProvider::QgsVectorDataProvider ( const QString &  uri = QString(),
const QgsDataProvider::ProviderOptions providerOptions = QgsDataProvider::ProviderOptions(),
QgsDataProvider::ReadFlags  flags = QgsDataProvider::ReadFlags() 
)

Constructor for a vector data provider.

The uri argument specifies the uniform resource locator (URI) for the associated dataset.

Additional creation options are specified within the options value and since QGIS 3.16 creation flags are specified within the flags value.

Definition at line 39 of file qgsvectordataprovider.cpp.

Member Function Documentation

◆ addAttributes()

bool QgsVectorDataProvider::addAttributes ( const QList< QgsField > &  attributes)
virtual

Adds new attributes to the provider.

Returns true in case of success and false in case of failure. If attributes are added using this method then QgsVectorLayer::updateFields() must be called manually to ensure that the layer's field are correctly reported.

Definition at line 153 of file qgsvectordataprovider.cpp.

◆ addFeatures()

bool QgsVectorDataProvider::addFeatures ( QgsFeatureList features,
QgsFeatureSink::Flags  flags = QgsFeatureSink::Flags() 
)
overridevirtual

Adds a list of features to the sink.

Feature addition behavior is controlled by the specified flags.

See also
addFeature()
Returns
true in case of success and false in case of failure

Implements QgsFeatureSink.

Definition at line 113 of file qgsvectordataprovider.cpp.

◆ aggregate()

QVariant QgsVectorDataProvider::aggregate ( QgsAggregateCalculator::Aggregate  aggregate,
int  index,
const QgsAggregateCalculator::AggregateParameters parameters,
QgsExpressionContext context,
bool &  ok,
QgsFeatureIds fids = nullptr 
) const
virtual

Calculates an aggregated value from the layer's features.

The base implementation does nothing, but subclasses can override this method to handoff calculation of aggregates to the provider.

Parameters
aggregateaggregate to calculate
indexthe index of the attribute to calculate aggregate over
parametersparameters controlling aggregate calculation
contextexpression context for filter
okwill be set to true if calculation was successfully performed by the data provider
fidslist of fids to filter, otherwise will use all fids
Returns
calculated aggregate value
Since
QGIS 2.16

Definition at line 587 of file qgsvectordataprovider.cpp.

◆ attributeEditCapabilities()

Qgis::VectorDataProviderAttributeEditCapabilities QgsVectorDataProvider::attributeEditCapabilities ( ) const
virtual

Returns the provider's supported attribute editing capabilities.

See also
capabilities()
Since
QGIS 3.32

Definition at line 406 of file qgsvectordataprovider.cpp.

◆ attributeIndexes()

QgsAttributeList QgsVectorDataProvider::attributeIndexes ( ) const
virtual

Returns list of indexes to fetch all attributes in nextFeature()

Definition at line 433 of file qgsvectordataprovider.cpp.

◆ availableEncodings()

QStringList QgsVectorDataProvider::availableEncodings ( )
static

Returns a list of available encodings.

Definition at line 764 of file qgsvectordataprovider.cpp.

◆ cancelReload()

bool QgsVectorDataProvider::cancelReload ( )
virtual

Cancels the current reloading of data.

Returns
true if the reloading has been correctly interrupted, false otherwise
See also
reloadData()
Since
QGIS 3.2

Definition at line 1024 of file qgsvectordataprovider.cpp.

◆ capabilities()

QgsVectorDataProvider::Capabilities QgsVectorDataProvider::capabilities ( ) const
virtual

Returns flags containing the supported capabilities.

Note
, some capabilities may change depending on whether a spatial filter is active on this provider, so it may be prudent to check this value per intended operation.
See also
attributeEditCapabilities()

Definition at line 256 of file qgsvectordataprovider.cpp.

◆ capabilitiesString()

QString QgsVectorDataProvider::capabilitiesString ( ) const

Returns the above in friendly format.

Definition at line 314 of file qgsvectordataprovider.cpp.

◆ changeAttributeValues()

bool QgsVectorDataProvider::changeAttributeValues ( const QgsChangedAttributesMap attr_map)
virtual

Changes attribute values of existing features.

This should succeed if the provider reports the ChangeAttributeValues capability. The method returns false if the provider does not have ChangeAttributeValues capability or if any of the changes could not be successfully applied.

Parameters
attr_mapa map containing changed attributes
Returns
true in case of success and false in case of failure

Definition at line 177 of file qgsvectordataprovider.cpp.

◆ changeFeatures()

bool QgsVectorDataProvider::changeFeatures ( const QgsChangedAttributesMap attr_map,
const QgsGeometryMap geometry_map 
)
virtual

Changes attribute values and geometries of existing features.

This should succeed if the provider reports both the ChangeAttributeValues and ChangeGeometries capabilities. Providers which report the ChangeFeatures capability implement an optimised version of this method.

Parameters
attr_mapa map containing changed attributes
geometry_mapA QgsGeometryMap whose index contains the feature IDs that will have their geometries changed. The second map parameter being the new geometries themselves
Returns
true in case of success and false in case of failure

Definition at line 227 of file qgsvectordataprovider.cpp.

◆ changeGeometryValues()

bool QgsVectorDataProvider::changeGeometryValues ( const QgsGeometryMap geometry_map)
virtual

Changes geometries of existing features.

Parameters
geometry_mapA QgsGeometryMap whose index contains the feature IDs that will have their geometries changed. The second map parameter being the new geometries themselves
Returns
true in case of success and false in case of failure

Definition at line 219 of file qgsvectordataprovider.cpp.

◆ clearErrors()

void QgsVectorDataProvider::clearErrors ( )

Clear recorded errors.

Definition at line 832 of file qgsvectordataprovider.cpp.

◆ clearMinMaxCache()

void QgsVectorDataProvider::clearMinMaxCache ( )
protected

Invalidates the min/max cache.

This will force the provider to recalculate the cache the next time it is requested.

Definition at line 604 of file qgsvectordataprovider.cpp.

◆ convertToProviderType() [1/2]

QgsGeometry QgsVectorDataProvider::convertToProviderType ( const QgsGeometry geom) const
protected

Converts the geometry to the provider type if possible / necessary.

Returns
the converted geometry or nullptr if no conversion was necessary or possible
Note
The default implementation simply calls the static version of this function.

Definition at line 883 of file qgsvectordataprovider.cpp.

◆ convertToProviderType() [2/2]

QgsGeometry QgsVectorDataProvider::convertToProviderType ( const QgsGeometry geometry,
Qgis::WkbType  providerGeometryType 
)
staticprotected

Converts the geometry to the provider geometry type providerGeometryType if possible / necessary.

Returns
the converted geometry or nullptr if no conversion was necessary or possible
Since
QGIS 3.34

Definition at line 907 of file qgsvectordataprovider.cpp.

◆ convertValue()

QVariant QgsVectorDataProvider::convertValue ( QVariant::Type  type,
const QString &  value 
)
static

Definition at line 737 of file qgsvectordataprovider.cpp.

◆ createAttributeIndex()

bool QgsVectorDataProvider::createAttributeIndex ( int  field)
virtual

Create an attribute index on the datasource.

Definition at line 248 of file qgsvectordataprovider.cpp.

◆ createLabeling()

QgsAbstractVectorLayerLabeling * QgsVectorDataProvider::createLabeling ( const QVariantMap &  configuration = QVariantMap()) const
virtual

Creates labeling settings, using provider backend specific information.

The configuration map can be used to pass provider-specific configuration maps to the provider to allow customization of the returned labeling object. Support and format of configuration varies by provider.

When called with an empty configuration map the provider's default labeling settings will be returned.

This method returns a new labeling settings and the caller takes ownership of the returned object.

Only providers which report the CreateLabeling capability will return labeling settings. Other providers will return nullptr.

Since
QGIS 3.6

Definition at line 860 of file qgsvectordataprovider.cpp.

◆ createRenderer()

QgsFeatureRenderer * QgsVectorDataProvider::createRenderer ( const QVariantMap &  configuration = QVariantMap()) const
virtual

Creates a new vector layer feature renderer, using provider backend specific information.

The configuration map can be used to pass provider-specific configuration maps to the provider to allow customization of the returned renderer. Support and format of configuration varies by provider.

When called with an empty configuration map the provider's default renderer will be returned.

This method returns a new renderer and the caller takes ownership of the returned object.

Only providers which report the CreateRenderer capability will return a feature renderer. Other providers will return nullptr.

Since
QGIS 3.2

Definition at line 853 of file qgsvectordataprovider.cpp.

◆ createSpatialIndex()

bool QgsVectorDataProvider::createSpatialIndex ( )
virtual

Creates a spatial index on the datasource (if supported by the provider type).

Returns
true in case of success

Definition at line 241 of file qgsvectordataprovider.cpp.

◆ dataComment()

QString QgsVectorDataProvider::dataComment ( ) const
overridevirtual

Returns a short comment for the data that this provider is providing access to (e.g.

the comment for postgres table).

Reimplemented from QgsDataProvider.

Definition at line 106 of file qgsvectordataprovider.cpp.

◆ defaultValue()

QVariant QgsVectorDataProvider::defaultValue ( int  fieldIndex) const
virtual

Returns any literal default values which are present at the provider for a specified field index.

Important - this should ONLY be called when creating an attribute to insert directly into the database. Do not call this method for non-feature creation or modification, e.g., when validating an attribute or to compare it against an existing value, as calling it can cause changes to the underlying data source (e.g., Postgres provider where the default value is calculated as a result of a sequence). It is recommended that you instead use the methods in QgsVectorLayerUtils such as QgsVectorLayerUtils::createFeature() so that default value handling and validation is automatically carried out.

See also
defaultValueClause()

Definition at line 185 of file qgsvectordataprovider.cpp.

◆ defaultValueClause()

QString QgsVectorDataProvider::defaultValueClause ( int  fieldIndex) const
virtual

Returns any default value clauses which are present at the provider for a specified field index.

These clauses are usually SQL fragments which must be evaluated by the provider, e.g., sequence values.

See also
defaultValue()
Since
QGIS 3.0

Definition at line 193 of file qgsvectordataprovider.cpp.

◆ deleteAttributes()

bool QgsVectorDataProvider::deleteAttributes ( const QgsAttributeIds attributes)
virtual

Deletes existing attributes from the provider.

If attributes are deleted using this method then QgsVectorLayer::updateFields() must be called manually to ensure that the layer's field are correctly reported.

Parameters
attributesa set containing indices of attributes
Returns
true in case of success and false in case of failure

Definition at line 161 of file qgsvectordataprovider.cpp.

◆ deleteFeatures()

bool QgsVectorDataProvider::deleteFeatures ( const QgsFeatureIds id)
virtual

Deletes one or more features from the provider.

This requires the DeleteFeatures capability.

Parameters
idlist containing feature ids to delete
Returns
true in case of success and false in case of failure
See also
truncate()

Definition at line 129 of file qgsvectordataprovider.cpp.

◆ dependencies()

QSet< QgsMapLayerDependency > QgsVectorDataProvider::dependencies ( ) const
virtual

Gets the list of layer ids on which this layer depends.

This in particular determines the order of layer loading.

Definition at line 876 of file qgsvectordataprovider.cpp.

◆ discoverRelations()

QList< QgsRelation > QgsVectorDataProvider::discoverRelations ( const QgsVectorLayer target,
const QList< QgsVectorLayer * > &  layers 
) const
virtual

Discover the available relations with the given layers.

Parameters
targetthe layer using this data provider.
layersthe other layers.
Returns
the list of N-1 relations from this provider.
Since
QGIS 3.0

Definition at line 1033 of file qgsvectordataprovider.cpp.

◆ doesStrictFeatureTypeCheck()

virtual bool QgsVectorDataProvider::doesStrictFeatureTypeCheck ( ) const
inlinevirtual

Returns true if the provider is strict about the type of inserted features (e.g.

no multipolygon in a polygon layer)

Definition at line 515 of file qgsvectordataprovider.h.

◆ empty()

bool QgsVectorDataProvider::empty ( ) const
virtual

Returns true if the layer does not contain any feature.

Since
QGIS 3.4

Definition at line 53 of file qgsvectordataprovider.cpp.

◆ encoding()

QString QgsVectorDataProvider::encoding ( ) const

Returns the encoding which is used for accessing data.

See also
setEncoding()

Definition at line 302 of file qgsvectordataprovider.cpp.

◆ enumValues()

virtual void QgsVectorDataProvider::enumValues ( int  index,
QStringList &  enumList 
) const
inlinevirtual

Returns the possible enum values of an attribute.

Returns an empty stringlist if a provider does not support enum types or if the given attribute is not an enum type.

Parameters
indexthe index of the attribute
enumListreference to the list to fill

Definition at line 270 of file qgsvectordataprovider.h.

◆ errors()

QStringList QgsVectorDataProvider::errors ( ) const

Gets recorded errors.

Definition at line 846 of file qgsvectordataprovider.cpp.

◆ featureCount()

long long QgsVectorDataProvider::featureCount ( ) const
overridepure virtual

Number of features in the layer.

Returns
number of features

Implements QgsFeatureSource.

◆ featureSource()

virtual QgsAbstractFeatureSource * QgsVectorDataProvider::featureSource ( ) const
pure virtual

Returns feature source object that can be used for querying provider's data.

The returned feature source is independent from provider - any changes to provider's state (e.g. change of subset string) will not be reflected in the feature source, therefore it can be safely used for processing in background without having to care about possible changes within provider that may happen concurrently. Also, even in the case of provider being deleted, any feature source obtained from the provider will be kept alive and working (they are independent and owned by the caller).

Sometimes there are cases when some data needs to be shared between vector data provider and its feature source. In such cases, the implementation must ensure that the data is not susceptible to run condition. For example, if it is possible that both feature source and provider may need reading/writing to some shared data at the same time, some synchronization mechanisms must be used (e.g. mutexes) to prevent data corruption.

Returns
new instance of QgsAbstractFeatureSource (caller is responsible for deleting it)
Since
QGIS 2.4

◆ fieldConstraints()

QgsFieldConstraints::Constraints QgsVectorDataProvider::fieldConstraints ( int  fieldIndex) const

Returns any constraints which are present at the provider for a specified field index.

See also
skipConstraintCheck()
Since
QGIS 3.0

Definition at line 201 of file qgsvectordataprovider.cpp.

◆ fieldNameIndex()

int QgsVectorDataProvider::fieldNameIndex ( const QString &  fieldName) const

Returns the index of a field name or -1 if the field does not exist.

Definition at line 411 of file qgsvectordataprovider.cpp.

◆ fieldNameMap()

QMap< QString, int > QgsVectorDataProvider::fieldNameMap ( ) const

Returns a map where the key is the name of the field and the value is its index.

Definition at line 418 of file qgsvectordataprovider.cpp.

◆ fields()

QgsFields QgsVectorDataProvider::fields ( ) const
overridepure virtual

Returns the fields associated with this data provider.

Implements QgsFeatureSource.

◆ fillMinMaxCache()

void QgsVectorDataProvider::fillMinMaxCache ( ) const
protected

Populates the cache of minimum and maximum attribute values.

Definition at line 613 of file qgsvectordataprovider.cpp.

◆ forceReload()

virtual Q_DECL_DEPRECATED void QgsVectorDataProvider::forceReload ( )
inlinevirtual
Deprecated:
QGIS 3.12 - will be removed in QGIS 4.0 - use reloadData instead

Definition at line 579 of file qgsvectordataprovider.h.

◆ getFeatures()

QgsFeatureIterator QgsVectorDataProvider::getFeatures ( const QgsFeatureRequest request = QgsFeatureRequest()) const
overridepure virtual

Query the provider for features specified in request.

Parameters
requestfeature request describing parameters of features to return
Returns
iterator for matching features from provider

Implements QgsFeatureSource.

◆ handlePostCloneOperations()

void QgsVectorDataProvider::handlePostCloneOperations ( QgsVectorDataProvider source)
virtual

Handles any post-clone operations required after this vector data provider was cloned from the source provider.

Since
QGIS 3.8.1

Definition at line 1040 of file qgsvectordataprovider.cpp.

◆ hasErrors()

bool QgsVectorDataProvider::hasErrors ( ) const

Provider has errors to report.

Definition at line 839 of file qgsvectordataprovider.cpp.

◆ hasFeatures()

QgsFeatureSource::FeatureAvailability QgsVectorDataProvider::hasFeatures ( ) const
overridevirtual

Will always return FeatureAvailability::FeaturesAvailable or FeatureAvailability::NoFeaturesAvailable.

Calls empty() internally. Providers should override empty() instead if they provide an optimized version of this call.

See also
empty()
Since
QGIS 3.4

Reimplemented from QgsFeatureSource.

Definition at line 82 of file qgsvectordataprovider.cpp.

◆ hasMetadata()

virtual bool QgsVectorDataProvider::hasMetadata ( ) const
inlinevirtual

Returns true if the data source has metadata, false otherwise.

Returns
true if data source has metadata, false otherwise.
Since
QGIS 3.0

Definition at line 623 of file qgsvectordataprovider.h.

◆ isSqlQuery()

bool QgsVectorDataProvider::isSqlQuery ( ) const
virtual

Returns true if the layer is a query (SQL) layer.

Note
this is simply a shortcut to check if the SqlQuery flag is set.
See also
vectorLayerTypeFlags()
Since
QGIS 3.24

Definition at line 68 of file qgsvectordataprovider.cpp.

◆ lastError()

QString QgsVectorDataProvider::lastError ( ) const
overridevirtual

Returns the most recent error encountered by the sink, e.g.

when a call to addFeatures() returns false.

Since
QGIS 3.16

Reimplemented from QgsFeatureSink.

Definition at line 122 of file qgsvectordataprovider.cpp.

◆ maximumValue()

QVariant QgsVectorDataProvider::maximumValue ( int  index) const
overridevirtual

Returns the maximum value of an attribute.

Parameters
indexthe index of the attribute

Default implementation walks all numeric attributes and caches minimal and maximal values. If provider has facilities to retrieve maximal value directly, override this function.

Reimplemented from QgsFeatureSource.

Definition at line 531 of file qgsvectordataprovider.cpp.

◆ metadata()

virtual QVariantMap QgsVectorDataProvider::metadata ( ) const
inlinevirtual

Gets metadata, dependent on the provider type, that will be display in the metadata tab of the layer properties.

Returns
The provider metadata

Definition at line 599 of file qgsvectordataprovider.h.

◆ minimumValue()

QVariant QgsVectorDataProvider::minimumValue ( int  index) const
overridevirtual

Returns the minimum value of an attribute.

Parameters
indexthe index of the attribute

Default implementation walks all numeric attributes and caches minimal and maximal values. If provider has facilities to retrieve minimal value directly, override this function.

Reimplemented from QgsFeatureSource.

Definition at line 513 of file qgsvectordataprovider.cpp.

◆ nativeTypes()

QList< QgsVectorDataProvider::NativeType > QgsVectorDataProvider::nativeTypes ( ) const

Returns the names of the supported types.

Definition at line 447 of file qgsvectordataprovider.cpp.

◆ palAttributeIndexNames()

QgsAttrPalIndexNameHash QgsVectorDataProvider::palAttributeIndexNames ( ) const

Returns list of indexes to names for QgsPalLabeling fix.

Deprecated:
since QGIS 3.32 this method is unused and will always return an empty hash

Definition at line 454 of file qgsvectordataprovider.cpp.

◆ pkAttributeIndexes()

QgsAttributeList QgsVectorDataProvider::pkAttributeIndexes ( ) const
virtual

Returns list of indexes of fields that make up the primary key.

Definition at line 440 of file qgsvectordataprovider.cpp.

◆ pushError()

void QgsVectorDataProvider::pushError ( const QString &  msg) const
protected

Push a notification about errors that happened in this providers scope.

Errors should be translated strings that require the users immediate attention.

For general debug information use QgsMessageLog::logMessage() instead.

Since
QGIS 3.0

Definition at line 867 of file qgsvectordataprovider.cpp.

◆ raiseError

void QgsVectorDataProvider::raiseError ( const QString &  msg) const
signal

Signals an error in this provider.

Since
QGIS 3.0

◆ renameAttributes()

bool QgsVectorDataProvider::renameAttributes ( const QgsFieldNameMap renamedAttributes)
virtual

Renames existing attributes.

If attributes are renamed using this method then QgsVectorLayer::updateFields() must be called manually to ensure that the layer's field are correctly reported.

Parameters
renamedAttributesmap of attribute index to new attribute name
Returns
true in case of success and false in case of failure
Since
QGIS 2.16

Definition at line 169 of file qgsvectordataprovider.cpp.

◆ setEncoding()

void QgsVectorDataProvider::setEncoding ( const QString &  e)
virtual

Set encoding used for accessing data from layer.

An empty encoding string indicates that the provider should automatically select the most appropriate encoding for the data source.

Warning
Support for setting the provider encoding depends on the underlying data provider. Check capabilities() for the QgsVectorDataProvider::SelectEncoding capability in order to determine if the provider supports this ability.
See also
encoding()

Definition at line 263 of file qgsvectordataprovider.cpp.

◆ setNativeTypes()

void QgsVectorDataProvider::setNativeTypes ( const QList< QgsVectorDataProvider::NativeType > &  nativeTypes)
protected

Set the list of native types supported by this provider.

Usually done in the constructor.

Since
QGIS 3.0

Definition at line 892 of file qgsvectordataprovider.cpp.

◆ skipConstraintCheck()

bool QgsVectorDataProvider::skipConstraintCheck ( int  fieldIndex,
QgsFieldConstraints::Constraint  constraint,
const QVariant &  value = QVariant() 
) const
virtual

Returns true if a constraint check should be skipped for a specified field (e.g., if the value returned by defaultValue() is trusted implicitly.

An optional attribute value can be passed which can help refine the skip constraint check.

See also
fieldConstraints()
Since
QGIS 3.0

Definition at line 212 of file qgsvectordataprovider.cpp.

◆ sourceCrs()

QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs ( ) const
overridevirtual

Returns the coordinate reference system for features in the source.

Implements QgsFeatureSource.

Definition at line 92 of file qgsvectordataprovider.cpp.

◆ sourceExtent()

QgsRectangle QgsVectorDataProvider::sourceExtent ( ) const
overridevirtual

Returns the extent of all geometries from the source.

The base class implementation uses a non-optimised approach of looping through all features in the source.

Reimplemented from QgsFeatureSource.

Definition at line 99 of file qgsvectordataprovider.cpp.

◆ sourceName()

QString QgsVectorDataProvider::sourceName ( ) const
inlineoverridevirtual

Returns a friendly display name for the source.

The returned value can be an empty string.

Implements QgsFeatureSource.

Definition at line 205 of file qgsvectordataprovider.h.

◆ storageType()

QString QgsVectorDataProvider::storageType ( ) const
virtual

Returns the permanent storage type for this layer as a friendly name.

Definition at line 46 of file qgsvectordataprovider.cpp.

◆ supportedType()

bool QgsVectorDataProvider::supportedType ( const QgsField field) const

check if provider supports type of field

Definition at line 461 of file qgsvectordataprovider.cpp.

◆ temporalCapabilities() [1/2]

const QgsVectorDataProviderTemporalCapabilities * QgsVectorDataProvider::temporalCapabilities ( ) const
overridevirtual

Returns the provider's temporal capabilities.

This may be nullptr, depending on the data provider.

Since
QGIS 3.14

Reimplemented from QgsDataProvider.

Definition at line 1053 of file qgsvectordataprovider.cpp.

◆ temporalCapabilities() [2/2]

QgsVectorDataProviderTemporalCapabilities * QgsVectorDataProvider::temporalCapabilities ( )
overridevirtual

Returns the provider's temporal capabilities.

This may be nullptr, depending on the data provider.

Since
QGIS 3.14

Reimplemented from QgsDataProvider.

Definition at line 1046 of file qgsvectordataprovider.cpp.

◆ textEncoding()

QTextCodec * QgsVectorDataProvider::textEncoding ( ) const
protected

Gets this providers encoding.

Since
QGIS 3.0

Definition at line 899 of file qgsvectordataprovider.cpp.

◆ transaction()

QgsTransaction * QgsVectorDataProvider::transaction ( ) const
virtual

Returns the transaction this data provider is included in, if any.

Definition at line 747 of file qgsvectordataprovider.cpp.

◆ translateMetadataKey()

virtual QString QgsVectorDataProvider::translateMetadataKey ( const QString &  mdKey) const
inlinevirtual

Gets the translated metadata key.

Parameters
mdKeyThe metadata key
Returns
The translated metadata value

Definition at line 606 of file qgsvectordataprovider.h.

◆ translateMetadataValue()

virtual QString QgsVectorDataProvider::translateMetadataValue ( const QString &  mdKey,
const QVariant &  value 
) const
inlinevirtual

Gets the translated metadata value.

Parameters
mdKeyThe metadata key
valueThe metadata value
Returns
The translated metadata value

Definition at line 614 of file qgsvectordataprovider.h.

◆ truncate()

bool QgsVectorDataProvider::truncate ( )
virtual

Removes all features from the layer.

This requires either the FastTruncate or DeleteFeatures capability. Providers with the FastTruncate capability will use an optimised method to truncate the layer.

Returns
true in case of success and false in case of failure.
See also
deleteFeatures()
Since
QGIS 3.0

Definition at line 137 of file qgsvectordataprovider.cpp.

◆ uniqueStringsMatching()

QStringList QgsVectorDataProvider::uniqueStringsMatching ( int  index,
const QString &  substring,
int  limit = -1,
QgsFeedback feedback = nullptr 
) const
virtual

Returns unique string values of an attribute which contain a specified subset string.

Subset matching is done in a case-insensitive manner.

Parameters
indexthe index of the attribute
substringsubstring to match (case insensitive)
limitmaxmum number of the values to return, or -1 to return all unique values
feedbackoptional feedback object for canceling request
Returns
list of unique strings containing substring

Definition at line 549 of file qgsvectordataprovider.cpp.

◆ vectorLayerTypeFlags()

Qgis::VectorLayerTypeFlags QgsVectorDataProvider::vectorLayerTypeFlags ( ) const
virtual

Returns the vector layer type flags.

See also
isSqlQuery()
Since
QGIS 3.24

Definition at line 75 of file qgsvectordataprovider.cpp.

◆ wkbType()

Qgis::WkbType QgsVectorDataProvider::wkbType ( ) const
overridepure virtual

Returns the geometry type which is returned by this layer.

Implements QgsFeatureSource.

Friends And Related Symbol Documentation

◆ QgsTransaction

friend class QgsTransaction
friend

Definition at line 62 of file qgsvectordataprovider.h.

◆ QgsVectorLayerEditBuffer

friend class QgsVectorLayerEditBuffer
friend

Definition at line 63 of file qgsvectordataprovider.h.

Member Data Documentation

◆ EditingCapabilities

const int QgsVectorDataProvider::EditingCapabilities
static
Initial value:
@ ChangeGeometries
Allows modifications of geometries.
@ DeleteAttributes
Allows deletion of attributes (fields)
@ DeleteFeatures
Allows deletion of features.
@ AddAttributes
Allows addition of new attributes (fields)
@ RenameAttributes
Supports renaming attributes (fields). Since QGIS 2.16.
@ ChangeAttributeValues
Allows modification of attribute values.
@ AddFeatures
Allows adding features.

Bitmask of all provider's editing capabilities.

Definition at line 104 of file qgsvectordataprovider.h.


The documentation for this class was generated from the following files: