Skip to content
Permalink
Browse files

Add QgsDataProvider::ProviderOptions struct to constructors

for data providers

Allows a way to pass generic settings to providers, e.g.
passing a datum transform context for use in provider's
constructors.
  • Loading branch information
nyalldawson committed May 21, 2018
1 parent 1098b39 commit 44630b47edaee68a514947f7ebd314ff67c63fc4
Showing with 373 additions and 201 deletions.
  1. +1 −1 python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
  2. +7 −1 python/core/auto_generated/mesh/qgsmeshlayer.sip.in
  3. +9 −1 python/core/auto_generated/qgsdataprovider.sip.in
  4. +0 −1 python/core/auto_generated/qgsprovidermetadata.sip.in
  5. +3 −1 python/core/auto_generated/qgsproviderregistry.sip.in
  6. +5 −3 python/core/auto_generated/qgsvectordataprovider.sip.in
  7. +18 −1 python/core/auto_generated/qgsvectorlayer.sip.in
  8. +9 −1 python/core/auto_generated/raster/qgsrasterdataprovider.sip.in
  9. +14 −2 python/core/auto_generated/raster/qgsrasterlayer.sip.in
  10. +2 −2 src/core/mesh/qgsmeshdataprovider.cpp
  11. +1 −1 src/core/mesh/qgsmeshdataprovider.h
  12. +8 −5 src/core/mesh/qgsmeshlayer.cpp
  13. +12 −2 src/core/mesh/qgsmeshlayer.h
  14. +4 −4 src/core/mesh/qgsmeshmemorydataprovider.cpp
  15. +2 −2 src/core/mesh/qgsmeshmemorydataprovider.h
  16. +4 −5 src/core/providers/memory/qgsmemoryprovider.cpp
  17. +6 −2 src/core/providers/memory/qgsmemoryprovider.h
  18. +16 −2 src/core/qgsdataprovider.h
  19. +4 −3 src/core/qgspluginlayer.cpp
  20. +1 −1 src/core/qgspluginlayer.h
  21. +2 −3 src/core/qgsprovidermetadata.h
  22. +2 −2 src/core/qgsproviderregistry.cpp
  23. +4 −2 src/core/qgsproviderregistry.h
  24. +2 −2 src/core/qgsvectordataprovider.cpp
  25. +6 −3 src/core/qgsvectordataprovider.h
  26. +13 −5 src/core/qgsvectorlayer.cpp
  27. +17 −2 src/core/qgsvectorlayer.h
  28. +3 −1 src/core/qgsvectorlayerexporter.cpp
  29. +3 −2 src/core/raster/qgsrasterchecker.cpp
  30. +4 −3 src/core/raster/qgsrasterdataprovider.cpp
  31. +9 −1 src/core/raster/qgsrasterdataprovider.h
  32. +2 −1 src/core/raster/qgsrasterfilewriter.cpp
  33. +14 −5 src/core/raster/qgsrasterlayer.cpp
  34. +13 −2 src/core/raster/qgsrasterlayer.h
  35. +2 −4 src/providers/arcgisrest/qgsafsprovider.cpp
  36. +3 −3 src/providers/arcgisrest/qgsafsprovider.h
  37. +2 −2 src/providers/arcgisrest/qgsafsproviderextern.cpp
  38. +2 −1 src/providers/arcgisrest/qgsafssourceselect.cpp
  39. +4 −3 src/providers/arcgisrest/qgsamsprovider.cpp
  40. +2 −2 src/providers/arcgisrest/qgsamsprovider.h
  41. +2 −2 src/providers/arcgisrest/qgsamsproviderextern.cpp
  42. +4 −4 src/providers/db2/qgsdb2provider.cpp
  43. +1 −1 src/providers/db2/qgsdb2provider.h
  44. +4 −4 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  45. +1 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.h
  46. +8 −7 src/providers/gdal/qgsgdalprovider.cpp
  47. +2 −2 src/providers/gdal/qgsgdalprovider.h
  48. +4 −4 src/providers/gpx/qgsgpxprovider.cpp
  49. +1 −1 src/providers/gpx/qgsgpxprovider.h
  50. +4 −4 src/providers/mdal/qgsmdalprovider.cpp
  51. +3 −4 src/providers/mdal/qgsmdalprovider.h
  52. +7 −5 src/providers/mssql/qgsmssqlprovider.cpp
  53. +1 −1 src/providers/mssql/qgsmssqlprovider.h
  54. +4 −4 src/providers/ogr/qgsogrprovider.cpp
  55. +4 −2 src/providers/ogr/qgsogrprovider.h
  56. +7 −5 src/providers/oracle/qgsoracleprovider.cpp
  57. +2 −1 src/providers/oracle/qgsoracleprovider.h
  58. +4 −4 src/providers/ows/qgsowsprovider.cpp
  59. +2 −1 src/providers/ows/qgsowsprovider.h
  60. +7 −5 src/providers/postgres/qgspostgresprovider.cpp
  61. +2 −1 src/providers/postgres/qgspostgresprovider.h
  62. +7 −5 src/providers/spatialite/qgsspatialiteprovider.cpp
  63. +3 −2 src/providers/spatialite/qgsspatialiteprovider.h
  64. +4 −4 src/providers/virtual/qgsvirtuallayerprovider.cpp
  65. +3 −2 src/providers/virtual/qgsvirtuallayerprovider.h
  66. +2 −1 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  67. +6 −5 src/providers/wcs/qgswcsprovider.cpp
  68. +3 −3 src/providers/wcs/qgswcsprovider.h
  69. +4 −4 src/providers/wfs/qgswfsprovider.cpp
  70. +1 −1 src/providers/wfs/qgswfsprovider.h
  71. +3 −1 src/providers/wfs/qgswfsshareddata.cpp
  72. +9 −3 src/providers/wfs/qgswfssourceselect.cpp
  73. +6 −5 src/providers/wms/qgswmsprovider.cpp
  74. +4 −3 src/providers/wms/qgswmsprovider.h
  75. +5 −5 tests/src/providers/testqgsgdalprovider.cpp
  76. +4 −4 tests/src/providers/testqgswmsprovider.cpp
