Skip to content
Permalink
Browse files

Deprecate vector layer ctor with default constructed options

replaced by QgsVectorLayer( const QgsVectorLayer::LayerOptions &options,
...
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent f5bc1c7 commit 6813a55fcecc232b073502b1ddd66ed4ca458e71
Showing with 79 additions and 16 deletions.
  1. +37 −5 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +4 −4 src/app/qgisapp.cpp
  3. +2 −2 src/core/qgsvectorlayer.cpp
  4. +36 −5 src/core/qgsvectorlayer.h
@@ -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


@@ -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<QgsMapLayer *> 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 );
@@ -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<QgsGeometryOptions>();
@@ -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()
@@ -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;

0 comments on commit 6813a55

Please sign in to comment.
You can’t perform that action at this time.