Skip to content
Permalink
Browse files

Add flag to QgsProviderMetadata to indicate if a provider

can handle file based uris

E.g. gdal/ogr can, but postgres/wfs cannot

(cherry picked from commit 1bef866)
  • Loading branch information
nyalldawson committed Mar 11, 2021
1 parent 4ec6c81 commit 0ef7d3b7d891d25e40cd5e82f951995d3d09eeb7
@@ -29,6 +29,7 @@
#include "qgslayertreeregistrybridge.h"
#include "qgsapplication.h"
#include "qgsfileutils.h"
#include "qgsprovidermetadata.h"

#include <QDomDocument>
#include <QDomElement>
@@ -126,9 +127,12 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers )
QString type = node.toElement().attribute( QStringLiteral( "type" ) );
QString id = node.namedItem( QStringLiteral( "id" ) ).toElement().text();
QString datasource = node.namedItem( QStringLiteral( "datasource" ) ).toElement().text();
QString provider = node.namedItem( QStringLiteral( "provider" ) ).toElement().text();
QString vectorProvider = type == QLatin1String( "vector" ) ? provider : tr( "none" );
bool providerFileBased = ( provider == QLatin1String( "gdal" ) || provider == QLatin1String( "ogr" ) || provider == QLatin1String( "mdal" ) );
const QString provider = node.namedItem( QStringLiteral( "provider" ) ).toElement().text();

bool providerFileBased = false;
if ( const QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( provider ) )
providerFileBased = metadata->providerCapabilities() & QgsProviderMetadata::FileBasedUris;

const QString basepath = QFileInfo( datasource ).absolutePath();
mOriginalFileBase[ node.namedItem( QStringLiteral( "id" ) ).toElement().text() ].append( basepath );

@@ -3569,6 +3569,11 @@ QList<QPair<QString, QString> > QgsGdalProviderMetadata::pyramidResamplingMethod
return methods;
}

QgsProviderMetadata::ProviderCapabilities QgsGdalProviderMetadata::providerCapabilities() const
{
return FileBasedUris;
}

QList<QgsDataItemProvider *> QgsGdalProviderMetadata::dataItemProviders() const
{
QList< QgsDataItemProvider * > providers;
@@ -382,6 +382,7 @@ class QgsGdalProviderMetadata final: public QgsProviderMetadata
QString filters( FilterType type ) override;
QList< QgsDataItemProvider * > dataItemProviders() const override;
QList<QPair<QString, QString> > pyramidResamplingMethods() override;
ProviderCapabilities providerCapabilities() const override;
};

///@endcond
@@ -7277,4 +7277,9 @@ void QgsOgrProviderMetadata::saveConnection( const QgsAbstractProviderConnection
saveConnectionProtected( conn, name );
}

QgsProviderMetadata::ProviderCapabilities QgsOgrProviderMetadata::providerCapabilities() const
{
return FileBasedUris;
}
///@endcond

@@ -765,6 +765,7 @@ class QgsOgrProviderMetadata final: public QgsProviderMetadata
QVariantMap decodeUri( const QString &uri ) const override;
QString encodeUri( const QVariantMap &parts ) const override;
QString filters( FilterType type ) override;
ProviderCapabilities providerCapabilities() const override;
bool uriIsBlocklisted( const QString &uri ) const override;
QgsVectorLayerExporter::ExportError createEmptyLayer(
const QString &uri,
@@ -56,6 +56,11 @@ QgsProviderMetadata::ProviderMetadataCapabilities QgsProviderMetadata::capabilit
return QgsProviderMetadata::ProviderMetadataCapabilities();
}

QgsProviderMetadata::ProviderCapabilities QgsProviderMetadata::providerCapabilities() const
{
return QgsProviderMetadata::ProviderCapabilities();
}

QString QgsProviderMetadata::library() const
{
return mLibrary;
@@ -153,6 +153,17 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
};
Q_DECLARE_FLAGS( ProviderMetadataCapabilities, ProviderMetadataCapability )

/**
* Provider capabilities
*
* \since QGIS 3.20
*/
enum ProviderCapability
{
FileBasedUris = 1 << 0, //!< Indicates that the provider can utilise URIs which are based on paths to files (as opposed to database or internet paths)
};
Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )

/**
* Typedef for data provider creation function.
* \since QGIS 3.0
@@ -199,6 +210,13 @@ class CORE_EXPORT QgsProviderMetadata : public QObject
*/
virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;

/**
* Returns the provider's capabilities.
*
* \since QGIS 3.20
*/
virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;

/**
* This returns the library file name
*
@@ -981,6 +981,11 @@ QString QgsMdalProviderMetadata::encodeUri( const QVariantMap &parts ) const
return path;
}

QgsProviderMetadata::ProviderCapabilities QgsMdalProviderMetadata::providerCapabilities() const
{
return FileBasedUris;
}

QString QgsMdalProviderMetadata::filters( FilterType type )
{
switch ( type )
@@ -145,6 +145,7 @@ class QgsMdalProviderMetadata: public QgsProviderMetadata
const QgsCoordinateReferenceSystem &crs ) const override;
QVariantMap decodeUri( const QString &uri ) const override;
QString encodeUri( const QVariantMap &parts ) const override;
ProviderCapabilities providerCapabilities() const override;
};

#endif //QGSMDALPROVIDER_H

0 comments on commit 0ef7d3b

Please sign in to comment.