Skip to content

Commit 69d0b30

Browse files
committed
Allow data items from plugins
1 parent 3dfa260 commit 69d0b30

9 files changed

+76
-10
lines changed

python/core/qgsdataitem.sip

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ class QgsDataItem : QObject
3232
Populated //!< children created
3333
};
3434

35+
//! @note added in 2.8
3536
State state() const;
3637

3738
/** Set item state. It also take care about starting/stopping loading icon animation.
38-
* @param state */
39+
* @param state
40+
* @note added in 2.8
41+
*/
3942
virtual void setState( State state );
4043

4144
//! @deprecated in 2.8, use state()
@@ -170,7 +173,8 @@ class QgsLayerItem : QgsDataItem
170173
Polygon,
171174
TableLayer,
172175
Database,
173-
Table
176+
Table,
177+
Plugin //!< added in 2.10
174178
};
175179

176180
QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );

python/core/qgspluginlayerregistry.sip

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class QgsPluginLayerType
1414
/** return new layer of this type. Return NULL on error */
1515
virtual QgsPluginLayer* createLayer() /Factory/;
1616

17+
/** return new layer of this type, using layer URI (specific to this plugin layer type). Return NULL on error.
18+
* @note added in 2.10
19+
*/
20+
virtual QgsPluginLayer* createLayer( const QString& uri ) /Factory/;
21+
1722
/** show plugin layer properties dialog. Return false if the dialog cannot be shown. */
1823
virtual bool showLayerProperties( QgsPluginLayer* layer );
1924

@@ -50,8 +55,10 @@ class QgsPluginLayerRegistry
5055
/** return plugin layer type metadata or NULL if doesn't exist */
5156
QgsPluginLayerType* pluginLayerType( QString typeName );
5257

53-
/** return new layer if corresponding plugin has been found, else return NULL */
54-
QgsPluginLayer* createLayer( QString typeName ) /Factory/;
58+
/** return new layer if corresponding plugin has been found, else return NULL.
59+
* @note optional param uri added in 2.10
60+
*/
61+
QgsPluginLayer* createLayer( QString typeName, const QString& uri = QString() ) /Factory/;
5562

5663
private:
5764

src/app/qgisapp.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ void QgisApp::dropEvent( QDropEvent *event )
10421042
{
10431043
addRasterLayer( uri, u.name, u.providerKey );
10441044
}
1045+
else if ( u.layerType == "plugin" )
1046+
{
1047+
addPluginLayer( uri, u.name, u.providerKey );
1048+
}
10451049
}
10461050
}
10471051
mMapCanvas->freeze( false );
@@ -9813,6 +9817,22 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
98139817
//
98149818
///////////////////////////////////////////////////////////////////
98159819

9820+
9821+
QgsPluginLayer* QgisApp::addPluginLayer( const QString& uri, const QString& baseName, const QString& providerKey )
9822+
{
9823+
QgsPluginLayer* layer = QgsPluginLayerRegistry::instance()->createLayer( providerKey, uri );
9824+
if ( !layer )
9825+
return 0;
9826+
9827+
layer->setLayerName( baseName );
9828+
9829+
QgsMapLayerRegistry::instance()->addMapLayer( layer );
9830+
9831+
return layer;
9832+
}
9833+
9834+
9835+
98169836
#ifdef ANDROID
98179837
void QgisApp::keyReleaseEvent( QKeyEvent *event )
98189838
{

src/app/qgisapp.h

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class QgsMapLayer;
5555
class QgsMapTip;
5656
class QgsMapTool;
5757
class QgsMapToolAdvancedDigitizing;
58+
class QgsPluginLayer;
5859
class QgsPoint;
5960
class QgsProviderRegistry;
6061
class QgsPythonUtils;
@@ -619,6 +620,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
619620
/** Open a raster layer using the Raster Data Provider. */
620621
QgsRasterLayer *addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );
621622

623+
/** Open a plugin layer using its provider */
624+
QgsPluginLayer* addPluginLayer( const QString& uri, const QString& baseName, const QString& providerKey );
625+
622626
void addWfsLayer( QString uri, QString typeName );
623627

624628
void versionReplyFinished();