@@ -266,7 +266,7 @@ Responsible for reading native mesh data
#include "qgsmeshdataprovider.h"
%End
public:
QgsMeshDataProvider( const QString &uri = QString() );
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
%Docstring
Ctor
%End
@@ -77,7 +77,13 @@ is the MDAL connection string. QGIS must be built with MDAL support to allow thi
%End
public:

explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = "mesh_memory" );
struct LayerOptions
{

};

explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = "mesh_memory",
const QgsMeshLayer::LayerOptions &options = QgsMeshLayer::LayerOptions() );
%Docstring
Constructor - creates a mesh layer

@@ -64,9 +64,17 @@ to generic QgsVectorDataProvider's) depends on it.
CustomData
};

QgsDataProvider( const QString &uri = QString() );

struct ProviderOptions
{

};

QgsDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
%Docstring
Create a new dataprovider with the specified in the ``uri``.

Additional creation options are specified within the ``options`` value.
%End

virtual QgsCoordinateReferenceSystem crs() const = 0;
@@ -10,7 +10,6 @@




class QgsProviderMetadata
{
%Docstring
@@ -73,12 +73,14 @@ Set library directory where to search for plugins
%End

QgsDataProvider *createProvider( const QString &providerKey,
const QString &dataSource ) /Factory/;
const QString &dataSource,
const QgsDataProvider::ProviderOptions &options ) /Factory/;
%Docstring
Creates a new instance of a provider.

:param providerKey: identificator of the provider
:param dataSource: string containing data source for the provider
:param options: provider options

:return: new instance of provider or NULL on error
%End
@@ -67,11 +67,13 @@ of feature and attribute information from a spatial datasource.
UnknownCount,
};

QgsVectorDataProvider( const QString &uri = QString() );
QgsVectorDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
%Docstring
Constructor of the vector provider
Constructor for a vector data provider.

:param uri: uniform resource locator (URI) for a dataset
The ``uri`` argument specifies the uniform resource locator (URI) for the associated dataset.

Additional creation options are specified within the ``options`` value.
%End

virtual QgsAbstractFeatureSource *featureSource() const = 0 /Factory/;
@@ -925,7 +925,7 @@ calculated by countSymbolFeatures()
:return: number of features rendered by symbol or -1 if failed or counts are not available
%End

void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ) /Deprecated/;
%Docstring
Update the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.
@@ -937,6 +937,23 @@ if the geometry type of the new data source matches the current geometry type of
data source

.. versionadded:: 2.10

.. deprecated:: Use version with ProviderOptions argument instead
%End

void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.

:param dataSource: new layer data source
:param baseName: base name of the layer
:param provider: provider string
:param options: provider options
:param loadDefaultStyleFlag: set to true to reset the layer's style to the default for the
data source

.. versionadded:: 3.2
%End

virtual QString loadDefaultStyle( bool &resultFlag /Out/ );
@@ -82,7 +82,15 @@ Base class for raster data providers.

QgsRasterDataProvider();

QgsRasterDataProvider( const QString &uri );
QgsRasterDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
%Docstring
Constructor for QgsRasterDataProvider.

