Skip to content

Commit

Permalink
Handle the coordinate tranform context in the layer ctor
Browse files Browse the repository at this point in the history
Also use the context when read/write XML by passing it
in the R/W context
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent 6962649 commit df2bdf9
Show file tree
Hide file tree
Showing 45 changed files with 215 additions and 89 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions python/core/auto_generated/qgsdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions python/core/auto_generated/qgsreadwritecontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsvectordataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
15 changes: 14 additions & 1 deletion python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -335,6 +337,8 @@ Constructor for LayerOptions.

bool readExtentFromXml;

QgsCoordinateTransformContext coordinateTransformContext;

};

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




public slots:

void select( QgsFeatureId featureId );
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 12 additions & 1 deletion python/core/auto_generated/raster/qgsrasterlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgsmeshdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshmemorydataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/providers/memory/qgsmemoryprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
}

Expand Down Expand Up @@ -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 );
}
26 changes: 13 additions & 13 deletions src/core/qgsdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspluginlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -1749,6 +1753,7 @@ bool QgsProject::writeProjectFile( const QString &filename )

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

QDomImplementation DomImplementation;
DomImplementation.setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit df2bdf9

Please sign in to comment.