28#include <QNetworkRequest> 
   32QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY = QStringLiteral( 
"xyzvectortiles" );
 
   33QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION = QObject::tr( 
"XYZ Vector Tiles data provider" );
 
   39QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase( 
const QString &uri, 
const ProviderOptions &providerOptions, ReadFlags flags )
 
   48QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase( 
const QgsXyzVectorTileDataProviderBase &other )
 
   51  mAuthCfg = other.mAuthCfg;
 
   52  mHeaders = other.mHeaders;
 
   55bool QgsXyzVectorTileDataProviderBase::supportsAsync()
 const 
   67  QList<QgsVectorTileRawData> rawTiles;
 
   68  rawTiles.reserve( tiles.size() );
 
   69  const QString source = sourcePath();
 
   75    const QByteArray rawData = loadFromNetwork( 
id, set.
tileMatrix( 
id.zoomLevel() ), source, mAuthCfg, mHeaders, feedback, usage );
 
   76    if ( !rawData.isEmpty() )
 
   86  QString urlTemplate = sourcePath();
 
   88  if ( urlTemplate.contains( QLatin1String( 
"{usage}" ) ) )
 
   93        urlTemplate.replace( QLatin1String( 
"{usage}" ), QLatin1String( 
"view" ) );
 
   96        urlTemplate.replace( QLatin1String( 
"{usage}" ), QLatin1String( 
"export" ) );
 
   99        urlTemplate.replace( QLatin1String( 
"{usage}" ), QString() );
 
  106  QNetworkRequest request( url );
 
  110  request.setAttribute( 
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 1 ), 
id.column() );
 
  111  request.setAttribute( 
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 2 ), 
id.row() );
 
  112  request.setAttribute( 
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 3 ), 
id.zoomLevel() );
 
  114  request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
 
  115  request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, 
true );
 
  117  mHeaders.updateNetworkRequest( request );
 
  131  if ( url.contains( QLatin1String( 
"{usage}" ) ) )
 
  136        url.replace( QLatin1String( 
"{usage}" ), QLatin1String( 
"view" ) );
 
  139        url.replace( QLatin1String( 
"{usage}" ), QLatin1String( 
"export" ) );
 
  142        url.replace( QLatin1String( 
"{usage}" ), QString() );
 
  148  nr.setUrl( QUrl( url ) );
 
  172QgsXyzVectorTileDataProviderMetadata::QgsXyzVectorTileDataProviderMetadata()
 
  173  : 
