Skip to content
Permalink
Browse files

Handle the coordinate tranform context in the layer ctor

Also use the context when read/write XML by passing it
in the R/W context
  • Loading branch information
elpaso authored and nyalldawson committed Mar 22, 2019
1 parent 6962649 commit df2bdf9c1a88ba780a53a5010d6e72ba871170a0
Showing with 215 additions and 89 deletions.
  1. +1 −1 python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
  2. +13 −13 python/core/auto_generated/qgsdataprovider.sip.in
  3. +18 −0 python/core/auto_generated/qgsreadwritecontext.sip.in
  4. +1 −1 python/core/auto_generated/qgsvectordataprovider.sip.in
  5. +14 −1 python/core/auto_generated/qgsvectorlayer.sip.in
  6. +1 −1 python/core/auto_generated/raster/qgsrasterdataprovider.sip.in
  7. +12 −1 python/core/auto_generated/raster/qgsrasterlayer.sip.in
  8. +1 −1 src/core/mesh/qgsmeshdataprovider.h
  9. +2 −2 src/core/mesh/qgsmeshmemorydataprovider.h
  10. +2 −2 src/core/providers/memory/qgsmemoryprovider.h
  11. +7 −7 src/core/qgsdataprovider.cpp
  12. +13 −13 src/core/qgsdataprovider.h
  13. +1 −1 src/core/qgspluginlayer.h
  14. +7 −0 src/core/qgsproject.cpp
  15. +11 −0 src/core/qgsreadwritecontext.cpp
  16. +20 −0 src/core/qgsreadwritecontext.h
  17. +1 −1 src/core/qgsvectordataprovider.h
  18. +8 −2 src/core/qgsvectorlayer.cpp
  19. +19 −1 src/core/qgsvectorlayer.h
  20. +1 −1 src/core/raster/qgsrasterdataprovider.h
  21. +7 −1 src/core/raster/qgsrasterlayer.cpp
  22. +17 −1 src/core/raster/qgsrasterlayer.h
  23. +1 −1 src/providers/arcgisrest/qgsafsprovider.cpp
  24. +1 −1 src/providers/arcgisrest/qgsafsprovider.h
  25. +1 −1 src/providers/arcgisrest/qgsamsprovider.h
  26. +2 −2 src/providers/db2/qgsdb2provider.h
  27. +1 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.h
  28. +1 −1 src/providers/gdal/qgsgdalprovider.h
  29. +1 −1 src/providers/gpx/qgsgpxprovider.h
  30. +1 −1 src/providers/mdal/qgsmdalprovider.h
  31. +2 −2 src/providers/mssql/qgsmssqlprovider.h
  32. +2 −2 src/providers/ogr/qgsogrprovider.h
  33. +1 −1 src/providers/ows/qgsowsprovider.h
  34. +3 −3 src/providers/postgres/qgspostgresprovider.h
  35. +2 −2 src/providers/spatialite/qgsspatialiteprovider.h
  36. +1 −1 src/providers/virtual/qgsvirtuallayerprovider.h
  37. +1 −1 src/providers/wcs/qgswcsprovider.cpp
  38. +1 −1 src/providers/wcs/qgswcsprovider.h
  39. +1 −1 src/providers/wfs/qgswfsprovider.cpp
  40. +1 −1 src/providers/wfs/qgswfsprovider.h
  41. +3 −3 src/providers/wms/qgswmscapabilities.cpp
  42. +3 −3 src/providers/wms/qgswmscapabilities.h
  43. +6 −6 src/providers/wms/qgswmsprovider.cpp
  44. +1 −1 src/providers/wms/qgswmsprovider.h
  45. +1 −1 src/providers/wms/qgswmssourceselect.cpp
@@ -556,7 +556,7 @@ Responsible for reading native mesh data
#include "qgsmeshdataprovider.h"
%End
public:
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );
%Docstring
Ctor
%End
@@ -61,7 +61,7 @@ Abstract base class for spatial data provider implementations.
QgsCoordinateTransformContext coordinateTransformContext;
};

QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() );
QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );
%Docstring
Create a new dataprovider with the specified in the ``uri``.

