QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 Q_DECL_DEPRECATED QgsAttrPalIndexNameHash palAttributeIndexNames() const SIP_DEPRECATED;
433
437 bool supportedType( const QgsField &field ) const;
438
440 {
441 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 )
442 : mTypeDesc( typeDesc )
443 , mTypeName( typeName )
444 , mType( type )
445 , mMinLen( minLen )
446 , mMaxLen( maxLen )
447 , mMinPrec( minPrec )
448 , mMaxPrec( maxPrec )
449 , mSubType( subType )
450 {}
451
452 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 )
453 : mTypeDesc( typeDesc )
454 , mTypeName( typeName )
455 , mType( QgsVariantUtils::variantTypeToMetaType( type ) )
456 , mMinLen( minLen )
457 , mMaxLen( maxLen )
458 , mMinPrec( minPrec )
459 , mMaxPrec( maxPrec )
460 , mSubType( QgsVariantUtils::variantTypeToMetaType( subType ) ) SIP_DEPRECATED
461 {}
462
463
464 QString mTypeDesc;
465 QString mTypeName;
466 QMetaType::Type mType;
471 QMetaType::Type mSubType;
472 };
473
477 QList< QgsVectorDataProvider::NativeType > nativeTypes() const;
478
483 virtual bool doesStrictFeatureTypeCheck() const { return true; }
484
486 static QStringList availableEncodings();
487
491 bool hasErrors() const;
492
496 void clearErrors();
497
501 QStringList errors() const;
502
518 virtual QgsFeatureRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
519
535 virtual QgsAbstractVectorLayerLabeling *createLabeling( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
536
540 static QVariant convertValue( QMetaType::Type type, const QString &value );
541
547 Q_DECL_DEPRECATED static QVariant convertValue( QVariant::Type type, const QString &value ) SIP_DEPRECATED;
548
552 virtual QgsTransaction *transaction() const;
553
557 Q_DECL_DEPRECATED virtual void forceReload() SIP_DEPRECATED { reloadData(); }
558
562 virtual QSet<QgsMapLayerDependency> dependencies() const;
563
570 virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer *target, const QList<QgsVectorLayer *> &layers ) const;
571
576 virtual QVariantMap metadata() const { return QVariantMap(); }
577
583 virtual QString translateMetadataKey( const QString &mdKey ) const { return mdKey; }
584
591 virtual QString translateMetadataValue( const QString &mdKey, const QVariant &value ) const { Q_UNUSED( mdKey ) return value.toString(); }
592
599 virtual bool hasMetadata() const { return true; }
600
607 virtual void handlePostCloneOperations( QgsVectorDataProvider *source );
608
611
612 QgsDataProviderElevationProperties *elevationProperties() override;
613 const QgsDataProviderElevationProperties *elevationProperties() const override SIP_SKIP;
614
615 signals:
616
621 void raiseError( const QString &msg ) const;
622
623 protected:
624
629 void clearMinMaxCache();
630
634 void fillMinMaxCache() const;
635
644 void pushError( const QString &msg ) const;
645
651 QgsGeometry convertToProviderType( const QgsGeometry &geom ) const;
652
658 void setNativeTypes( const QList<QgsVectorDataProvider::NativeType> &nativeTypes );
659
660#ifdef SIP_PYQT5_RUN
661
666 QTextCodec *textEncoding() const;
667#endif
668
674 static QgsGeometry convertToProviderType( const QgsGeometry &geometry, Qgis::WkbType providerGeometryType );
675
676
677 private:
678 mutable bool mCacheMinMaxDirty = true;
679 mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
680
682 QTextCodec *mEncoding = nullptr;
683
685 QgsAttributeList mAttributesToFetch;
686
688 QList< NativeType > mNativeTypes;
689
691 mutable QStringList mErrors;
692
693 std::unique_ptr< QgsVectorDataProviderTemporalCapabilities > mTemporalCapabilities;
694 std::unique_ptr< QgsDataProviderElevationProperties > mElevationProperties;
695
696 static QStringList sEncodings;
697
701 virtual void setTransaction( QgsTransaction * /*transaction*/ ) {}
702};
703
704#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:5400
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)