Skip to content

Commit

Permalink
Move setDataSource to QgsMapLayer
Browse files Browse the repository at this point in the history
also setter and getter for providerType
  • Loading branch information
elpaso committed Nov 5, 2018
1 parent 7bbd1ca commit c32d542
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
42 changes: 42 additions & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,31 @@ Write just the symbology information for the layer into the document
.. versionadded:: 2.16
%End


virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.

Subclasses should override this method: default implementation does nothing.

:param dataSource: new layer data source
:param baseName: base name of the layer
:param provider: provider string
:param options: provider options
:param loadDefaultStyleFlag: set to true to reset the layer's style to the default for the
data source

.. seealso:: :py:func:`dataSourceChanged`

.. versionadded:: 3.6
%End

QString providerType() const;
%Docstring
Returns the provider type (provider key) for this layer
%End

QUndoStack *undoStack();
%Docstring
Returns pointer to layer's undo stack
Expand Down Expand Up @@ -1212,6 +1237,7 @@ Returns true if the refresh on provider nofification is enabled
.. versionadded:: 3.0
%End


public slots:

void setMinimumScale( double scale );
Expand Down Expand Up @@ -1432,6 +1458,15 @@ Emitted when layer's flags have been modified.
.. seealso:: :py:func:`flags`

.. versionadded:: 3.4
%End

void dataSourceChanged();
%Docstring
Emitted whenever the layer's data source has been changed.

.. seealso:: :py:func:`setDataSource`

.. versionadded:: 3.5
%End

protected:
Expand Down Expand Up @@ -1535,6 +1570,11 @@ Read style data common to all layer types
.. versionadded:: 3.0
%End

void setProviderType( const QString &providerType );
%Docstring
Sets the ``providerType`` (provider key)
%End


void appendError( const QgsErrorMessage &error );
%Docstring
Expand Down Expand Up @@ -1563,6 +1603,8 @@ Checks whether a new set of dependencies will introduce a cycle
%End




};

QFlags<QgsMapLayer::LayerFlag> operator|(QgsMapLayer::LayerFlag f1, QFlags<QgsMapLayer::LayerFlag> f2);
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,21 @@ bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorM
return false;
}

void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
{
Q_UNUSED( dataSource );
Q_UNUSED( baseName );
Q_UNUSED( provider );
Q_UNUSED( options );
Q_UNUSED( loadDefaultStyleFlag );
}


QString QgsMapLayer::providerType() const
{
return mProviderKey;
}

void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
QgsMapLayer::StyleCategories categories )
{
Expand Down Expand Up @@ -1818,6 +1833,11 @@ bool QgsMapLayer::isReadOnly() const
return true;
}

void QgsMapLayer::setProviderType( const QString &providerType )
{
mProviderKey = providerType;
}

QSet<QgsMapLayerDependency> QgsMapLayer::dependencies() const
{
return mDependencies;
Expand Down
41 changes: 41 additions & 0 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "qgslayermetadata.h"
#include "qgsmaplayerstyle.h"
#include "qgsreadwritecontext.h"
#include "qgsdataprovider.h"

class QgsAbstract3DRenderer;
class QgsDataProvider;
Expand Down Expand Up @@ -886,6 +887,29 @@ class CORE_EXPORT QgsMapLayer : public QObject
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
StyleCategories categories = AllStyleCategories ) const;


/**
* Updates the data source of the layer. The layer's renderer and legend will be preserved only
* if the geometry type of the new data source matches the current geometry type of the layer.
*
* Subclasses should override this method: default implementation does nothing.
*
* \param dataSource new layer data source
* \param baseName base name of the layer
* \param provider provider string
* \param options provider options
* \param loadDefaultStyleFlag set to true to reset the layer's style to the default for the
* data source
* \see dataSourceChanged()
* \since QGIS 3.6
*/
virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );

/**
* Returns the provider type (provider key) for this layer
*/
QString providerType() const;

//! Returns pointer to layer's undo stack
QUndoStack *undoStack();

Expand Down Expand Up @@ -1077,6 +1101,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }


public slots:

/**
Expand Down Expand Up @@ -1253,6 +1278,15 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void flagsChanged();

/**
* Emitted whenever the layer's data source has been changed.
*
* \see setDataSource()
*
* \since QGIS 3.5
*/
void dataSourceChanged();

private slots:

void onNotifiedTriggerRepaint( const QString &message );
Expand Down Expand Up @@ -1340,6 +1374,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
StyleCategories categories = AllStyleCategories );

//! Sets the \a providerType (provider key)
void setProviderType( const QString &providerType );

#ifndef SIP_RUN
#if 0
//! Debugging member - invoked when a connect() is made to this object
Expand Down Expand Up @@ -1400,6 +1437,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
bool mIsRefreshOnNofifyEnabled = false;
QString mRefreshOnNofifyMessage;

//! Data provider key (name of the data provider)
QString mProviderKey;


private:

virtual QString baseURI( PropertyType type ) const;
Expand Down

0 comments on commit c32d542

Please sign in to comment.