diff --git a/python/core/auto_generated/qgsvectorlayer.sip.in b/python/core/auto_generated/qgsvectorlayer.sip.in index 9897a504231..b9e92eae772 100644 --- a/python/core/auto_generated/qgsvectorlayer.sip.in +++ b/python/core/auto_generated/qgsvectorlayer.sip.in @@ -326,11 +326,22 @@ TODO QGIS3: Remove virtual from non-inherited methods (like isModified) struct LayerOptions { - explicit LayerOptions( bool loadDefaultStyle = true, - bool readExtentFromXml = false, - const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() ); + explicit LayerOptions( bool loadDefaultStyle = true, + bool readExtentFromXml = false ); %Docstring Constructor for LayerOptions. + +.. deprecated:: Use version with transformContext argument instead +%End + + explicit LayerOptions( const QgsCoordinateTransformContext & transformContext, + bool loadDefaultStyle = true, + bool readExtentFromXml = false + ); +%Docstring +Constructor for LayerOptions. + +.. versionadded:: 3.10 %End bool loadDefaultStyle; @@ -341,8 +352,8 @@ Constructor for LayerOptions. }; - explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(), - const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() ); + explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(), + const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() ) /Deprecated/; %Docstring Constructor - creates a vector layer @@ -355,6 +366,27 @@ data. :param baseName: The name used to represent the layer in the legend :param providerLib: The name of the data provider, e.g., "memory", "postgres" :param options: layer load options + +.. deprecated:: Use version with options as mandatory argument instead +%End + + + explicit QgsVectorLayer( const QgsVectorLayer::LayerOptions &options, const QString &path = QString(), const QString &baseName = QString(), + const QString &providerLib = "ogr" ); +%Docstring +Constructor - creates a vector layer + +The QgsVectorLayer is constructed by instantiating a data provider. The provider +interprets the supplied path (url) of the data source to connect to and access the +data. + +:param options: layer load options +:param path: The path or url of the parameter. Typically this encodes + parameters used by the data provider as url query items. +:param baseName: The name used to represent the layer in the legend +:param providerLib: The name of the data provider, e.g., "memory", "postgres" + +.. versionadded:: 3.10 %End diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index d58dd68f037..978f6156428 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -4708,7 +4708,7 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layerQStringList, const const bool isRemoteUrl { scheme.startsWith( QStringLiteral( "http" ) ) || scheme == QStringLiteral( "ftp" ) }; // create the layer - QgsVectorLayer::LayerOptions options; + QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; options.loadDefaultStyle = false; if ( isVsiCurl || isRemoteUrl ) { @@ -5254,7 +5254,7 @@ QList QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer ) QgsDebugMsg( "Creating new vector layer using " + composedURI ); QString name = fileName + " " + def.layerName; - QgsVectorLayer::LayerOptions options; + QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; options.loadDefaultStyle = false; QgsVectorLayer *layer = new QgsVectorLayer( composedURI, name, QStringLiteral( "ogr" ), options ); if ( layer && layer->isValid() ) @@ -5318,7 +5318,7 @@ void QgisApp::addDatabaseLayers( QStringList const &layerPathList, QString const // create the layer QgsDataSourceUri uri( layerPath ); - QgsVectorLayer::LayerOptions options; + QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; options.loadDefaultStyle = false; QgsVectorLayer *layer = new QgsVectorLayer( uri.uri( false ), uri.table(), providerKey, options ); Q_CHECK_PTR( layer ); @@ -11108,7 +11108,7 @@ QgsVectorLayer *QgisApp::addVectorLayerPrivate( const QString &vectorLayerPath, } // create the layer - QgsVectorLayer::LayerOptions options; + QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; // Default style is loaded later in this method options.loadDefaultStyle = false; QgsVectorLayer *layer = new QgsVectorLayer( vectorLayerPath, baseName, providerKey, options ); diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index f811663ac52..10b8fc2d879 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -139,6 +139,7 @@ typedef bool deleteStyleById_t( ); + QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey, @@ -148,7 +149,6 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath, , mAuxiliaryLayerKey( QString() ) , mReadExtentFromXml( options.readExtentFromXml ) { - setProviderType( providerKey ); mGeometryOptions = qgis::make_unique(); @@ -179,8 +179,8 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath, mSimplifyMethod.setThreshold( settings.value( QStringLiteral( "qgis/simplifyDrawingTol" ), mSimplifyMethod.threshold() ).toFloat() ); mSimplifyMethod.setForceLocalOptimization( settings.value( QStringLiteral( "qgis/simplifyLocal" ), mSimplifyMethod.forceLocalOptimization() ).toBool() ); mSimplifyMethod.setMaximumScale( settings.value( QStringLiteral( "qgis/simplifyMaxScale" ), mSimplifyMethod.maximumScale() ).toFloat() ); -} // QgsVectorLayer ctor +} // QgsVectorLayer ctor QgsVectorLayer::~QgsVectorLayer() diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index 70839560e69..d4010d461b3 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -400,11 +400,23 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte /** * Constructor for LayerOptions. + * \deprecated Use version with transformContext argument instead */ - explicit LayerOptions( bool loadDefaultStyle = true, - bool readExtentFromXml = false, - const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() ) + Q_DECL_DEPRECATED explicit LayerOptions( bool loadDefaultStyle = true, + bool readExtentFromXml = false ) : loadDefaultStyle( loadDefaultStyle ) + , readExtentFromXml( readExtentFromXml ) SIP_DEPRECATED + {} + + /** + * Constructor for LayerOptions. + * \since QGIS 3.10 + */ + explicit LayerOptions( const QgsCoordinateTransformContext & transformContext, + bool loadDefaultStyle = true, + bool readExtentFromXml = false + ) + : loadDefaultStyle( loadDefaultStyle ) , readExtentFromXml( readExtentFromXml ) , transformContext( transformContext ) {} @@ -438,9 +450,28 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte * \param baseName The name used to represent the layer in the legend * \param providerLib The name of the data provider, e.g., "memory", "postgres" * \param options layer load options + * \deprecated Use version with options as mandatory argument instead */ - explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(), - const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() ); + Q_DECL_DEPRECATED explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(), + const QString &providerLib = "ogr", const QgsVectorLayer::LayerOptions &options = QgsVectorLayer::LayerOptions() ) SIP_DEPRECATED; + + + /** + * Constructor - creates a vector layer + * + * The QgsVectorLayer is constructed by instantiating a data provider. The provider + * interprets the supplied path (url) of the data source to connect to and access the + * data. + * + * \param options layer load options + * \param path The path or url of the parameter. Typically this encodes + * parameters used by the data provider as url query items. + * \param baseName The name used to represent the layer in the legend + * \param providerLib The name of the data provider, e.g., "memory", "postgres" + * \since QGIS 3.10 + */ + explicit QgsVectorLayer( const QgsVectorLayer::LayerOptions &options, const QString &path = QString(), const QString &baseName = QString(), + const QString &providerLib = "ogr" ); ~QgsVectorLayer() override;