Skip to content

Commit

Permalink
Provider key getter and layer options
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jul 7, 2020
1 parent 1d1b689 commit 8ded0f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Expand Up @@ -475,9 +475,16 @@ Raises a QgsProviderConnectionException if any errors are encountered.
the default implementation creates a temporary vector layer, providers may
choose to override this method for a greater efficiency.

.. versionadded:: 3.18
.. versionadded:: 3.16

:raises :: py:class:`QgsProviderConnectionException`
%End

QString providerKey() const;
%Docstring
Returns the provider key

.. versionadded:: 3.16
%End

protected:
Expand Down
9 changes: 8 additions & 1 deletion src/core/qgsabstractdatabaseproviderconnection.cpp
Expand Up @@ -52,6 +52,11 @@ void QgsAbstractDatabaseProviderConnection::checkCapability( QgsAbstractDatabase
throw QgsProviderConnectionException( QObject::tr( "Operation '%1' is not supported for this connection" ).arg( capName ) );
}
}

QString QgsAbstractDatabaseProviderConnection::providerKey() const
{
return mProviderKey;
}
///@endcond

void QgsAbstractDatabaseProviderConnection::createVectorTable( const QString &schema,
Expand Down Expand Up @@ -215,7 +220,9 @@ QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType>

QgsFields QgsAbstractDatabaseProviderConnection::fields( const QString &schema, const QString &tableName ) const
{
QgsVectorLayer vl { tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey };
QgsVectorLayer::LayerOptions options { true, true };
options.skipCrsValidation = true;
QgsVectorLayer vl { tableUri( schema, tableName ), QStringLiteral( "temp_layer" ), mProviderKey, options };
if ( vl.isValid() )
{
return vl.fields();
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsabstractdatabaseproviderconnection.h
Expand Up @@ -501,11 +501,17 @@ class CORE_EXPORT QgsAbstractDatabaseProviderConnection : public QgsAbstractProv
* Raises a QgsProviderConnectionException if any errors are encountered.
* \note the default implementation creates a temporary vector layer, providers may
* choose to override this method for a greater efficiency.
* \since QGIS 3.18
* \since QGIS 3.16
* \throws QgsProviderConnectionException
*/
virtual QgsFields fields( const QString &schema, const QString &table ) const SIP_THROW( QgsProviderConnectionException );

/**
* Returns the provider key
* \since QGIS 3.16
*/
QString providerKey() const;

protected:

///@cond PRIVATE
Expand Down

0 comments on commit 8ded0f1

Please sign in to comment.