Skip to content

Commit

Permalink
Deprecate vector layer ctor with default constructed options
Browse files Browse the repository at this point in the history
replaced by QgsVectorLayer( const QgsVectorLayer::LayerOptions &options,
...
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent f5bc1c7 commit 6813a55
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
42 changes: 37 additions & 5 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand All @@ -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


Expand Down
8 changes: 4 additions & 4 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef bool deleteStyleById_t(
);



QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
const QString &baseName,
const QString &providerKey,
Expand All @@ -148,7 +149,6 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
, mAuxiliaryLayerKey( QString() )
, mReadExtentFromXml( options.readExtentFromXml )
{

setProviderType( providerKey );

mGeometryOptions = qgis::make_unique<QgsGeometryOptions>();
Expand Down Expand Up @@ -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()
Expand Down
41 changes: 36 additions & 5 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6813a55

Please sign in to comment.