@@ -387,24 +387,24 @@ Returns ``True`` if metadata was successfully written to the data provider.
.. versionadded:: 3.0
%End

QgsDataProvider::ProviderOptions options() const;
QgsCoordinateTransformContext coordinateTransformContext() const;
%Docstring
Returns data provider options
Returns data provider coordinate transform context

.. seealso:: :py:func:`setOptions`
.. seealso:: :py:func:`setCoordinateTranformContext`

.. seealso:: :py:func:`optionsChanged`
.. seealso:: :py:func:`coordinateTransformContextChanged`

.. versionadded:: 3.10
%End

void setOptions( const QgsDataProvider::ProviderOptions &options );
void setCoordinateTransformContext( const QgsCoordinateTransformContext &coordinateTransformContext );
%Docstring
Sets data provider options to ``options``
Sets data coordinate transform context to ``coordinateTransformContext``

.. seealso:: :py:func:`options`
.. seealso:: :py:func:`coordinateTransformContext`

.. seealso:: :py:func:`optionsChanged`
.. seealso:: :py:func:`coordinateTransformContextChanged`

.. versionadded:: 3.10
%End
@@ -444,13 +444,13 @@ Emitted when the datasource issues a notification.
.. versionadded:: 3.0
%End

void optionsChanged( const QgsDataProvider::ProviderOptions &options );
void coordinateTransformContextChanged( const QgsCoordinateTransformContext &coordinateTransformContext );
%Docstring
Emitted when the data provider options has changed
Emitted when the data provider coordinate transform context has changed

.. seealso:: :py:func:`setOptions`
.. seealso:: :py:func:`coordinateTransformContext`

.. seealso:: :py:func:`options`
.. seealso:: :py:func:`setCoordinateTranformContext`

.. versionadded:: 3.10
%End
@@ -111,6 +111,24 @@ Sets the project translator. Means it shouldn't conform mDefaultTranslator anymo
It's usually the QgsProject where the function with the context is made and won't be changed anymore.

.. versionadded:: 3.4
%End

QgsCoordinateTransformContext coordinateTransformContext() const;
%Docstring
Returns data provider coordinate transform context

.. seealso:: :py:func:`setCoordinateTranformContext`

.. versionadded:: 3.10
%End

void setCoordinateTransformContext( const QgsCoordinateTransformContext &coordinateTransformContext );
%Docstring
Sets data coordinate transform context to ``coordinateTransformContext``

.. seealso:: :py:func:`coordinateTransformContext`

.. versionadded:: 3.10
%End

public:
@@ -68,7 +68,7 @@ of feature and attribute information from a spatial datasource.
UnknownCount,
};

QgsVectorDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() );
QgsVectorDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );
%Docstring
Constructor for a vector data provider.

@@ -326,7 +326,9 @@ TODO QGIS3: Remove virtual from non-inherited methods (like isModified)
struct LayerOptions
{

explicit LayerOptions( bool loadDefaultStyle = true, bool readExtentFromXml = false );
explicit LayerOptions( bool loadDefaultStyle = true,
bool readExtentFromXml = false,
const QgsCoordinateTransformContext &coordinateTransformContext = QgsCoordinateTransformContext() );
%Docstring
Constructor for LayerOptions.
%End
@@ -335,6 +337,8 @@ Constructor for LayerOptions.

bool readExtentFromXml;

QgsCoordinateTransformContext coordinateTransformContext;

};

explicit QgsVectorLayer( const QString &path = QString(), const QString &baseName = QString(),
@@ -2260,6 +2264,7 @@ Configuration and logic to apply automatically on any edit happening on this lay




public slots:

void select( QgsFeatureId featureId );
@@ -2330,6 +2335,14 @@ rollBack().
.. seealso:: :py:func:`rollBack`
%End


void changeCoordinateTranformContext( const QgsCoordinateTransformContext &coordinateTransformContext );
%Docstring
Change coordinate transform context to ``coordinateTransformContext``

.. versionadded:: 3.10
%End

signals:

void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );
@@ -82,7 +82,7 @@ Base class for raster data providers.