QgsProviderMetadata( QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY, QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION )
 
  177QgsXyzVectorTileDataProvider *QgsXyzVectorTileDataProviderMetadata::createProvider( 
const QString &uri, 
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
 
  179  return new QgsXyzVectorTileDataProvider( uri, options, flags );
 
  182QIcon QgsXyzVectorTileDataProviderMetadata::icon()
 const 
  187QgsProviderMetadata::ProviderCapabilities QgsXyzVectorTileDataProviderMetadata::providerCapabilities()
 const 
  189  return FileBasedUris;
 
  192QVariantMap QgsXyzVectorTileDataProviderMetadata::decodeUri( 
const QString &uri )
 const 
  197  QVariantMap uriComponents;
 
  198  uriComponents.insert( QStringLiteral( 
"type" ), QStringLiteral( 
"xyz" ) );
 
  200  if ( uriComponents[ QStringLiteral( 
"type" ) ] == QLatin1String( 
"mbtiles" ) ||
 
  201       ( uriComponents[ QStringLiteral( 
"type" ) ] == QLatin1String( 
"xyz" ) &&
 
  202         !dsUri.
param( QStringLiteral( 
"url" ) ).startsWith( QLatin1String( 
"http" ) ) ) )
 
  204    uriComponents.insert( QStringLiteral( 
"path" ), dsUri.
param( QStringLiteral( 
"url" ) ) );
 
  208    uriComponents.insert( QStringLiteral( 
"url" ), dsUri.
param( QStringLiteral( 
"url" ) ) );
 
  211  if ( dsUri.
hasParam( QStringLiteral( 
"zmin" ) ) )
 
  212    uriComponents.insert( QStringLiteral( 
"zmin" ), dsUri.
param( QStringLiteral( 
"zmin" ) ) );
 
  213  if ( dsUri.
hasParam( QStringLiteral( 
"zmax" ) ) )
 
  214    uriComponents.insert( QStringLiteral( 
"zmax" ), dsUri.
param( QStringLiteral( 
"zmax" ) ) );
 
  218  if ( dsUri.
hasParam( QStringLiteral( 
"styleUrl" ) ) )
 
  219    uriComponents.insert( QStringLiteral( 
"styleUrl" ), dsUri.
param( QStringLiteral( 
"styleUrl" ) ) );
 
  222  if ( !authcfg.isEmpty() )
 
  223    uriComponents.insert( QStringLiteral( 
"authcfg" ), authcfg );
 
  225  return uriComponents;
 
  228QString QgsXyzVectorTileDataProviderMetadata::encodeUri( 
const QVariantMap &parts )
 const 
  231  dsUri.
setParam( QStringLiteral( 
"type" ), QStringLiteral( 
"xyz" ) );
 
  232  dsUri.
setParam( QStringLiteral( 
"url" ), parts.value( parts.contains( QStringLiteral( 
"path" ) ) ? QStringLiteral( 
"path" ) : QStringLiteral( 
"url" ) ).toString() );
 
  234  if ( parts.contains( QStringLiteral( 
"zmin" ) ) )
 
  235    dsUri.
setParam( QStringLiteral( 
"zmin" ), parts[ QStringLiteral( 
"zmin" ) ].toString() );
 
  236  if ( parts.contains( QStringLiteral( 
"zmax" ) ) )
 
  237    dsUri.
setParam( QStringLiteral( 
"zmax" ), parts[ QStringLiteral( 
"zmax" ) ].toString() );
 
  241  if ( parts.contains( QStringLiteral( 
"styleUrl" ) ) )
 
  242    dsUri.
setParam( QStringLiteral( 
"styleUrl" ), parts[ QStringLiteral( 
"styleUrl" ) ].toString() );
 
  244  if ( parts.contains( QStringLiteral( 
"authcfg" ) ) )
 
  245    dsUri.
setAuthConfigId( parts[ QStringLiteral( 
"authcfg" ) ].toString() );
 
  250QString QgsXyzVectorTileDataProviderMetadata::absoluteToRelativeUri( 
const QString &uri, 
const QgsReadWriteContext &context )
 const 
  255  QString sourcePath = dsUri.
param( QStringLiteral( 
"url" ) );
 
  257  const QUrl sourceUrl( sourcePath );
 
  258  if ( sourceUrl.isLocalFile() )
 
  263    dsUri.
setParam( QStringLiteral( 
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
 
  270QString QgsXyzVectorTileDataProviderMetadata::relativeToAbsoluteUri( 
const QString &uri, 
const QgsReadWriteContext &context )
 const 
  275  QString sourcePath = dsUri.
param( QStringLiteral( 
"url" ) );
 
  277  const QUrl sourceUrl( sourcePath );
 
  278  if ( sourceUrl.isLocalFile() )  
 
  282    dsUri.
setParam( QStringLiteral( 
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
 
  289QList<Qgis::LayerType> QgsXyzVectorTileDataProviderMetadata::supportedLayerTypes()
 const 
  291  return { Qgis::LayerType::VectorTile };
 
  299QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider( 
const QString &uri, 
const ProviderOptions &providerOptions, ReadFlags flags )
 
  300  : QgsXyzVectorTileDataProviderBase( uri, providerOptions, flags )
 
  305  const QString sourcePath = dsUri.
param( QStringLiteral( 
"url" ) );
 
  308    QgsDebugError( QStringLiteral( 
"Invalid format of URL for XYZ source: " ) + sourcePath );
 
  314  if ( dsUri.
hasParam( QStringLiteral( 
"zmin" ) ) )
 
  315    zMin = dsUri.
param( QStringLiteral( 
"zmin" ) ).toInt();
 
  318  if ( dsUri.
hasParam( QStringLiteral( 
"zmax" ) ) )
 
  319    zMax = dsUri.
param( QStringLiteral( 
"zmax" ) ).toInt();
 
  322  mExtent = 
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 );
 
  327QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider( 
const QgsXyzVectorTileDataProvider &other )
 
  328  : QgsXyzVectorTileDataProviderBase( other )
 
  330  mIsValid = other.mIsValid;
 
  331  mExtent = other.mExtent;
 
  332  mMatrixSet = other.mMatrixSet;
 
  335QString QgsXyzVectorTileDataProvider::name()
 const 
  339  return XYZ_DATA_PROVIDER_KEY;
 
  342QString QgsXyzVectorTileDataProvider::description()
 const 
  346  return XYZ_DATA_PROVIDER_DESCRIPTION;
 
  353  return new QgsXyzVectorTileDataProvider( *
this );
 
  356bool QgsXyzVectorTileDataProvider::isValid()
 const 
  363QgsRectangle QgsXyzVectorTileDataProvider::extent()
 const 
  384QString QgsXyzVectorTileDataProvider::sourcePath()
 const 
  390  return dsUri.param( QStringLiteral( 
"url" ) );
 
RendererUsage
Usage of the renderer.
 
@ Export
Renderer used for printing or exporting to a file.
 
@ View
Renderer used for displaying on screen.
 
@ Unknown
Renderer used for unknown usage.
 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
 
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
 
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
 
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
 
ErrorCode get(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "get" operation on the specified request.
 
void setAuthCfg(const QString &authCfg)
Sets the authentication config id which should be used during the request.
 
@ NoError
No error was encountered.
 
QgsNetworkReplyContent reply() const
Returns the content of the network reply, after a get(), post(), head() or put() request has been mad...
 
This class represents a coordinate reference system (CRS).
 
Class for storing the component parts of a RDBMS data source URI (e.g.
 
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
 
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
 
int removeParam(const QString &key)
Removes a generic parameter by key.
 
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
 
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
 
QgsHttpHeaders httpHeaders() const
Returns http headers.
 
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
 
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
 
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
 
Base class for feedback objects to be used for cancellation of something running in a worker thread.
 
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
 
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
 
QByteArray content() const
Returns the reply content.
 
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
 
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
 
The class is used as a container of context for various read/write operations on other objects.
 
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
 
A rectangle specified with double values.
 
Defines a set of tile matrices for multiple zoom levels.
 
QgsTileMatrix tileMatrix(int zoom) const
Returns the tile matrix corresponding to the specified zoom.
 
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
 
Stores coordinates of a tile in a tile matrix set.
 
Base class for vector tile layer data providers.
 
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
 
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
 
Keeps track of raw tile data that need to be decoded.
 
static bool checkXYZUrlTemplate(const QString &url)
Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)
 
static QString formatXYZUrlTemplate(const QString &url, QgsTileXYZ tile, const QgsTileMatrix &tileMatrix)
Returns formatted tile URL string replacing {x}, {y}, {z} placeholders (or {-y} instead of {y} for TM...
 
#define QgsDebugMsgLevel(str, level)
 
#define QgsDebugError(str)
 
#define QgsSetRequestInitiatorClass(request, _class)
 
#define QgsSetRequestInitiatorId(request, str)
 
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
 
const QgsCoordinateReferenceSystem & crs
 
Setting options for creating vector data providers.