Navigation Menu

Skip to content

Commit

Permalink
Allow data items from plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 18, 2015
1 parent 3dfa260 commit 69d0b30
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 10 deletions.
8 changes: 6 additions & 2 deletions python/core/qgsdataitem.sip
Expand Up @@ -32,10 +32,13 @@ class QgsDataItem : QObject
Populated //!< children created
};

//! @note added in 2.8
State state() const;

/** Set item state. It also take care about starting/stopping loading icon animation.
* @param state */
* @param state
* @note added in 2.8
*/
virtual void setState( State state );

//! @deprecated in 2.8, use state()
Expand Down Expand Up @@ -170,7 +173,8 @@ class QgsLayerItem : QgsDataItem
Polygon,
TableLayer,
Database,
Table
Table,
Plugin //!< added in 2.10
};

QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );
Expand Down
11 changes: 9 additions & 2 deletions python/core/qgspluginlayerregistry.sip
Expand Up @@ -14,6 +14,11 @@ class QgsPluginLayerType
/** return new layer of this type. Return NULL on error */
virtual QgsPluginLayer* createLayer() /Factory/;

/** return new layer of this type, using layer URI (specific to this plugin layer type). Return NULL on error.
* @note added in 2.10
*/
virtual QgsPluginLayer* createLayer( const QString& uri ) /Factory/;

/** show plugin layer properties dialog. Return false if the dialog cannot be shown. */
virtual bool showLayerProperties( QgsPluginLayer* layer );

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

/** return new layer if corresponding plugin has been found, else return NULL */
QgsPluginLayer* createLayer( QString typeName ) /Factory/;
/** return new layer if corresponding plugin has been found, else return NULL.
* @note optional param uri added in 2.10
*/
QgsPluginLayer* createLayer( QString typeName, const QString& uri = QString() ) /Factory/;

private:

Expand Down
20 changes: 20 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1042,6 +1042,10 @@ void QgisApp::dropEvent( QDropEvent *event )
{
addRasterLayer( uri, u.name, u.providerKey );
}
else if ( u.layerType == "plugin" )
{
addPluginLayer( uri, u.name, u.providerKey );
}
}
}
mMapCanvas->freeze( false );
Expand Down Expand Up @@ -9813,6 +9817,22 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
//
///////////////////////////////////////////////////////////////////


QgsPluginLayer* QgisApp::addPluginLayer( const QString& uri, const QString& baseName, const QString& providerKey )
{
QgsPluginLayer* layer = QgsPluginLayerRegistry::instance()->createLayer( providerKey, uri );
if ( !layer )
return 0;

layer->setLayerName( baseName );

QgsMapLayerRegistry::instance()->addMapLayer( layer );

return layer;
}



#ifdef ANDROID
void QgisApp::keyReleaseEvent( QKeyEvent *event )
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -55,6 +55,7 @@ class QgsMapLayer;
class QgsMapTip;
class QgsMapTool;
class QgsMapToolAdvancedDigitizing;
class QgsPluginLayer;
class QgsPoint;
class QgsProviderRegistry;
class QgsPythonUtils;
Expand Down Expand Up @@ -619,6 +620,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
/** Open a raster layer using the Raster Data Provider. */
QgsRasterLayer *addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );

/** Open a plugin layer using its provider */
QgsPluginLayer* addPluginLayer( const QString& uri, const QString& baseName, const QString& providerKey );

void addWfsLayer( QString uri, QString typeName );

void versionReplyFinished();
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -486,6 +486,10 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
{
QgisApp::instance()->addRasterLayer( uri, layerItem->layerName(), providerKey );
}
if ( type == QgsMapLayer::PluginLayer )
{
QgisApp::instance()->addPluginLayer( uri, layerItem->layerName(), providerKey );
}
}

void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
Expand Down Expand Up @@ -591,6 +595,11 @@ void QgsBrowserDockWidget::showProperties()
delete layer;
}
}
else if ( type == QgsMapLayer::PluginLayer )
{
// TODO: support display of properties for plugin layers
return;
}

// restore /Projections/defaultBehaviour
if ( defaultProjectionOption == "prompt" )
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -653,6 +653,8 @@ QgsMapLayer::LayerType QgsLayerItem::mapLayerType()
{
if ( mLayerType == QgsLayerItem::Raster )
return QgsMapLayer::RasterLayer;
if ( mLayerType == QgsLayerItem::Plugin )
return QgsMapLayer::PluginLayer;
return QgsMapLayer::VectorLayer;
}

Expand Down
8 changes: 6 additions & 2 deletions src/core/qgsdataitem.h
Expand Up @@ -74,10 +74,13 @@ class CORE_EXPORT QgsDataItem : public QObject
Populated //!< children created
};

//! @note added in 2.8
State state() const;

/** Set item state. It also take care about starting/stopping loading icon animation.
* @param state */
* @param state
* @note added in 2.8
*/
virtual void setState( State state );

//! @deprecated in 2.8, use state()
Expand Down Expand Up @@ -261,7 +264,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
Polygon,
TableLayer,
Database,
Table
Table,
Plugin //!< added in 2.10
};

QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );
Expand Down
13 changes: 11 additions & 2 deletions src/core/qgspluginlayerregistry.cpp
Expand Up @@ -40,6 +40,12 @@ QgsPluginLayer* QgsPluginLayerType::createLayer()
return NULL;
}

QgsPluginLayer* QgsPluginLayerType::createLayer( const QString& uri )
{
Q_UNUSED( uri );
return NULL;
}

bool QgsPluginLayerType::showLayerProperties( QgsPluginLayer *layer )
{
Q_UNUSED( layer );
Expand Down Expand Up @@ -121,7 +127,7 @@ QgsPluginLayerType* QgsPluginLayerRegistry::pluginLayerType( QString typeName )
}


QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName )
QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName, const QString& uri )
{
QgsPluginLayerType* type = pluginLayerType( typeName );
if ( !type )
Expand All @@ -130,5 +136,8 @@ QgsPluginLayer* QgsPluginLayerRegistry::createLayer( QString typeName )
return NULL;
}

return type->createLayer();
if ( !uri.isEmpty() )
return type->createLayer( uri );
else
return type->createLayer();
}
11 changes: 9 additions & 2 deletions src/core/qgspluginlayerregistry.h
Expand Up @@ -39,6 +39,11 @@ class CORE_EXPORT QgsPluginLayerType
/** return new layer of this type. Return NULL on error */
virtual QgsPluginLayer* createLayer();

/** return new layer of this type, using layer URI (specific to this plugin layer type). Return NULL on error.
* @note added in 2.10
*/
virtual QgsPluginLayer* createLayer( const QString& uri );

/** show plugin layer properties dialog. Return false if the dialog cannot be shown. */
virtual bool showLayerProperties( QgsPluginLayer* layer );

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

/** return new layer if corresponding plugin has been found, else return NULL */
QgsPluginLayer* createLayer( QString typeName );
/** return new layer if corresponding plugin has been found, else return NULL.
* @note optional param uri added in 2.10
*/
QgsPluginLayer* createLayer( QString typeName, const QString& uri = QString() );

private:

Expand Down

1 comment on commit 69d0b30

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES! WIN!

Please sign in to comment.