QGIS/python/core/qgsvectordataprovider.sip

329 lines
11 KiB
Plaintext
Raw Normal View History

class QgsVectorDataProvider : QgsDataProvider
{
%TypeHeaderCode
#include <qgsvectordataprovider.h>
%End
public:
// If you add to this, please also add to capabilitiesString()
/**
* enumeration with capabilities that providers might implement
*/
enum Capability
{
2014-01-26 18:35:21 +01:00
/** provider has no capabilities */
2014-05-27 23:22:50 +02:00
NoCapabilities,
2014-01-26 18:35:21 +01:00
/** allows adding features */
2014-05-27 23:22:50 +02:00
AddFeatures,
2014-01-26 18:35:21 +01:00
/** allows deletion of features */
2014-05-27 23:22:50 +02:00
DeleteFeatures,
2014-01-26 18:35:21 +01:00
/** allows modification of attribute values */
2014-05-27 23:22:50 +02:00
ChangeAttributeValues,
2014-01-26 18:35:21 +01:00
/** allows addition of new attributes (fields) */
2014-05-27 23:22:50 +02:00
AddAttributes,
2014-01-26 18:35:21 +01:00
/** allows deletion of attributes (fields) */
2014-05-27 23:22:50 +02:00
DeleteAttributes,
2014-01-26 18:35:21 +01:00
/** DEPRECATED - do not use */
2014-05-27 23:22:50 +02:00
SaveAsShapefile,
2014-01-26 18:35:21 +01:00
/** allows creation of spatial index */
2014-05-27 23:22:50 +02:00
CreateSpatialIndex,
2014-01-26 18:35:21 +01:00
/** fast access to features using their ID */
2014-05-27 23:22:50 +02:00
SelectAtId,
2014-01-26 18:35:21 +01:00
/** allows modifications of geometries */
2014-05-27 23:22:50 +02:00
ChangeGeometries,
2014-01-26 18:35:21 +01:00
/** DEPRECATED - do not use */
2014-05-27 23:22:50 +02:00
SelectGeometryAtId,
2014-01-26 18:35:21 +01:00
/** DEPRECATED - do not use */
2014-05-27 23:22:50 +02:00
RandomSelectGeometryAtId,
2014-01-26 18:35:21 +01:00
/** DEPRECATED - do not use */
2014-05-27 23:22:50 +02:00
SequentialSelectGeometryAtId,
CreateAttributeIndex,
2014-01-26 18:35:21 +01:00
/** allows user to select encoding */
2014-05-27 23:22:50 +02:00
SelectEncoding,
2014-01-26 18:35:21 +01:00
/** supports simplification of geometries on provider side according to a distance tolerance */
2014-05-27 23:22:50 +02:00
SimplifyGeometries,
2014-01-26 18:35:21 +01:00
/** supports topological simplification of geometries on provider side according to a distance tolerance */
2014-05-27 23:22:50 +02:00
SimplifyGeometriesWithTopologicalValidation,
2015-02-03 02:21:52 +01:00
/** supports transactions*/
2015-02-03 20:47:20 +11:00
TransactionSupport
};
/** bitmask of all provider's editing capabilities */
static const int EditingCapabilities;
/**
* Constructor of the vector provider
* @param uri uniform resource locator (URI) for a dataset
*/
QgsVectorDataProvider( QString uri = QString() );
/**
* Destructor
*/
virtual ~QgsVectorDataProvider();
/**
* Return 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.
*
* @note added in 2.4
* @return new instance of QgsAbstractFeatureSource (caller is responsible for deleting it)
*/
virtual QgsAbstractFeatureSource* featureSource() const /Factory/;
/**
* Returns the permanent storage type for this layer as a friendly name.
*/
virtual QString storageType() const;
2012-10-09 20:57:35 +02:00
/**
* Query the provider for features specified in request.
*/
2012-10-09 20:57:35 +02:00
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
/**
* Get feature type.
* @return int representing the feature type
*/
virtual QGis::WkbType geometryType() const = 0;
/**
* Number of features in the layer
* @return long containing number of features
*/
virtual long featureCount() const = 0;
/**
* Return a map of indexes with field names for this layer
* @return map of fields
2014-11-21 01:17:21 +01:00
* @see QgsFields
*/
virtual const QgsFields &fields() const = 0;
/**
* Return a short comment for the data that this provider is
* providing access to (e.g. the comment for postgres table).
*/
virtual QString dataComment() const;
/**
* Returns the minimum value of an attribute
* @param index the 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.
*/
virtual QVariant minimumValue( int index );
/**
* Returns the maximum value of an attribute
* @param index the 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.
*/
virtual QVariant maximumValue( int index );
/**
* Return unique values of an attribute
* @param index the index of the attribute
* @param uniqueValues values reference to the list to fill
2014-11-21 01:17:21 +01:00
* @param limit maxmum number of the values to return
*
* Default implementation simply iterates the features
*/
virtual void uniqueValues( int index, QList<QVariant> &uniqueValues /Out/, int limit = -1 );
2014-01-26 18:35:21 +01:00
/**
* 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.
* @param index the index of the attribute
* @param enumList reference to the list to fill
2014-01-26 18:35:21 +01:00
*/
virtual void enumValues( int index, QStringList& enumList /Out/ );
/**
* Adds a list of features
* @return true in case of success and false in case of failure
*/
virtual bool addFeatures( QList<QgsFeature> &flist /In,Out/ );
/**
* Deletes one or more features
* @param id list containing feature ids to delete
* @return true in case of success and false in case of failure
*/
virtual bool deleteFeatures( const QSet<qint64> &id );
/**
* Adds new attributes
* @param attributes list of new attributes
* @return true in case of success and false in case of failure
*/
virtual bool addAttributes( const QList<QgsField> &attributes );
/**
* Deletes existing attributes
* @param attributes a set containing indices of attributes
* @return true in case of success and false in case of failure
*/
virtual bool deleteAttributes( const QSet<int> &attributes );
/**
* Changes attribute values of existing features.
* @param attr_map a map containing changed attributes
* @return true in case of success and false in case of failure
*/
virtual bool changeAttributeValues( const QMap<qint64, QMap<int, QVariant> > &attr_map );
/**
* Returns the default value for field specified by @c fieldId
*/
virtual QVariant defaultValue( int fieldId );
/**
* Changes geometries of existing features
* @param geometry_map A QgsGeometryMap whose index contains the feature IDs
* that will have their geometries changed.
* The second map parameter being the new geometries themselves
* @return True in case of success and false in case of failure
*/
virtual bool changeGeometryValues( QMap<qint64, QgsGeometry> & geometry_map );
/**
* Creates a spatial index on the datasource (if supported by the provider type).
* @return true in case of success
*/
virtual bool createSpatialIndex();
/**Create an attribute index on the datasource*/
virtual bool createAttributeIndex( int field );
/** Returns a bitmask 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.
*/
virtual int capabilities() const;
/**
* Returns the above in friendly format.
*/
QString capabilitiesString() const;
/**
* Set encoding used for accessing data from layer
*/
virtual void setEncoding( const QString& e );
/**
* Get encoding which is used for accessing data
*/
QString encoding() const;
/**
* Returns the index of a field name or -1 if the field does not exist
*/
int fieldNameIndex( const QString& fieldName ) const;
2014-01-26 18:35:21 +01:00
/**
* Return a map where the key is the name of the field and the value is its index
*/
QMap<QString, int> fieldNameMap() const;
/**
* Return list of indexes to fetch all attributes in nextFeature()
*/
QList<int> attributeIndexes();
/**
* Return list of indexes of fields that make up the primary key
*/
virtual QList<int> pkAttributeIndexes();
/**
* Return list of indexes to names for QgsPalLabeling fix
*/
virtual QHash<int, QString> palAttributeIndexNames() const;
/**
* check if provider supports type of field
*/
bool supportedType( const QgsField &field ) const;
struct NativeType
{
NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 );
QString mTypeDesc;
QString mTypeName;
QVariant::Type mType;
int mMinLen;
int mMaxLen;
int mMinPrec;
int mMaxPrec;
};
/**
* Returns the names of the supported types
*/
const QList< QgsVectorDataProvider::NativeType > &nativeTypes() const;
2014-11-21 01:17:21 +01:00
/**
* Returns true if the provider is strict about the type of inserted features
* (e.g. no multipolygon in a polygon layer)
*/
bool doesStrictFeatureTypeCheck() const;
/** Returns a list of available encodings */
static const QStringList &availableEncodings();
2014-01-26 18:35:21 +01:00
/**
* Provider has errors to report
*/
bool hasErrors();
2014-01-26 18:35:21 +01:00
/**
* Clear recorded errors
*/
void clearErrors();
2014-01-26 18:35:21 +01:00
/**
* Get recorded errors
*/
QStringList errors();
/**
* It returns false by default.
* Must be implemented by providers that support saving and loading styles to db returning true
*/
virtual bool isSaveAndLoadStyleToDBSupported();
static QVariant convertValue( QVariant::Type type, QString value );
2015-02-03 02:21:52 +01:00
/**
* Returns the transaction this data provider is included in, if any.
*/
virtual QgsTransaction* transaction() const;
2014-05-27 23:22:50 +02:00
protected:
void clearMinMaxCache();
void fillMinMaxCache();
void pushError( QString msg );
};