Skip to content

Commit

Permalink
Add QgsDataProvider::ProviderOptions struct to constructors
Browse files Browse the repository at this point in the history
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 25, 2018
1 parent 1098b39 commit 44630b4
Show file tree
Hide file tree
Showing 76 changed files with 373 additions and 201 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion python/core/auto_generated/qgsdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion python/core/auto_generated/qgsprovidermetadata.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@




class QgsProviderMetadata
{
%Docstring
Expand Down
4 changes: 3 additions & 1 deletion python/core/auto_generated/qgsproviderregistry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions python/core/auto_generated/qgsvectordataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
19 changes: 18 additions & 1 deletion python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/ );
Expand Down
10 changes: 9 additions & 1 deletion python/core/auto_generated/raster/qgsrasterdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 14 additions & 2 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgsmeshdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down
14 changes: 12 additions & 2 deletions src/core/mesh/qgsmeshlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions src/core/mesh/qgsmeshmemorydataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshmemorydataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 4 additions & 5 deletions src/core/providers/memory/qgsmemoryprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/core/providers/memory/qgsmemoryprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 */

Expand Down
18 changes: 16 additions & 2 deletions src/core/qgsdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgspluginlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 44630b4

Please sign in to comment.