Skip to content

Commit b827e08

Browse files
committed
Add a minimal data provider for plugin layers
Throughout the codebase, there is a general assumption that layer->dataProvider() is not null. This wasn't the case for plugin layers.
1 parent 7d2c897 commit b827e08

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

python/core/qgspluginlayer.sip.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
************************************************************************/
88

99

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

56+
virtual QgsDataProvider *dataProvider();
57+
58+
5759
protected:
5860
};
5961

src/core/qgspluginlayer.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,41 @@
1717
#include "qgsmaplayerlegend.h"
1818
#include "qgsmaplayerrenderer.h"
1919

20+
21+
/**
22+
A minimal data provider for plugin layers
23+
*/
24+
///@cond PRIVATE
25+
class QgsPluginLayerDataProvider : public QgsDataProvider
26+
{
27+
public:
28+
QgsPluginLayerDataProvider( const QString &layerType ) : mName( layerType ) {}
29+
void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
30+
virtual QgsCoordinateReferenceSystem crs() const { return QgsCoordinateReferenceSystem(); }
31+
virtual QString name() const override { return mName; }
32+
QString description() const override { return ""; }
33+
virtual QgsRectangle extent() const { return mExtent; }
34+
virtual bool isValid() const { return true; }
35+
36+
private:
37+
QString mName;
38+
QgsRectangle mExtent;
39+
};
40+
///@endcond
41+
2042
QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerName )
2143
: QgsMapLayer( PluginLayer, layerName )
2244
, mPluginLayerType( layerType )
2345
{
46+
mDataProvider = new QgsPluginLayerDataProvider( layerType );
2447
}
2548

2649
QgsPluginLayer::~QgsPluginLayer()
2750
{
2851
// TODO: shall we move the responsibility of emitting the signal to plugin
2952
// layer implementations before they start doing their part of cleanup...?
3053
emit willBeDeleted();
54+
delete mDataProvider;
3155
}
3256

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

4368
void QgsPluginLayer::setSource( const QString &source )
4469
{
4570
mDataSource = source;
4671
}
72+
73+
QgsDataProvider *QgsPluginLayer::dataProvider()
74+
{
75+
return mDataProvider;
76+
}
77+
78+
const QgsDataProvider *QgsPluginLayer::dataProvider() const
79+
{
80+
return mDataProvider;
81+
}

src/core/qgspluginlayer.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "qgis_core.h"
1919
#include "qgsmaplayer.h"
20-
20+
#include "qgsdataprovider.h"
2121

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

58+
QgsDataProvider *dataProvider() override;
59+
const QgsDataProvider *dataProvider() const override SIP_SKIP;
60+
5861
protected:
5962
QString mPluginLayerType;
63+
QgsDataProvider *mDataProvider;
6064
};
6165

6266
#endif // QGSPLUGINLAYER_H

0 commit comments

Comments
 (0)