Skip to content
Permalink
Browse files

Merge pull request #6645 from manisandro/pluginlayer_30

[3.0 backport] Add a minimal data provider for plugin layers
  • Loading branch information
manisandro committed Mar 20, 2018
2 parents 7d2c897 + b827e08 commit dfb0c4f3026e2f5bda3131b684e814c4b15fd5dc
Showing with 43 additions and 2 deletions.
  1. +3 −1 python/core/qgspluginlayer.sip.in
  2. +35 −0 src/core/qgspluginlayer.cpp
  3. +5 −1 src/core/qgspluginlayer.h
@@ -7,7 +7,6 @@
************************************************************************/



class QgsPluginLayer : QgsMapLayer
{
%Docstring
@@ -54,6 +53,9 @@ Set source string. This is used for example in layer tree to show tooltip.
.. versionadded:: 2.16
%End

virtual QgsDataProvider *dataProvider();


protected:
};

@@ -17,17 +17,41 @@
#include "qgsmaplayerlegend.h"
#include "qgsmaplayerrenderer.h"


/**
A minimal data provider for plugin layers
*/
///@cond PRIVATE
class QgsPluginLayerDataProvider : public QgsDataProvider
{
public:
QgsPluginLayerDataProvider( const QString &layerType ) : mName( layerType ) {}
void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
virtual QgsCoordinateReferenceSystem crs() const { return QgsCoordinateReferenceSystem(); }
virtual QString name() const override { return mName; }
QString description() const override { return ""; }
virtual QgsRectangle extent() const { return mExtent; }
virtual bool isValid() const { return true; }

private:
QString mName;
QgsRectangle mExtent;
};
///@endcond

QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerName )
: QgsMapLayer( PluginLayer, layerName )
, mPluginLayerType( layerType )
{
mDataProvider = new QgsPluginLayerDataProvider( layerType );
}

QgsPluginLayer::~QgsPluginLayer()
{
// TODO: shall we move the responsibility of emitting the signal to plugin
// layer implementations before they start doing their part of cleanup...?
emit willBeDeleted();
delete mDataProvider;
}

QString QgsPluginLayer::pluginLayerType()
@@ -38,9 +62,20 @@ QString QgsPluginLayer::pluginLayerType()
void QgsPluginLayer::setExtent( const QgsRectangle &extent )
{
mExtent = extent;
static_cast<QgsPluginLayerDataProvider *>( mDataProvider )->setExtent( extent );
}

void QgsPluginLayer::setSource( const QString &source )
{
mDataSource = source;
}

QgsDataProvider *QgsPluginLayer::dataProvider()
{
return mDataProvider;
}

const QgsDataProvider *QgsPluginLayer::dataProvider() const
{
return mDataProvider;
}
@@ -17,7 +17,7 @@

#include "qgis_core.h"
#include "qgsmaplayer.h"

#include "qgsdataprovider.h"

/**
* \ingroup core
@@ -55,8 +55,12 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
*/
void setSource( const QString &source );

QgsDataProvider *dataProvider() override;
const QgsDataProvider *dataProvider() const override SIP_SKIP;

protected:
QString mPluginLayerType;
QgsDataProvider *mDataProvider;
};

#endif // QGSPLUGINLAYER_H

0 comments on commit dfb0c4f

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