QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Classes | Public Types | Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
QgsDataProvider Class Referenceabstract

Abstract base class for spatial data provider implementations. More...

#include <qgsdataprovider.h>

Inheritance diagram for QgsDataProvider:
Inheritance graph
[legend]

Classes

struct  PreviewContext
 Stores settings related to the context in which a preview job runs. More...
 
struct  ProviderOptions
 Setting options for creating vector data providers. More...
 

Public Types

enum  DataCapability {
  NoDataCapabilities = 0, File = 1, Dir = 1 << 1, Database = 1 << 2,
  Net = 1 << 3
}
 
enum  ProviderProperty { EvaluateDefaultValues, CustomData = 3000 }
 Properties are used to pass custom configuration options into data providers. More...
 

Signals

void dataChanged ()
 This is emitted whenever an asynchronous operation has finished and the data should be redrawn. More...
 
void fullExtentCalculated ()
 This is emitted whenever the worker thread has fully calculated the PostGIS extents for this layer, and its event has been received by this provider. More...
 
void notify (const QString &msg)
 Emitted when datasource issues a notification. More...
 

Public Member Functions

 QgsDataProvider (const QString &uri=QString(), const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
 Create a new dataprovider with the specified in the uri. More...
 
virtual QgsCoordinateReferenceSystem crs () const =0
 Returns the coordinate system for the data source. More...
 
virtual QString dataSourceUri (bool expandAuthConfig=false) const
 Gets the data source specification. More...
 
virtual QDateTime dataTimestamp () const
 Current time stamp of data source. More...
 
virtual QString description () const =0
 Returns description. More...
 
virtual bool enterUpdateMode ()
 Enter update mode. More...
 
virtual QgsError error () const
 Gets current status error. More...
 
virtual QgsRectangle extent () const =0
 Returns the extent of the layer. More...
 
virtual QString fileRasterFilters () const
 Returns raster file filter string. More...
 
virtual QString fileVectorFilters () const
 Returns vector file filter string. More...
 
virtual void invalidateConnections (const QString &connection)
 Invalidate connections corresponding to specified name. More...
 
virtual bool isValid () const =0
 Returns true if this is a valid layer. More...
 
virtual QgsLayerMetadata layerMetadata () const
 Returns layer metadata collected from the provider's source. More...
 
virtual bool leaveUpdateMode ()
 Leave update mode. More...
 
virtual QString name () const =0
 Returns a provider name. More...
 
QVariant providerProperty (ProviderProperty property, const QVariant &defaultValue=QVariant()) const
 Gets the current value of a certain provider property. More...
 
QVariant providerProperty (int property, const QVariant &defaultValue) const
 Gets the current value of a certain provider property. More...
 
virtual void reloadData ()
 Reloads the data from the source. More...
 
virtual bool renderInPreview (const QgsDataProvider::PreviewContext &context)
 Returns whether the layer must be rendered in preview jobs. More...
 
virtual void setDataSourceUri (const QString &uri)
 Set the data source specification. More...
 
virtual void setLayerOrder (const QStringList &layers)
 Reorder the list of layer names to be rendered by this provider (in order from bottom to top) More...
 
virtual void setListening (bool isListening)
 Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals. More...
 
void setProviderProperty (ProviderProperty property, const QVariant &value)
 Allows setting arbitrary properties on the provider. More...
 
void setProviderProperty (int property, const QVariant &value)
 Allows setting arbitrary properties on the provider. More...
 
virtual void setSubLayerVisibility (const QString &name, bool vis)
 Set the visibility of the given sublayer name. More...
 
virtual bool setSubsetString (const QString &subset, bool updateFeatureCount=true)
 Set the subset string used to create a subset of features in the layer. More...
 
void setUri (const QgsDataSourceUri &uri)
 Set the data source specification. More...
 
virtual uint subLayerCount () const
 Returns the number of layers for the current data source. More...
 
virtual QStringList subLayers () const
 Sub-layers handled by this provider, in order from bottom to top. More...
 
virtual QStringList subLayerStyles () const
 Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top. More...
 
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. More...
 
virtual bool supportsSubsetString () const
 Returns true if the provider supports setting of subset strings. More...
 
virtual QDateTime timestamp () const
 Time stamp of data source in the moment when data/metadata were loaded by provider. More...
 
virtual void updateExtents ()
 Update the extents of the layer. More...
 
QgsDataSourceUri uri () const
 Gets the data source specification. More...
 
virtual bool writeLayerMetadata (const QgsLayerMetadata &metadata)
 Writes layer metadata to the underlying provider source. More...
 

Static Public Attributes

static QString SUBLAYER_SEPARATOR = QString( "!!::!!" )
 String sequence used for separating components of sublayers strings. More...
 

Protected Member Functions

void appendError (const QgsErrorMessage &message)
 Add error message. More...
 
void setError (const QgsError &error)
 Sets error message. More...
 

Protected Attributes

QgsError mError
 Error. More...
 
QDateTime mTimestamp
 Timestamp of data in the moment when the data were loaded by provider. More...
 

Detailed Description

Abstract base class for spatial data provider implementations.

This object needs to inherit from QObject to enable event processing in the Postgres/PostGIS provider (QgsPostgresProvider). It is called here so that this vtable and the vtable for QgsPostgresProvider don't get misaligned - the QgsVectorLayer class factory (which refers to generic QgsVectorDataProvider's) depends on it.

Definition at line 49 of file qgsdataprovider.h.

Member Enumeration Documentation

Enumerator
NoDataCapabilities 
File 
Dir 
Database 
Net 

Definition at line 76 of file qgsdataprovider.h.

Properties are used to pass custom configuration options into data providers.

This enum defines a list of custom properties which can be used on different providers. It depends on the provider, which properties are supported. In addition to these default properties, providers can add their custom properties starting from CustomData.

Enumerator
EvaluateDefaultValues 

Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ) rather than on commit.

CustomData 

Custom properties for 3rd party providers or very provider-specific properties which are not expected to be of interest for other providers can be added starting from this value up.

Definition at line 93 of file qgsdataprovider.h.

Constructor & Destructor Documentation

QgsDataProvider::QgsDataProvider ( const QString &  uri = QString(),
const QgsDataProvider::ProviderOptions options = QgsDataProvider::ProviderOptions() 
)
inline

Create a new dataprovider with the specified in the uri.

Additional creation options are specified within the options value.

Definition at line 114 of file qgsdataprovider.h.

Member Function Documentation

void QgsDataProvider::appendError ( const QgsErrorMessage message)
inlineprotected

Add error message.

Definition at line 573 of file qgsdataprovider.h.

virtual QgsCoordinateReferenceSystem QgsDataProvider::crs ( ) const
pure virtual

Returns the coordinate system for the data source.

If the provider isn't capable of returning its projection then an invalid QgsCoordinateReferenceSystem will be returned.

void QgsDataProvider::dataChanged ( )
signal

This is emitted whenever an asynchronous operation has finished and the data should be redrawn.

When emitted from a QgsVectorDataProvider, any cached information such as feature ids should be invalidated.

virtual QString QgsDataProvider::dataSourceUri ( bool  expandAuthConfig = false) const
inlinevirtual

Gets the data source specification.

This may be a path or database connection string

Parameters
expandAuthConfigWhether to expand any assigned authentication configuration
Returns
data source specification
Note
The default authentication configuration expansion is FALSE. This keeps credentials out of layer data source URIs and project files. Expansion should be specifically done only when needed within a provider

Definition at line 147 of file qgsdataprovider.h.

virtual QDateTime QgsDataProvider::dataTimestamp ( ) const
inlinevirtual

Current time stamp of data source.

Reimplemented in QgsRasterDataProvider.

Definition at line 381 of file qgsdataprovider.h.

virtual QString QgsDataProvider::description ( ) const
pure virtual

Returns description.

Returns a terse string describing what the provider is.

Note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

virtual bool QgsDataProvider::enterUpdateMode ( )
inlinevirtual

Enter update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. A call to this method shall be balanced with a call to leaveUpdateMode(), if this method returns true.

Most providers will have an empty implementation for that method.

For backward compatibility, providers that implement enterUpdateMode() should still make sure to allow editing operations to work even if enterUpdateMode() is not explicitly called.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the first call to enterUpdateMode() will really turn update mode on.

Returns
true in case of success (or no-op implementation), false in case of failure.
Since
QGIS 2.16

Definition at line 418 of file qgsdataprovider.h.

virtual QgsError QgsDataProvider::error ( ) const
inlinevirtual

Gets current status error.

This error describes some principal problem for which provider cannot work and thus is not valid. It is not last error after accessing data by block(), identify() etc.

Definition at line 388 of file qgsdataprovider.h.

