Skip to content
Permalink
Browse files

Add API to QgsProviderMetadata to determine valid layer types

which the provider can use to open a specified URI
  • Loading branch information
nyalldawson committed Nov 6, 2020
1 parent 8254b7d commit 51762dd0ef50111b908607685697dac6d51f777e
@@ -209,6 +209,26 @@ priority for the same URI.

The default implementation returns 0 for all URIs.

.. warning::

Not all providers implement this functionality. Check whether :py:func:`~QgsProviderMetadata.capabilities` returns the
ProviderMetadataCapability.PriorityForUri to determine whether a specific provider metadata object
supports this method.

.. versionadded:: 3.18
%End

virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;
%Docstring
Returns a list of valid layer types which the provider can be used with when
opening the specified ``uri``.

.. warning::

Not all providers implement this functionality. Check whether :py:func:`~QgsProviderMetadata.capabilities` returns the
ProviderMetadataCapability.LayerTypesForUri to determine whether a specific provider metadata object
supports this method.

.. versionadded:: 3.18
%End

@@ -281,9 +281,41 @@ Returns list of available providers by their keys
Returns metadata of the provider or ``None`` if not found
%End

QList< QgsProviderMetadata *> preferredProvidersForUri( const QString &uri ) const;
class ProviderCandidateDetails
{
%Docstring

Contains information pertaining to a candidate provider.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgsproviderregistry.h"
%End
public:

ProviderCandidateDetails( QgsProviderMetadata *metadata, const QList< QgsMapLayerType > &layerTypes );
%Docstring
Constructor for ProviderCandidateDetails, with the specified provider ``metadata`` and valid candidate ``layerTypes``.
%End

QgsProviderMetadata *metadata() const;
%Docstring
Returns the candidate provider metadata.
%End

QList<QgsMapLayerType> layerTypes() const;
%Docstring
Returns a list of map layer types which are valid options for opening the
target using this candidate provider.
%End

};

QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
%Docstring
Returns the metadata for the preferred provider(s) for opening the specified ``uri``.
Returns the details for the preferred provider(s) for opening the specified ``uri``.

The preferred provider is determined by comparing the priority returned by
:py:func:`QgsProviderMetadata.priorityForUri()` for all registered providers, and selecting
@@ -100,6 +100,16 @@ int QgsEptProviderMetadata::priorityForUri( const QString &uri ) const
return 0;
}

QList<QgsMapLayerType> QgsEptProviderMetadata::validLayerTypesForUri( const QString &uri ) const
{
const QVariantMap parts = decodeUri( uri );
QFileInfo fi( parts.value( QStringLiteral( "path" ) ).toString() );
if ( fi.fileName().compare( QLatin1String( "ept.json" ), Qt::CaseInsensitive ) == 0 )
return QList< QgsMapLayerType>() << QgsMapLayerType::PointCloudLayer;

return QList< QgsMapLayerType>();
}

bool QgsEptProviderMetadata::uriIsBlocklisted( const QString &uri ) const
{
const QVariantMap parts = decodeUri( uri );
@@ -91,6 +91,11 @@ int QgsProviderMetadata::priorityForUri( const QString & ) const
return 0;
}

QList<QgsMapLayerType> QgsProviderMetadata::validLayerTypesForUri( const QString &uri ) const
{

}

bool QgsProviderMetadata::uriIsBlocklisted( const QString & ) const
{
return false;
@@ -267,10 +267,26 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
*
* The default implementation returns 0 for all URIs.
*
* \warning Not all providers implement this functionality. Check whether capabilities() returns the
* ProviderMetadataCapability::PriorityForUri to determine whether a specific provider metadata object
* supports this method.
*
* \since QGIS 3.18
*/
virtual int priorityForUri( const QString &uri ) const;

/**
* Returns a list of valid layer types which the provider can be used with when
* opening the specified \a uri.
*
* \warning Not all providers implement this functionality. Check whether capabilities() returns the
* ProviderMetadataCapability::LayerTypesForUri to determine whether a specific provider metadata object
* supports this method.
*
* \since QGIS 3.18
*/
virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;

/**
* Returns TRUE if the specified \a uri is known by this provider to be something which should
* be blocklisted from the QGIS interface, e.g. an internal detail only.
@@ -605,6 +621,7 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;

/// @endcond

#endif

private:
@@ -162,6 +162,16 @@ int QgsPdalProviderMetadata::priorityForUri( const QString &uri ) const
return 0;
}

QList<QgsMapLayerType> QgsPdalProviderMetadata::validLayerTypesForUri( const QString &uri ) const
{
const QVariantMap parts = decodeUri( uri );
QFileInfo fi( parts.value( QStringLiteral( "path" ) ).toString() );
if ( fi.suffix().compare( QLatin1String( "las" ), Qt::CaseInsensitive ) == 0 || fi.suffix().compare( QLatin1String( "laz" ), Qt::CaseInsensitive ) == 0 )
return QList<QgsMapLayerType>() << QgsMapLayerType::PointCloudLayer;

return QList<QgsMapLayerType>();
}

QString QgsPdalProviderMetadata::filters( QgsProviderMetadata::FilterType type )
{
switch ( type )
@@ -62,6 +62,7 @@ class QgsPdalProviderMetadata : public QgsProviderMetadata
QString encodeUri( const QVariantMap &parts ) const override;
QVariantMap decodeUri( const QString &uri ) const override;
int priorityForUri( const QString &uri ) const override;
QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const override;
QString filters( FilterType type ) override;
};

0 comments on commit 51762dd

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