QgsRasterDataProvider();

QgsRasterDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() );
QgsRasterDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );
%Docstring
Constructor for QgsRasterDataProvider.

@@ -104,12 +104,16 @@ Constructor. Provider is not set.
struct LayerOptions
{

explicit LayerOptions( bool loadDefaultStyle = true );
explicit LayerOptions( bool loadDefaultStyle = true,
const QgsCoordinateTransformContext &coordinateTransformContext = QgsCoordinateTransformContext() );
%Docstring
Constructor for LayerOptions.
%End

bool loadDefaultStyle;

QgsCoordinateTransformContext coordinateTransformContext;

};

explicit QgsRasterLayer( const QString &uri,
@@ -380,6 +384,13 @@ Writes the symbology of the layer into the document provided in SLD 1.0.0 format
public slots:
void showStatusMessage( const QString &message );

void changeCoordinateTranformContext( const QgsCoordinateTransformContext &coordinateTransformContext );
%Docstring
Change coordinate transform context to ``coordinateTransformContext``

.. versionadded:: 3.10
%End

protected:
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );

@@ -551,7 +551,7 @@ class CORE_EXPORT QgsMeshDataProvider: public QgsDataProvider, public QgsMeshDat

public:
//! Ctor
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );

signals:
//! Emitted when some new dataset groups have been added
@@ -96,7 +96,7 @@ class CORE_EXPORT QgsMeshMemoryDataProvider: public QgsMeshDataProvider
* );
* \endcode
*/
QgsMeshMemoryDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
QgsMeshMemoryDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );

bool isValid() const override;
QString name() const override;
@@ -160,7 +160,7 @@ class CORE_EXPORT QgsMeshMemoryDataProvider: public QgsMeshDataProvider
//! Returns the memory provider description
static QString providerDescription();
//! Provider factory
static QgsMeshMemoryDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
static QgsMeshMemoryDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );

private:
void calculateMinMaxForDatasetGroup( QgsMeshMemoryDatasetGroup &grp ) const;
@@ -31,7 +31,7 @@ class QgsMemoryProvider : public QgsVectorDataProvider
Q_OBJECT

public:
explicit QgsMemoryProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &options );
explicit QgsMemoryProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &coordinateTransformContext );

~QgsMemoryProvider() override;

@@ -44,7 +44,7 @@ class QgsMemoryProvider : public QgsVectorDataProvider
* Creates a new memory provider, with provider properties embedded within the given \a uri and \a options
* argument.
*/
static QgsMemoryProvider *createProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &options );
static QgsMemoryProvider *createProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &coordinateTransformContext );

/* Implementation of functions from QgsVectorDataProvider */

@@ -17,9 +17,9 @@

QString QgsDataProvider::SUBLAYER_SEPARATOR = QString( "!!::!!" );

QgsDataProvider::QgsDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
QgsDataProvider::QgsDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions )
: mDataSourceURI( uri ),
mOptions( options )
mOptions( providerOptions )
{
}

@@ -53,13 +53,13 @@ bool QgsDataProvider::renderInPreview( const PreviewContext &context )
return context.lastRenderingTimeMs <= context.maxRenderingTimeMs;
}

QgsDataProvider::ProviderOptions QgsDataProvider::options() const
QgsCoordinateTransformContext QgsDataProvider::coordinateTransformContext() const
{
return mOptions;
return mOptions.coordinateTransformContext;
}

void QgsDataProvider::setOptions( const QgsDataProvider::ProviderOptions &options )
void QgsDataProvider::setCoordinateTransformContext( const QgsCoordinateTransformContext &value )
{
mOptions = options;
emit optionsChanged( options );
mOptions.coordinateTransformContext = value;
emit coordinateTransformContextChanged( value );
}
@@ -106,7 +106,7 @@ class CORE_EXPORT QgsDataProvider : public QObject
*
* Additional creation options are specified within the \a options value.
*/
QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() );
QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );

/**
* Returns the coordinate system for the data source.
@@ -522,24 +522,24 @@ class CORE_EXPORT QgsDataProvider : public QObject
virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ); return false; }

/**
* Returns data provider options
* Returns data provider coordinate transform context
*
* \see setOptions()
* \see optionsChanged()
* \see setCoordinateTranformContext()
* \see coordinateTransformContextChanged()
*
* \since QGIS 3.10
*/
QgsDataProvider::ProviderOptions options() const;
QgsCoordinateTransformContext coordinateTransformContext() const;

/**
* Sets data provider options to \a options
* Sets data coordinate transform context to \a coordinateTransformContext
*
* \see options()
* \see optionsChanged()
* \see coordinateTransformContext()
* \see coordinateTransformContextChanged()
*
* \since QGIS 3.10
*/
void setOptions( const QgsDataProvider::ProviderOptions &options );
void setCoordinateTransformContext( const QgsCoordinateTransformContext &coordinateTransformContext );

signals:

@@ -575,14 +575,14 @@ class CORE_EXPORT QgsDataProvider : public QObject
void notify( const QString &msg );

/**
* Emitted when the data provider options has changed
* Emitted when the data provider coordinate transform context has changed
*
* \see setOptions()
* \see options()
* \see coordinateTransformContext()
* \see setCoordinateTranformContext()
*
* \since QGIS 3.10
*/
void optionsChanged( const QgsDataProvider::ProviderOptions &options );
void coordinateTransformContextChanged( const QgsCoordinateTransformContext &coordinateTransformContext );


protected:
@@ -74,7 +74,7 @@ class QgsPluginLayerDataProvider : public QgsDataProvider
Q_OBJECT

public:
QgsPluginLayerDataProvider( const QString &layerType, const QgsDataProvider::ProviderOptions &options );
QgsPluginLayerDataProvider( const QString &layerType, const QgsDataProvider::ProviderOptions &providerOptions );
void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
QgsCoordinateReferenceSystem crs() const override;
QString name() const override;
@@ -923,6 +923,8 @@ bool QgsProject::_getMapLayers( const QDomDocument &doc, QList<QDomNode> &broken
QgsReadWriteContext context;
context.setPathResolver( pathResolver() );
context.setProjectTranslator( this );
context.setCoordinateTransformContext( transformContext() );

if ( !addLayer( element, brokenNodes, context ) )
{
returnStatus = false;
@@ -1646,6 +1648,7 @@ bool QgsProject::readLayer( const QDomNode &layerNode )
QgsReadWriteContext context;
context.setPathResolver( pathResolver() );
context.setProjectTranslator( this );
context.setCoordinateTransformContext( transformContext() );
QList<QDomNode> brokenNodes;
if ( addLayer( layerNode.toElement(), brokenNodes, context ) )
{
@@ -1693,6 +1696,7 @@ bool QgsProject::write()
}

QgsReadWriteContext context;
context.setCoordinateTransformContext( transformContext() );
if ( !storage->writeProject( mFile.fileName(), &tmpZipFile, context ) )
{
QString err = tr( "Unable to save project to storage %1" ).arg( mFile.fileName() );
@@ -1749,6 +1753,7 @@ bool QgsProject::writeProjectFile( const QString &filename )

QgsReadWriteContext context;
context.setPathResolver( pathResolver() );
context.setCoordinateTransformContext( transformContext() );

QDomImplementation DomImplementation;
DomImplementation.setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
@@ -2304,6 +2309,7 @@ bool QgsProject::createEmbeddedLayer( const QString &layerId, const QString &pro
if ( !useAbsolutePaths )
embeddedContext.setPathResolver( QgsPathResolver( projectFilePath ) );
embeddedContext.setProjectTranslator( this );
embeddedContext.setCoordinateTransformContext( transformContext() );

QDomElement projectLayersElem = sProjectDocument.documentElement().firstChildElement( QStringLiteral( "projectlayers" ) );
if ( projectLayersElem.isNull() )
@@ -2361,6 +2367,7 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
QgsReadWriteContext context;
context.setPathResolver( pathResolver() );
context.setProjectTranslator( this );
context.setCoordinateTransformContext( transformContext() );

QgsLayerTreeGroup *root = new QgsLayerTreeGroup;

0 comments on commit df2bdf9

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