Merge pull request #45262 from nyalldawson/provider

Always pass on transform context to providers, even minimal ones
This commit is contained in:
Even Rouault 2021-09-28 21:20:53 +02:00 committed by GitHub
commit 08ad87f123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 11 deletions

View File

@ -71,7 +71,20 @@ Currently supported decoders:
#include "qgsvectortilelayer.h"
%End
public:
explicit QgsVectorTileLayer( const QString &path = QString(), const QString &baseName = QString() );
struct LayerOptions
{
explicit LayerOptions( const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext( ) );
%Docstring
Constructor for LayerOptions with optional ``transformContext``.
%End
QgsCoordinateTransformContext transformContext;
};
explicit QgsVectorTileLayer( const QString &path = QString(), const QString &baseName = QString(), const QgsVectorTileLayer::LayerOptions &options = QgsVectorTileLayer::LayerOptions() );
%Docstring
Constructs a new vector tile layer
%End

View File

@ -2159,7 +2159,8 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
{
QgsTemporaryCursorOverride busyCursor( Qt::WaitCursor );
QgsVectorTileLayer *layer = new QgsVectorTileLayer( uri, u.name );
const QgsVectorTileLayer::LayerOptions options( QgsProject::instance()->transformContext() );
QgsVectorTileLayer *layer = new QgsVectorTileLayer( uri, u.name, options );
bool ok = false;
layer->loadDefaultMetadata( ok );
@ -6004,7 +6005,8 @@ QgsVectorTileLayer *QgisApp::addVectorTileLayerPrivate( const QString &url, cons
QgsDebugMsgLevel( "completeBaseName: " + base, 2 );
// create the layer
std::unique_ptr<QgsVectorTileLayer> layer( new QgsVectorTileLayer( url, base ) );
const QgsVectorTileLayer::LayerOptions options( QgsProject::instance()->transformContext() );
std::unique_ptr<QgsVectorTileLayer> layer( new QgsVectorTileLayer( url, base, options ) );
if ( !layer || !layer->isValid() )
{
@ -7609,7 +7611,8 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
QUrlQuery uq;
uq.addQueryItem( QStringLiteral( "type" ), QStringLiteral( "mbtiles" ) );
uq.addQueryItem( QStringLiteral( "url" ), fileName );
std::unique_ptr<QgsVectorTileLayer> vtLayer( new QgsVectorTileLayer( uq.toString(), fileInfo.completeBaseName() ) );
const QgsVectorTileLayer::LayerOptions options( QgsProject::instance()->transformContext() );
std::unique_ptr<QgsVectorTileLayer> vtLayer( new QgsVectorTileLayer( uq.toString(), fileInfo.completeBaseName(), options ) );
if ( vtLayer->isValid() )
{
QgsProject::instance()->addMapLayer( vtLayer.release() );

View File

@ -107,7 +107,10 @@ QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions
{
mShouldValidateCrs = false;
mValid = true;
mDataProvider = new QgsAnnotationLayerDataProvider( QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() );
QgsDataProvider::ProviderOptions providerOptions;
providerOptions.transformContext = options.transformContext;
mDataProvider = new QgsAnnotationLayerDataProvider( providerOptions, QgsDataProvider::ReadFlags() );
mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
mPaintEffect->setEnabled( false );
@ -325,6 +328,9 @@ QgsRectangle QgsAnnotationLayer::extent() const
void QgsAnnotationLayer::setTransformContext( const QgsCoordinateTransformContext &context )
{
if ( mDataProvider )
mDataProvider->setTransformContext( context );
mTransformContext = context;
invalidateWgs84Extent();
}

View File

@ -95,7 +95,10 @@ QgsMapLayer *QgsMapLayerFactory::createLayer( const QString &uri, const QString
}
case QgsMapLayerType::VectorTileLayer:
return new QgsVectorTileLayer( uri, name );
{
const QgsVectorTileLayer::LayerOptions vectorTileOptions( options.transformContext );
return new QgsVectorTileLayer( uri, name, vectorTileOptions );
}
case QgsMapLayerType::AnnotationLayer:
{

View File

@ -36,8 +36,9 @@
#include <QUrl>
#include <QUrlQuery>
QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName, const LayerOptions &options )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
, mTransformContext( options.transformContext )
{
mDataSource = uri;
@ -129,7 +130,7 @@ bool QgsVectorTileLayer::loadDataSource()
setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );
const QgsDataProvider::ProviderOptions providerOptions { transformContext() };
const QgsDataProvider::ProviderOptions providerOptions { mTransformContext };
const QgsDataProvider::ReadFlags flags;
mDataProvider.reset( new QgsVectorTileDataProvider( providerOptions, flags ) );
mProviderKey = mDataProvider->name();
@ -207,7 +208,8 @@ QgsVectorTileLayer::~QgsVectorTileLayer() = default;
QgsVectorTileLayer *QgsVectorTileLayer::clone() const
{
QgsVectorTileLayer *layer = new QgsVectorTileLayer( source(), name() );
const QgsVectorTileLayer::LayerOptions options( mTransformContext );
QgsVectorTileLayer *layer = new QgsVectorTileLayer( source(), name(), options );
layer->setRenderer( renderer() ? renderer()->clone() : nullptr );
return layer;
}
@ -385,7 +387,10 @@ bool QgsVectorTileLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QStr
void QgsVectorTileLayer::setTransformContext( const QgsCoordinateTransformContext &transformContext )
{
Q_UNUSED( transformContext )
if ( mDataProvider )
mDataProvider->setTransformContext( transformContext );
mTransformContext = transformContext;
invalidateWgs84Extent();
}

View File

@ -85,8 +85,29 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
Q_OBJECT
public:
/**
* Setting options for loading vector tile layers.
*
* \since QGIS 3.22
*/
struct LayerOptions
{
/**
* Constructor for LayerOptions with optional \a transformContext.
*/
explicit LayerOptions( const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext( ) )
: transformContext( transformContext )
{}
//! Coordinate transform context
QgsCoordinateTransformContext transformContext;
};
//! Constructs a new vector tile layer
explicit QgsVectorTileLayer( const QString &path = QString(), const QString &baseName = QString() );
explicit QgsVectorTileLayer( const QString &path = QString(), const QString &baseName = QString(), const QgsVectorTileLayer::LayerOptions &options = QgsVectorTileLayer::LayerOptions() );
~QgsVectorTileLayer() override;
#ifdef SIP_RUN
@ -195,6 +216,8 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
QVariantMap mArcgisLayerConfiguration;
QgsCoordinateTransformContext mTransformContext;
std::unique_ptr< QgsDataProvider > mDataProvider;
bool setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri );