Skip to content

Commit

Permalink
Merge pull request #6643 from manisandro/pluginlayer
Browse files Browse the repository at this point in the history
Add a minimal data provider for plugin layers
  • Loading branch information
manisandro authored Mar 20, 2018
2 parents 94e3d1c + e90ac56 commit 40da51c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion python/core/qgspluginlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
************************************************************************/



class QgsPluginLayer : QgsMapLayer
{
%Docstring
Expand Down Expand Up @@ -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:
};

Expand Down
35 changes: 35 additions & 0 deletions src/core/qgspluginlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
6 changes: 5 additions & 1 deletion src/core/qgspluginlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

#include "qgsdataprovider.h"

/**
* \ingroup core
Expand Down Expand Up @@ -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 40da51c

Please sign in to comment.