Skip to content
Permalink
Browse files

Allow data items from plugins

  • Loading branch information
wonder-sk committed Mar 18, 2015
1 parent 3dfa260 commit 69d0b30d58bf495d75592863fc3cfb906d183511
@@ -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()
@@ -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 );
@@ -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 );

@@ -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:

@@ -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 );
@@ -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 )
{
@@ -55,6 +55,7 @@ class QgsMapLayer;
class QgsMapTip;
class QgsMapTool;
class QgsMapToolAdvancedDigitizing;
class QgsPluginLayer;
class QgsPoint;
class QgsProviderRegistry;
class QgsPythonUtils;
@@ -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();
@@ -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 )
@@ -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" )
@@ -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;
}

@@ -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()
@@ -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 );
@@ -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 );
@@ -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 )
@@ -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();
}
@@ -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 );

@@ -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:

1 comment on commit 69d0b30

@NathanW2

This comment has been minimized.

Copy link
Member

NathanW2 commented on 69d0b30 Mar 18, 2015

YES! WIN!

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