Skip to content

Commit

Permalink
Merge pull request #45262 from nyalldawson/provider
Browse files Browse the repository at this point in the history
Always pass on transform context to providers, even minimal ones
  • Loading branch information
rouault committed Sep 28, 2021
2 parents 7188cdf + 094302d commit 08ad87f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
15 changes: 14 additions & 1 deletion python/core/auto_generated/vectortile/qgsvectortilelayer.sip.in
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -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 );

Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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() );
Expand Down
8 changes: 7 additions & 1 deletion src/core/annotations/qgsannotationlayer.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -325,6 +328,9 @@ QgsRectangle QgsAnnotationLayer::extent() const

void QgsAnnotationLayer::setTransformContext( const QgsCoordinateTransformContext &context )
{
if ( mDataProvider )
mDataProvider->setTransformContext( context );

mTransformContext = context;
invalidateWgs84Extent();
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsmaplayerfactory.cpp
Expand Up @@ -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:
{
Expand Down
13 changes: 9 additions & 4 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}

Expand Down
25 changes: 24 additions & 1 deletion src/core/vectortile/qgsvectortilelayer.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 08ad87f

Please sign in to comment.