virtual QgsRectangle QgsDataProvider::extent ( ) const
pure virtual

Returns the extent of the layer.

Returns
QgsRectangle containing the extent of the layer

Implemented in QgsMeshDataProvider, and QgsRasterDataProvider.

virtual QString QgsDataProvider::fileRasterFilters ( ) const
inlinevirtual

Returns raster file filter string.

Returns a string suitable for a QFileDialog of raster file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note
It'd be nice to eventually be raster/vector neutral.

Definition at line 366 of file qgsdataprovider.h.

virtual QString QgsDataProvider::fileVectorFilters ( ) const
inlinevirtual

Returns vector file filter string.

Returns a string suitable for a QFileDialog of vector file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note
It'd be nice to eventually be raster/vector neutral.

Definition at line 350 of file qgsdataprovider.h.

void QgsDataProvider::fullExtentCalculated ( )
signal

This is emitted whenever the worker thread has fully calculated the PostGIS extents for this layer, and its event has been received by this provider.

virtual void QgsDataProvider::invalidateConnections ( const QString &  connection)
inlinevirtual

Invalidate connections corresponding to specified name.

Since
QGIS 2.16

Definition at line 394 of file qgsdataprovider.h.

virtual bool QgsDataProvider::isValid ( ) const
pure virtual

Returns true if this is a valid layer.

It is up to individual providers to determine what constitutes a valid layer.

virtual QgsLayerMetadata QgsDataProvider::layerMetadata ( ) const
inlinevirtual

Returns layer metadata collected from the provider's source.

Individual data providers must implement this method if they support collecting metadata.

See also
writeLayerMetadata()
Since
QGIS 3.0

Definition at line 522 of file qgsdataprovider.h.

virtual bool QgsDataProvider::leaveUpdateMode ( )
inlinevirtual

Leave update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. This method shall be balanced with a successful call to enterUpdateMode().

Most providers will have an empty implementation for that method.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the last call to leaveUpdateMode() will really turn update mode off.

Returns
true in case of success (or no-op implementation), false in case of failure.
Since
QGIS 2.16

Definition at line 437 of file qgsdataprovider.h.

virtual QString QgsDataProvider::name ( ) const
pure virtual

Returns a provider name.

Essentially just returns the provider key. Should be used to build file dialogs so that providers can be shown with their supported types. Thus if more than one provider supports a given format, the user is able to select a specific provider to open that file.

Note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

void QgsDataProvider::notify ( const QString &  msg)
signal

Emitted when datasource issues a notification.

See also
setListening
Since
QGIS 3.0
QVariant QgsDataProvider::providerProperty ( QgsDataProvider::ProviderProperty  property,
const QVariant &  defaultValue = QVariant() 
) const

Gets the current value of a certain provider property.

It depends on the provider which properties are supported.

Since
QGIS 2.16

Definition at line 30 of file qgsdataprovider.cpp.

QVariant QgsDataProvider::providerProperty ( int  property,
const QVariant &  defaultValue = QVariant() 
) const

Gets the current value of a certain provider property.

It depends on the provider which properties are supported.

Since
QGIS 2.16

Definition at line 35 of file qgsdataprovider.cpp.

virtual void QgsDataProvider::reloadData ( )
inlinevirtual

Reloads the data from the source.

Needs to be implemented by providers with data caches to synchronize with changes in the data source

Definition at line 375 of file qgsdataprovider.h.

bool QgsDataProvider::renderInPreview ( const QgsDataProvider::PreviewContext context)
virtual

Returns whether the layer must be rendered in preview jobs.

The context argument gives useful information which can be used to determine whether the layer should be rendered or not.

The base implementation returns true if lastRenderingTimeMs <= maxRenderingTimeMs.

Note
not available in Python bindings
Since
QGIS 3.0

Definition at line 45 of file qgsdataprovider.cpp.

virtual void QgsDataProvider::setDataSourceUri ( const QString &  uri)
inlinevirtual

Set the data source specification.

This may be a path or database connection string

Parameters
urisource specification

Definition at line 133 of file qgsdataprovider.h.

void QgsDataProvider::setError ( const QgsError error)
inlineprotected

Sets error message.

Definition at line 576 of file qgsdataprovider.h.

virtual void QgsDataProvider::setLayerOrder ( const QStringList &  layers)
inlinevirtual

Reorder the list of layer names to be rendered by this provider (in order from bottom to top)

Note
layers must have been previously added.