src/app/qgsbrowserdockwidget.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
486486
{
487487
QgisApp::instance()->addRasterLayer( uri, layerItem->layerName(), providerKey );
488488
}
489+
if ( type == QgsMapLayer::PluginLayer )
490+
{
491+
QgisApp::instance()->addPluginLayer( uri, layerItem->layerName(), providerKey );
492+
}
489493
}
490494

491495
void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
@@ -591,6 +595,11 @@ void QgsBrowserDockWidget::showProperties()
591595
delete layer;
592596
}
593597
}
598+
else if ( type == QgsMapLayer::PluginLayer )
599+
{
600+
// TODO: support display of properties for plugin layers
601+
return;
602+
}
594603

595604
// restore /Projections/defaultBehaviour
596605
if ( defaultProjectionOption == "prompt" )

src/core/qgsdataitem.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ QgsMapLayer::LayerType QgsLayerItem::mapLayerType()
653653
{
654654
if ( mLayerType == QgsLayerItem::Raster )
655655
return QgsMapLayer::RasterLayer;
656+
if ( mLayerType == QgsLayerItem::Plugin )
657+
return QgsMapLayer::PluginLayer;
656658
return QgsMapLayer::VectorLayer;
657659
}
658660

src/core/qgsdataitem.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ class CORE_EXPORT QgsDataItem : public QObject
7474
Populated //!< children created
7575
};
7676

77+
//! @note added in 2.8
7778
State state() const;
7879

7980
/** Set item state. It also take care about starting/stopping loading icon animation.
80-
* @param state */
81+
* @param state
82+
* @note added in 2.8
83+
*/
8184
virtual void setState( State state );
8285

8386
//! @deprecated in 2.8, use state()
@@ -261,7 +264,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
261264
Polygon,
262265
TableLayer,
263266
Database,
264-
Table
267+
Table,
268+
Plugin //!< added in 2.10
265269
};
266270

267271
QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );

src/core/qgspluginlayerregistry.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ QgsPluginLayer* QgsPluginLayerType::createLayer()
4040
return NULL;
4141
}
4242

43+
QgsPluginLayer* QgsPluginLayerType::createLayer( const QString& uri )
44+
{
45+
Q_UNUSED( uri );
46+
return NULL;
47+
}
48+
4349
bool QgsPluginLayerType::showLayerProperties( QgsPluginLayer *layer )
4450
{
4551
Q_UNUSED( layer );
@@ -121,7 +127,7 @@ QgsPluginLayerType* QgsPluginLayerRegistry::pluginLayerType( QString typeName )
121127
}
122128

123129

124-
QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName )
130+
QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName, const QString& uri )
125131
{
126132
QgsPluginLayerType* type = pluginLayerType( typeName );
127133
if ( !type )
@@ -130,5 +136,8 @@ QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName )
130136
return NULL;
131137
}
132138

133-
return type->createLayer();
139+
if ( !uri.isEmpty() )
140+
return type->createLayer( uri );
141+
else
142+
return type->createLayer();
134143
}

src/core/qgspluginlayerregistry.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class CORE_EXPORT QgsPluginLayerType
3939
/** return new layer of this type. Return NULL on error */
4040
virtual QgsPluginLayer* createLayer();
4141

42+
/** return new layer of this type, using layer URI (specific to this plugin layer type). Return NULL on error.
43+
* @note added in 2.10
44+
*/
45+
virtual QgsPluginLayer* createLayer( const QString& uri );
46+
4247
/** show plugin layer properties dialog. Return false if the dialog cannot be shown. */
4348
virtual bool showLayerProperties( QgsPluginLayer* layer );
4449

@@ -73,8 +78,10 @@ class CORE_EXPORT QgsPluginLayerRegistry
7378
/** return plugin layer type metadata or NULL if doesn't exist */
7479
QgsPluginLayerType* pluginLayerType( QString typeName );
7580

76-
/** return new layer if corresponding plugin has been found, else return NULL */
77-
QgsPluginLayer* createLayer( QString typeName );
81+
/** return new layer if corresponding plugin has been found, else return NULL.
82+
* @note optional param uri added in 2.10
83+
*/
84+
QgsPluginLayer* createLayer( QString typeName, const QString& uri = QString() );
7885

7986
private:
8087

0 commit comments

Comments
 (0)