The ``uri`` argument gives a provider-specific uri indicating the underlying data
source and it's parameters.

The ``options`` argument specifies generic provider options.
%End

virtual QgsRasterInterface *clone() const = 0;

@@ -180,9 +180,21 @@ returned in ``retError``.
Return time stamp for given file name
%End

void setDataProvider( const QString &provider );
void setDataProvider( const QString &provider ) /Deprecated/;
%Docstring
[ data provider interface ] Set the data provider
Set the data provider.

.. deprecated:: Use the version with ProviderOptions instead.
%End

void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
%Docstring
Set the data provider.

:param provider: provider key string, must match a valid QgsRasterDataProvider key. E.g. "gdal", "wms", etc.
:param options: provider options

.. versionadded:: 3.2
%End

LayerType rasterType();
@@ -18,8 +18,8 @@
#include "qgsmeshdataprovider.h"
#include "qgis.h"

QgsMeshDataProvider::QgsMeshDataProvider( const QString &uri )
: QgsDataProvider( uri )
QgsMeshDataProvider::QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
: QgsDataProvider( uri, options )
{
}

@@ -253,7 +253,7 @@ class CORE_EXPORT QgsMeshDataProvider: public QgsDataProvider, public QgsMeshDat

public:
//! Ctor
QgsMeshDataProvider( const QString &uri = QString() );
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );

/**
* Returns the extent of the layer
@@ -30,12 +30,14 @@

QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
const QString &baseName,
const QString &providerKey )
const QString &providerKey,
const LayerOptions & )
: QgsMapLayer( MeshLayer, baseName, meshLayerPath )
, mProviderKey( providerKey )
{
// load data
setDataProvider( providerKey );
QgsDataProvider::ProviderOptions providerOptions;
setDataProvider( providerKey, providerOptions );

// show at least the mesh by default so we render something
mRendererNativeMeshSettings.setEnabled( true );
@@ -269,7 +271,8 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
mProviderKey = pkeyElt.text();
}

if ( !setDataProvider( mProviderKey ) )
QgsDataProvider::ProviderOptions providerOptions;
if ( !setDataProvider( mProviderKey, providerOptions ) )
{
return false;
}
@@ -304,15 +307,15 @@ bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const
return writeSymbology( layer_node, document, errorMsg, context );
}

bool QgsMeshLayer::setDataProvider( QString const &provider )
bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options )
{
if ( mDataProvider )
delete mDataProvider;

mProviderKey = provider;
QString dataSource = mDataSource;

mDataProvider = qobject_cast<QgsMeshDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
mDataProvider = qobject_cast<QgsMeshDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options ) );
if ( !mDataProvider )
{
QgsDebugMsgLevel( QStringLiteral( "Unable to get mesh data provider" ), 2 );
@@ -92,6 +92,14 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
Q_OBJECT
public:

/**
* Setting options for loading mesh layers.
*/
struct LayerOptions
{

};

/**
* Constructor - creates a mesh layer
*
@@ -104,7 +112,8 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
* \param baseName The name used to represent the layer in the legend
* \param providerLib The name of the data provider, e.g., "mesh_memory", "mdal"
*/
explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = "mesh_memory" );
explicit QgsMeshLayer( const QString &path = QString(), const QString &baseName = QString(), const QString &providerLib = "mesh_memory",
const QgsMeshLayer::LayerOptions &options = QgsMeshLayer::LayerOptions() );
~QgsMeshLayer() override;

//! QgsMeshLayer cannot be copied.
@@ -185,8 +194,9 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
/**
* Binds layer to a specific data provider
* \param provider provider key string, must match a valid QgsMeshDataProvider key. E.g. "mesh_memory", etc.
* \param options generic provider options
*/
bool setDataProvider( QString const &provider );
bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options );

#ifdef SIP_RUN
QgsMeshLayer( const QgsMeshLayer &rhs );
@@ -41,8 +41,8 @@ QgsCoordinateReferenceSystem QgsMeshMemoryDataProvider::crs() const
return QgsCoordinateReferenceSystem();
}

QgsMeshMemoryDataProvider::QgsMeshMemoryDataProvider( const QString &uri )
: QgsMeshDataProvider( uri )
QgsMeshMemoryDataProvider::QgsMeshMemoryDataProvider( const QString &uri, const ProviderOptions &options )
: QgsMeshDataProvider( uri, options )
{
mIsValid = splitMeshSections( uri );
}
@@ -61,9 +61,9 @@ QString QgsMeshMemoryDataProvider::providerDescription()
return TEXT_PROVIDER_DESCRIPTION;
}