Definition at line 282 of file qgsdataprovider.h.

void QgsDataProvider::setListening ( bool  isListening)
virtual

Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.

The default implementation does nothing.

See also
notify
Since
QGIS 3.0

Definition at line 40 of file qgsdataprovider.cpp.

void QgsDataProvider::setProviderProperty ( QgsDataProvider::ProviderProperty  property,
const QVariant &  value 
)

Allows setting arbitrary properties on the provider.

It depends on the provider which properties are supported.

Since
QGIS 2.16

Definition at line 20 of file qgsdataprovider.cpp.

void QgsDataProvider::setProviderProperty ( int  property,
const QVariant &  value 
)

Allows setting arbitrary properties on the provider.

It depends on the provider which properties are supported.

Since
QGIS 2.16

Definition at line 25 of file qgsdataprovider.cpp.

virtual void QgsDataProvider::setSubLayerVisibility ( const QString &  name,
bool  vis 
)
inlinevirtual

Set the visibility of the given sublayer name.

Definition at line 296 of file qgsdataprovider.h.

virtual bool QgsDataProvider::setSubsetString ( const QString &  subset,
bool  updateFeatureCount = true 
)
inlinevirtual

Set the subset string used to create a subset of features in the layer.

This may be a sql where clause or any other string that can be used by the data provider to create a subset. Must be implemented in the dataprovider.

Definition at line 209 of file qgsdataprovider.h.

void QgsDataProvider::setUri ( const QgsDataSourceUri uri)
inline

Set the data source specification.

Since
QGIS 3.0

Definition at line 165 of file qgsdataprovider.h.

virtual uint QgsDataProvider::subLayerCount ( ) const
inlinevirtual

Returns the number of layers for the current data source.

Definition at line 271 of file qgsdataprovider.h.

virtual QStringList QgsDataProvider::subLayers ( ) const
inlinevirtual

Sub-layers handled by this provider, in order from bottom to top.

Sub-layers are used when the provider's source can combine layers it knows about in some way before it hands them off to the provider.

See also
SUBLAYER_SEPARATOR

Reimplemented in QgsRasterDataProvider.

Definition at line 243 of file qgsdataprovider.h.

virtual QStringList QgsDataProvider::subLayerStyles ( ) const
inlinevirtual

Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top.

Sub-layer styles are used to abstract the way the provider's source can symbolise layers in some way at the server, before it serves them to the provider.

Definition at line 262 of file qgsdataprovider.h.

virtual QString QgsDataProvider::subsetString ( ) const
inlinevirtual

Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set.

Must be overridden in the dataprovider, otherwise returns a null QString.

Definition at line 229 of file qgsdataprovider.h.

virtual bool QgsDataProvider::supportsSubsetString ( ) const
inlinevirtual

Returns true if the provider supports setting of subset strings.

Definition at line 221 of file qgsdataprovider.h.

virtual QDateTime QgsDataProvider::timestamp ( ) const
inlinevirtual

Time stamp of data source in the moment when data/metadata were loaded by provider.

Reimplemented in QgsRasterDataProvider.

Definition at line 378 of file qgsdataprovider.h.

virtual void QgsDataProvider::updateExtents ( )
inlinevirtual

Update the extents of the layer.

Not implemented by default.

Definition at line 197 of file qgsdataprovider.h.

QgsDataSourceUri QgsDataProvider::uri ( ) const
inline

Gets the data source specification.

Since
QGIS 3.0

Definition at line 175 of file qgsdataprovider.h.

virtual bool QgsDataProvider::writeLayerMetadata ( const QgsLayerMetadata metadata)
inlinevirtual

Writes layer metadata to the underlying provider source.

Support depends on individual provider capabilities.

Returns true if metadata was successfully written to the data provider.

See also
layerMetadata()
Since
QGIS 3.0

Definition at line 532 of file qgsdataprovider.h.

Member Data Documentation

QgsError QgsDataProvider::mError
protected

Error.

Definition at line 570 of file qgsdataprovider.h.

QDateTime QgsDataProvider::mTimestamp
protected

Timestamp of data in the moment when the data were loaded by provider.

Definition at line 567 of file qgsdataprovider.h.

QString QgsDataProvider::SUBLAYER_SEPARATOR = QString( "!!::!!" )
static

String sequence used for separating components of sublayers strings.

See also
subLayers()
Since
QGIS 3.0

Definition at line 253 of file qgsdataprovider.h.


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