QgsMeshMemoryDataProvider *QgsMeshMemoryDataProvider::createProvider( const QString &uri )
QgsMeshMemoryDataProvider *QgsMeshMemoryDataProvider::createProvider( const QString &uri, const ProviderOptions &options )
{
return new QgsMeshMemoryDataProvider( uri );
return new QgsMeshMemoryDataProvider( uri, options );
}

bool QgsMeshMemoryDataProvider::splitMeshSections( const QString &uri )
@@ -71,7 +71,7 @@ class QgsMeshMemoryDataProvider: public QgsMeshDataProvider
* );
* \endcode
*/
QgsMeshMemoryDataProvider( const QString &uri = QString() );
QgsMeshMemoryDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
~QgsMeshMemoryDataProvider();

bool isValid() const override;
@@ -119,7 +119,7 @@ class QgsMeshMemoryDataProvider: public QgsMeshDataProvider
//! Returns the memory provider description
static QString providerDescription();
//! Provider factory
static QgsMeshMemoryDataProvider *createProvider( const QString &uri );
static QgsMeshMemoryDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
private:
bool splitMeshSections( const QString &uri );
bool addMeshVertices( const QString &def );
@@ -31,9 +31,8 @@
static const QString TEXT_PROVIDER_KEY = QStringLiteral( "memory" );
static const QString TEXT_PROVIDER_DESCRIPTION = QStringLiteral( "Memory provider" );

QgsMemoryProvider::QgsMemoryProvider( const QString &uri )
: QgsVectorDataProvider( uri )

QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions &options )
: QgsVectorDataProvider( uri, options )
{
// Initialize the geometry with the uri to support old style uri's
// (ie, just 'point', 'line', 'polygon')
@@ -201,9 +200,9 @@ QString QgsMemoryProvider::providerDescription()
return TEXT_PROVIDER_DESCRIPTION;
}

QgsMemoryProvider *QgsMemoryProvider::createProvider( const QString &uri )
QgsMemoryProvider *QgsMemoryProvider::createProvider( const QString &uri, const ProviderOptions &options )
{
return new QgsMemoryProvider( uri );
return new QgsMemoryProvider( uri, options );
}

QgsAbstractFeatureSource *QgsMemoryProvider::featureSource() const
@@ -31,7 +31,7 @@ class QgsMemoryProvider : public QgsVectorDataProvider
Q_OBJECT

public:
explicit QgsMemoryProvider( const QString &uri = QString() );
explicit QgsMemoryProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &options );

~QgsMemoryProvider() override;

@@ -40,7 +40,11 @@ class QgsMemoryProvider : public QgsVectorDataProvider
//! Returns the memory provider description
static QString providerDescription();

static QgsMemoryProvider *createProvider( const QString &uri );
/**
* Creates a new memory provider, with provider properties embedded within the given \a uri and \a options
* argument.
*/
static QgsMemoryProvider *createProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &options );

/* Implementation of functions from QgsVectorDataProvider */

@@ -96,12 +96,26 @@ class CORE_EXPORT QgsDataProvider : public QObject
CustomData = 3000 //!< 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.
};


/**
* Setting options for creating vector data providers.
* \since QGIS 3.2
*/
struct ProviderOptions
{

};

/**
* Create a new dataprovider with the specified in the \a uri.
*
* Additional creation options are specified within the \a options value.
*/
QgsDataProvider( const QString &uri = QString() )
QgsDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
: mDataSourceURI( uri )
{}
{
Q_UNUSED( options );
}

/**
* Returns the coordinate system for the data source.
@@ -22,7 +22,7 @@ QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerNa
: QgsMapLayer( PluginLayer, layerName )
, mPluginLayerType( layerType )
{
mDataProvider = new QgsPluginLayerDataProvider( layerType );
mDataProvider = new QgsPluginLayerDataProvider( layerType, QgsDataProvider::ProviderOptions() );
}

QgsPluginLayer::~QgsPluginLayer()
@@ -63,8 +63,9 @@ const QgsDataProvider *QgsPluginLayer::dataProvider() const
// QgsPluginLayerDataProvider
//
///@cond PRIVATE
QgsPluginLayerDataProvider::QgsPluginLayerDataProvider( const QString &layerType )
: mName( layerType )
QgsPluginLayerDataProvider::QgsPluginLayerDataProvider( const QString &layerType, const ProviderOptions &options )
: QgsDataProvider( QString(), options )
, mName( layerType )
{}

QgsCoordinateReferenceSystem QgsPluginLayerDataProvider::crs() const

0 comments on commit 44630b4

Please sign in to comment.
You can’t perform that action at this time.